how much time?

C

carlosp

I am aware that this is, technically, not a question about c++ but
surely here someone will now-how-to. I have a program, with lots of
routines, and complicated stuff. I want to optimize it but I don't
want to optimize all the parts, but rather the ones in which it takes
longer. Of course one can put time logs in the program, but there must
be an efficient way on how to do it. If someone can point out a few
keywords or commands in gdb or other linux debugger or something else,
I would be quite pleased. Thanks a lot!
 
A

anon

carlosp said:
I am aware that this is, technically, not a question about c++ but
surely here someone will now-how-to. I have a program, with lots of
routines, and complicated stuff. I want to optimize it but I don't
want to optimize all the parts, but rather the ones in which it takes
longer. Of course one can put time logs in the program, but there must
be an efficient way on how to do it. If someone can point out a few
keywords or commands in gdb or other linux debugger or something else,
I would be quite pleased. Thanks a lot!

callgrind
kcachegrind
 
P

Pascal J. Bourguignon

carlosp said:
I am aware that this is, technically, not a question about c++ but
surely here someone will now-how-to. I have a program, with lots of
routines, and complicated stuff. I want to optimize it but I don't
want to optimize all the parts, but rather the ones in which it takes
longer. Of course one can put time logs in the program, but there must
be an efficient way on how to do it. If someone can point out a few
keywords or commands in gdb or other linux debugger or something else,
I would be quite pleased. Thanks a lot!

Not gdb, but g++ with gprof.

Pass to g++ on of these options:

# Profile Options (to see where time is spent):
# -p --> prof
# -pg --> gprof
# -a --> tcov
# ATTENTION: -a inhibits -fprofile-args!

and possibly one or both of these options:

# Coverage Options (to check coverage of test cases):
# -fprofile-args ==> [email protected]
# -ftest-coverage ==> [email protected], [email protected]

Then run your program.

Then use gprof to get a profile report, or gcov to get the coverage.
 
J

James Kanze

I am aware that this is, technically, not a question about c++
but surely here someone will now-how-to. I have a program,
with lots of routines, and complicated stuff. I want to
optimize it but I don't want to optimize all the parts, but
rather the ones in which it takes longer. Of course one can
put time logs in the program, but there must be an efficient
way on how to do it. If someone can point out a few keywords
or commands in gdb or other linux debugger or something else,
I would be quite pleased. Thanks a lot!

The tool you're looking for is called a profiler. Under Linux,
there's gprof, which is quite good.

Typically, you'll also have to compile with special options: for
gprof, you'll need -pg with g++, but check the documentation.
 
C

carlosp

Thanks, I will try then gprof which seems to be the tool I am looking
for. Thanks a lot!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top