Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:06:50+00:00 2026-06-05T18:06:50+00:00

I need some help in terms of profiling existing code in terms of execution

  • 0

I need some help in terms of profiling existing code in terms of execution time. The intention is to speed it up.

I’ve been given some code that was worked on previously. It is completely written in C++ with OO concepts. There is a GUI based interface to it, and selecting a certain option runs selected peiece of code. (There are about 11 classes as part of the project).

I want to be able to press a GUI option and let the code run and generate a resource map like:

Functions of Class 1 = 20% of execution time
Functions of Class 2 = 60% of execution time
Functions of Class 3 = 10% of execution time
Functions of Class 4 = 10% of execution time

That way, I know which class is taking up the most time and then know which to work on and improve. However, I have no idea how to go about doing this. I only have basic C++ knowledge.

I did read this post: find c++ execution time, however since the program is not serial. One class calls another, and that calls another, I don’t know how system clock/ticks would be implementable?

I read of program like Valgrind, Zoom, Poor Man’s Profiler etc. but honestly have no idea on integrating it with the code. Is there so simpler method?

I also read this method: How can I profile C++ code running in Linux?, however I don’t see how I could get pin-pointed information as to class based information (Class 1, Class 2 etc.)

Could someone please advise for a newbie?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:06:52+00:00Added an answer on June 5, 2026 at 6:06 pm

    Valgrind (subtool callgrind) is pretty simple to use.You just need to make sure that sufficient debugging info is compiled/linked into your program so that callgrind can find the names of the various functions that are getting called. Then instead of calling your program directly, pass it (and its arguments) as parameters to valgrind, like:

    valgrind --tool=callgrind --trace-children=yes <myprogram> <myprogram_args>
    

    (–trace-children is there in case your real executable is hiding behind some layer or layers of wrapper scripts)

    Note that your program will run much more slowly (like 100x slower) because every single function entrypoint is being traced.

    Various tools exist to explore callgrind’s output, notably kcachegrind/qcachegrid.

    Alternatively, you could measure system clock ticks for some small number of high-level functions (so you see “time taken by function X and everything underneath it”) and progress down through your code as you find hotspots.

    Something like this (conceptually, needs to be properly organized into headers / sources):

    struct FunctionTimer {
      FunctionTimer(char const * name) : mName(name), mStartTime(clock()) { }
      ~FunctionTimer() { mFunctionTimes[mName] += clock() - mStartTime; }
    
      static void report()
      {
        ... iterate through mFunctionTimes, printing out
        the names and accumulated ticks ...
      }
    
      std::string mName;
      clock_t mStartTime;
    
      static std::map<std::string, clock_t> mFunctionTimes;
    };
    
    ...
    
    void myfunc()
    {
      FunctionTimer ft("myfunc");
      ... code of myfunc ...
    }
    
    ...
    
    int main(int argc, char* argv[])
    {
      ... do stuff ...
      FunctionTimer::report();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help assigning a mouseover event to display some icons that start out
I need some help with a query that should return posts based on their
I need some help with what is probably a newbie question in terms of
I'm looking for some db design help. I have an existing application that I'd
I have a problem that I need some help on but I feel I'm
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help with Activerecord Querying in a has_many :through association. Model: Job class
need some help with saxon.net. Can anybody tell me how to output a xslt
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.