From: Frank Ch. Eigler Date: Thu, 12 Feb 2026 15:53:23 +0000 (-0500) Subject: stackprof: testsuite++ now with gprof + debuginfod X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea6006c1dae2de9a9f81ce9beec5535fb915819e;p=thirdparty%2Felfutils.git stackprof: testsuite++ now with gprof + debuginfod switched back to "even" hashtable splitting mode, fixed an off-by-one --- diff --git a/src/stackprof.cxx b/src/stackprof.cxx index bf262758..89f689fb 100644 --- a/src/stackprof.cxx +++ b/src/stackprof.cxx @@ -427,7 +427,7 @@ static const struct argp_option options[] = { NULL, 0, NULL, OPTION_DOC, N_("Output options:"), 1 }, { "verbose", 'v', NULL, 0, N_ ("Increase verbosity of logging messages."), 0 }, { "gmon", 'g', NULL, 0, N_("Generate gmon.BUILDID.out files for each binary."), 0 }, - { "hist-split", 'h', HIST_SPLIT_OPTS, 0, N_("Histogram splitting method for gmon, default 'flex'."), 0 }, + { "hist-split",'G', HIST_SPLIT_OPTS, 0, N_("Histogram splitting method for gmon, default 'even'."), 0 }, { "output", 'o', "DIR", 0, N_("Output directory for gmon files."), 0 }, { "force", 'f', NULL, 0, N_("Unlink output files to force writing as new."), 0 }, { "pid", 'p', "PID", 0, N_("Profile given PID, and its future children."), 0 }, @@ -457,7 +457,7 @@ enum hist_split_method { // Globals set based on command line options: static unsigned verbose; static bool gmon; -static hist_split_method gmon_hist_split = HIST_SPLIT_FLEX; +static hist_split_method gmon_hist_split = HIST_SPLIT_EVEN; static string output_dir = "."; static bool output_force = false; // overwrite preexisting output files? static int pid; @@ -491,7 +491,7 @@ parse_opt (int key, char *arg, struct argp_state *state) gmon = true; break; - case 'h': + case 'G': /* TODO: Error if -g is not set? */ if (strcmp (arg, "none") == 0) gmon_hist_split = HIST_SPLIT_NONE; @@ -1875,14 +1875,18 @@ void GprofUnwindSampleConsumer::record_gmon_out(const string& buildid, UnwindMod if (pc - low_pc > opt_size) { /* Record a histogram from low_pc to low_pc+opt_size. */ - this->record_gmon_hist(of, m.histogram, low_pc, low_pc+opt_size /* >= prev_pc */, alignment); + this->record_gmon_hist(of, m.histogram, + low_pc, low_pc+opt_size-1 /* >= prev_pc */, + alignment); low_pc = pc; } prev_pc = pc; } /* Record a final histogram from low_pc to low_pc+opt_size. TODO: Edge case -- adjust for overflow of low_pc+opt_size at end of address space. */ - this->record_gmon_hist(of, m.histogram, low_pc, low_pc+opt_size /* >= prev_pc */, alignment); + this->record_gmon_hist(of, m.histogram, + low_pc, low_pc+opt_size-1 /* >= prev_pc */, + alignment); } else if (gmon_hist_split == HIST_SPLIT_FLEX) { diff --git a/tests/run-stackprof-user-gprof.sh b/tests/run-stackprof-user-gprof.sh index 10a914d1..b0a40474 100755 --- a/tests/run-stackprof-user-gprof.sh +++ b/tests/run-stackprof-user-gprof.sh @@ -33,9 +33,27 @@ grep "^perf_event_attr configuration" test.out grep "Starting stack profile collection pid" test.out grep -E "^buildid [0-9a-f]+" test.out +export DEBUGINFOD_URLS=https://debuginfod.elfutils.org/ + for f in gmon.*.out do - gprof `basename "$f" .out`.exe "$f" + exe="`basename "$f" .out`.exe" + echo "NOTE: analyzing $exe `readlink $exe`" + tempfiles gprof_output.txt + # Try a plain gprof attempt on the executable + if gprof "$exe" > gprof_output.txt 2>&1; then + # Success, use the output + cat gprof_output.txt + else + # Fall back to debuginfod if necessary (e.g., if debug info is missing) + echo "NOTE: stripped binary found, attempting to find debuginfo" + if testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $exe; then + debuginfo="`debuginfod-find debuginfo $exe`" + gprof "$debuginfo" "$f" + else + echo "SKIPPING: debuginfo not found" + fi + fi done exit 0