From: Serhei Makarov Date: Tue, 7 Apr 2026 21:24:18 +0000 (-0400) Subject: src/stackprof.cxx: fixups in prior X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=239fbaeca5b0defd462012ecebe3982de782b502;p=thirdparty%2Felfutils.git src/stackprof.cxx: fixups in prior - clog/cerr division is ok - mainfile can also be null - if we deliberately limit maxframes<=2, the heuristic flagging fewer than 2 frames as a 'lost' sample is inapplicable and - opt_maxframes relates to the user deliberately choosing to override GprofUnwindSampleConsumer preference with --maxframes (which I consider useful sometimes for testing): if --maxframes is provided, then use the default of 1. --- diff --git a/src/stackprof.cxx b/src/stackprof.cxx index c411bbc8..73a626c0 100644 --- a/src/stackprof.cxx +++ b/src/stackprof.cxx @@ -17,7 +17,6 @@ /* TODO(REVIEW.1) Need to make sure the following options produce reasonable output: - for -v, use show_pids, not show_samples (don't show a pid twice?) - - clog/cerr redirection -- these both end up in stderr, switch clog to cout? */ #ifdef HAVE_CONFIG_H @@ -1439,8 +1438,10 @@ int PerfConsumerUnwinder::unwind_frame_cb(Dwfl_Frame *state) const char *debugfile; const char *modname = dwfl_module_info (m, NULL, NULL, NULL, NULL, NULL, &mainfile, &debugfile); - clog << format(" module={} mainfile={} debugfile={}\n", - modname, mainfile, debugfile?debugfile:""); + clog << format("module={} mainfile={} debugfile={}\n", + modname, + mainfile ? mainfile : "", + debugfile ? debugfile : ""); /* TODO: Also store this data to avoid repeated extraction for the final buildid summary? */ #ifdef DEBUG_MODULES @@ -1573,7 +1574,7 @@ void PerfConsumerUnwinder::process_sample(const perf_event_header *sample, if (this->last_us.addrs.size() > (unsigned long)dwfl_ent->max_frames) dwfl_ent->max_frames = this->last_us.addrs.size(); dwfl_ent->total_samples++; - if (this->last_us.addrs.size() <= 2) + if (this->maxframes > 2 && this->last_us.addrs.size() <= 2) dwfl_ent->lost_samples++; } @@ -1962,7 +1963,10 @@ GprofUnwindSampleConsumer::~GprofUnwindSampleConsumer() int GprofUnwindSampleConsumer::maxframes() { - return 1; // gprof only needs one level of backtracing + // gprof only needs one level of backtracing, + // but user can override consumer's preference + // with --maxframes option: + return opt_maxframes >= 0 ? opt_maxframes : 1; }