C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-09-2010, 10:55 AM   #1
Registered User
 
Join Date: Feb 2010
Posts: 3
Profiler for C code

Hi everyone, I'm new here. I'm an italian student of informatic engineering. I'm looking for a C profiler. I try to use gprof but without success (even if I compile with -pg option). I try even Valgrind, but it's the same. Can anyone help me? Btw, I have a MacBook.
Thanks for the help!
guess85 is offline   Reply With Quote
Old 02-09-2010, 11:03 AM   #2
critical genius
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,198
Okay, here's how to use gprof:

1) compile: gcc -pg -fprofile-arcs -ftest-coverage
2) now run the executable once, this will create a file "gmon.out"
3) then gprof -b ./a.out (or the exe name).
__________________

"A man can't just sit around." -- Larry Walters
MK27 is offline   Reply With Quote
Old 02-09-2010, 11:03 AM   #3
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 539
OK the MacBook is your problem to solve

All joking aside, what about gprof did not work for you?

As for Valgrind, that is a memory/leak checking tool, not a profiler...


So if you can explain a little better what went wrong, maybe we can help you...
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-09-2010, 11:04 AM   #4
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 539
Quote:
Originally Posted by MK27 View Post
Okay, here's how to use gprof:

1) compile: gcc -pg -fprofile-arcs -ftest-coverage
2) now run the executable once, this will create a file "gmon.out"
3) then gprof -b ./a.out (or the exe name).
You beat me to it. I was going to try to get the OP to do some of the leg-work himself. You are too fast!

Happy Tuesday...
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-09-2010, 11:04 AM   #5
Jack of many languages
 
Dino's Avatar
 
Join Date: Nov 2007
Location: Katy, Texas
Posts: 2,071
Why not use Xcode tools?
__________________
Mac and Windows cross platform programmer. Ruby lover.
Dino is offline   Reply With Quote
Old 02-09-2010, 11:08 AM   #6
critical genius
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,198
Quote:
Originally Posted by jeffcobb View Post
I was going to try to get the OP to do some of the leg-work himself.
Oh yuck -- you need to contemplate my signature Jeff. The gprof man page is one of many still used in the FIFTH CIRCLE OF HELL!!!
__________________

"A man can't just sit around." -- Larry Walters
MK27 is offline   Reply With Quote
Old 02-09-2010, 11:16 AM   #7
Registered User
 
Join Date: Feb 2010
Posts: 3
Quote:
Originally Posted by MK27 View Post
Okay, here's how to use gprof:

1) compile: gcc -pg -fprofile-arcs -ftest-coverage
2) now run the executable once, this will create a file "gmon.out"
3) then gprof -b ./a.out (or the exe name).
But in (1) before "coverage" I insert my source code right? gcc -pg -fprofile-arcs -ftest-coverage myprog.c

Quote:
Originally Posted by jeffcobb View Post
OK the MacBook is your problem to solve
I can say the same thing for other OS

The code I want to profile is libsvm, if someone know. To compile this I do "make" in the dir and it compile svm-train and svm-predict.
This what "makefile" file contains:
Code:
CXX ?= g++
CFLAGS = -Wall -Wconversion -O3 -fPIC
SHVER = 1

all: svm-train svm-predict svm-scale

lib: svm.o
	$(CXX) -shared svm.o -o libsvm.so.$(SHVER)

svm-predict: svm-predict.c svm.o
	$(CXX) $(CFLAGS) svm-predict.c svm.o -o svm-predict -lm
svm-train: svm-train.c svm.o
	$(CXX) $(CFLAGS) svm-train.c svm.o -o svm-train -lm
svm-scale: svm-scale.c
	$(CXX) $(CFLAGS) svm-scale.c -o svm-scale
svm.o: svm.cpp svm.h
	$(CXX) $(CFLAGS) -c svm.cpp
clean:
	rm -f *~ svm.o svm-train svm-predict svm-scale
I need to profile svm-train and svm-predict, where I put -pg and other things?
I'm new in profiling and I need some help Thanks
guess85 is offline   Reply With Quote
Old 02-09-2010, 11:19 AM   #8
critical genius
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,198
Quote:
Originally Posted by guess85 View Post
I need to profile svm-train and svm-predict, where I put -pg and other things?
I'm new in profiling and I need some help Thanks
Try adding it to CFLAGS.
__________________

"A man can't just sit around." -- Larry Walters
MK27 is offline   Reply With Quote
Old 02-09-2010, 11:46 AM   #9
Registered User
 
Join Date: Feb 2010
Posts: 3
Quote:
Originally Posted by MK27 View Post
Try adding it to CFLAGS.
Thanks, I try to do it.
guess85 is offline   Reply With Quote
Old 02-09-2010, 11:46 AM   #10
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 539
Yeah but I know how to profile my code
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-09-2010, 11:52 AM   #11
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 539
Quote:
Originally Posted by MK27 View Post
Oh yuck -- you need to contemplate my signature Jeff. The gprof man page is one of many still used in the FIFTH CIRCLE OF HELL!!!
Actually I have a couple of really *really* nice volumes here that go into detail on that and all is explained well with plenty of example code.

And I am here to help...when I first got here I would jump on any request for code and post full working solutions to everything....until I realized the number of ppl coming here waiting for the answer to just be handed to them. I have a wife, the only person I work for unconditionally for free. Others must pay and if not monetarily (nothing that I am suggesting) then through gaining personal knowledge and experience, the latter of which can be the greatest teacher of all, IMHO....this is what working in FOSS has brought to me and one of its greatest virtues: not the free code, free support, security et al: free education...


I dunno, maybe if we had just !had that rash flea-bags posting home-work and demanding answers w/o being willing to even *try* to do the coding I might have answered differently. And the MacBook *is* his problem

I am not picking on him; I tease all of my Apple friends.
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-09-2010, 12:27 PM   #12
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,768
I have altered the below to set the correct flags for profiling. Those changes are marked in blue.

Quote:
Originally Posted by guess85 View Post
Code:
CXX ?= g++
PROFILE = -pg
CFLAGS = -Wall -Wconversion -O3 -fPIC $(PROFILE)
SHVER = 1

all: svm-train svm-predict svm-scale

lib: svm.o
	$(CXX) -shared svm.o -o libsvm.so.$(SHVER) $(PROFILE)

svm-predict: svm-predict.c svm.o
	$(CXX) $(CFLAGS) svm-predict.c svm.o -o svm-predict -lm
svm-train: svm-train.c svm.o
	$(CXX) $(CFLAGS) svm-train.c svm.o -o svm-train -lm
svm-scale: svm-scale.c
	$(CXX) $(CFLAGS) svm-scale.c -o svm-scale
svm.o: svm.cpp svm.h
	$(CXX) $(CFLAGS) -c svm.cpp
clean:
	rm -f *~ svm.o svm-train svm-predict svm-scale
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Reply

Tags
c code, gprof, macbook, profiler, profiling

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code profiler? h3ro Tech Board 5 04-07-2008 09:16 AM
Proposal: Code colouring Perspective General Discussions 28 05-14-2007 07:23 AM
Values changing without reason? subtled C Programming 2 04-19-2007 10:20 AM
Obfuscated Code Contest Stack Overflow Contests Board 51 01-21-2005 04:17 PM
Interface Question smog890 C Programming 11 06-03-2002 05:06 PM


All times are GMT -6. The time now is 02:13 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22