How to build an executable with profiling?

Roman Divacky rdivacky at freebsd.org
Tue Jan 18 21:12:04 UTC 2011


On Tue, Jan 18, 2011 at 09:35:17AM -0800, Steve Kargl wrote:
> On Tue, Jan 18, 2011 at 06:16:57PM +0100, Roman Divacky wrote:
> > On Tue, Jan 18, 2011 at 04:43:13PM +0200, Kostik Belousov wrote:
> > > On Tue, Jan 18, 2011 at 03:32:05PM +0100, Roman Divacky wrote:
> > > > On Mon, Jan 17, 2011 at 10:44:11AM -0800, Steve Kargl wrote:
> > > > > How does one build an executable for profiling with clang?
> > > >  
> > > > LLVM (and thus clang) does not support GPROF profiling. 
> > > > 
> > > > > clang -o testf -O2 -march=native -pipe -static -pg -I/usr/local/include -I../mp testf.c -L/usr/local/lib -L../mp -lsgk -lmpfr -lgmp -L/usr/home/kargl/work/lib -lm_clang_p
> > > > > clang: warning: the clang compiler does not support '-pg'
> > > > > 
> > > > > I suppose it will be pointless to ask, but shouldn't clang
> > > > > support one of the most basic gcc compiler options if clang
> > > > > is to replace gcc as the base system compiler?
> > > > 
> > > > is GPROF really needed at this point? we have HWPMC, isnt
> > > > it sufficient?
> > > Hwpmc requires additional work for each new CPU model. Also,
> > > hwpmc is not supported even on all Intel or AMD CPUs, esp. older
> > > models, and e.g. VIA cores.
> > > 
> > > Not to mention !x86 architectures.
> > 
> > yes. I agree. HWPMC is not 100% solution.
> > 
> > for those interested in profiling in LLVM in detail:
> > 
> >         http://llvm.org/pubs/2010-04-NeustifterProfiling.html
> > 
> > summary: LLVM supports inserting profiling probes (but the selection
> >          of places where to put them is very naive) but there's no
> >          "GPROF writer".
> > 
> > I mailed the author of the thesis yesterday and it looks like his work may
> > get committed to upstream LLVM.
> > 
> 
> Thanks for the url and checking on the status of profiling with llvm.

I checked the LLVM code instead and here's what I found:

LLVM actually supports profiling, in its own format (llvmprof.out). This can
only be used for its PGO optimization (BasicBlockPlacement) and is very naive.

Theoretically it should be possible to write "llvmprof.out -> a.out.gmon"
converter - no idea how feasible it is. I guess it would not be very easy.

I believe it can be sufficiently easy to write a "gprof-like dumper" for
the llvmprof.out files (if there's not one already) that would print
stuff like "foo called X times, bar called Y times". I dont know about
the actual measuring of time. I think it's not in the llvmprof.out.

roman


More information about the freebsd-toolchain mailing list