Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Feb 2024 08:20:55 +0100
From:      Paul Floyd <paulf2718@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Profiling applications
Message-ID:  <03729a10-8b55-416f-beb4-3a4275d880b7@gmail.com>
In-Reply-To: <efe56bdc-b4a8-4452-add3-a5b01c8a856a@app.fastmail.com>
References:  <efe56bdc-b4a8-4452-add3-a5b01c8a856a@app.fastmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help


On 03-02-24 01:16, Chuck Tuffli wrote:
> What is the recommended way of profiling applications on FreeBSD these 
> days? I’m looking for information like “28% of the execution time is 
> spent in function X”.
> 
> —chuck

First off, you will get best results with DWARF debuginfo. If you can, 
build your test exe with "-g -O3" or similar.

The first answer should be pmcstat. When I've used it, it didn't inspire 
a great amount of confidence. The wiki page 
https://wiki.freebsd.org/PmcTools hasn't been updated in 15 years, so 
I've no idea if it is still relevant. pmc and pmcstat are in base. No 
commits for the last 2 or 3 years, and low activity before that.

Using a non-debug kernel I get lots of

addr2line: dwarf_init: Debug info NULL [_dwarf_consumer_init(66)]
pmcstat: WARNING: addr2line function name read error
pmcstat: WARNING: addr2line pipe error

messages.

Still, I can get to see some measurements with it.

To see sampling data
0. pkg install kcachegrind
1. kldload hwpmc
2. profile: pmcstat -P inst_retired.any_p -O /tmp/pmctest.bin -d [your 
command and arguments]
3. convert to callgrind format: pmcstat -R/tmp/pmctest.bin -F/tmp/pmctest.cg
4. view results: kcachegrind /tmp/pmctest.cg

The next thing that I would suggest is Google perftools. You will need 
to install google-perftools. Roughly, you will need to link with their 
library (iirc LD_PRELOAD should also work), set some environment 
variables and then run your exe. You'll need to do some postprocessing 
similar to pmcstat. perftools are fairly well documented on the web.

Lastly, you could try cachegrind and callgrind. They are slow, do not 
accurately model the cache or branch prediction and not at all 
speculative execution. What they measure is accurate and as close to 
deterministic as you can get.


A+
Paul





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?03729a10-8b55-416f-beb4-3a4275d880b7>