]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
stackprof: add gmon.*.exe symlink sibling for gmon.*.out
authorFrank Ch. Eigler <fche@redhat.com>
Tue, 3 Feb 2026 19:28:08 +0000 (14:28 -0500)
committerFrank Ch. Eigler <fche@elastic.org>
Tue, 3 Feb 2026 19:28:35 +0000 (14:28 -0500)
src/stackprof.cxx

index cbf0bbbaa98c4d6a2e821be422704e38a8c5f11b..a0d7b59a86241306610aaffd86bc961d72f650ae 100644 (file)
@@ -127,8 +127,8 @@ struct UnwindDwflStats {
 
 struct hash_arc {
   template <class T1, class T2>
-  size_t operator()(const std::pair<T1, T2> &p) const {
-    return std::hash<T1>()(p.first) ^ std::hash<T2>()(p.second);
+  size_t operator()(const pair<T1, T2> &p) const {
+    return hash<T1>()(p.first) ^ hash<T2>()(p.second);
   }
 };
 
@@ -160,7 +160,7 @@ struct UnwindModuleStats {
     if (mod != mod2)
       cerr << "XXX duplicate modules for buildid" << endl;
 #endif
-    std::pair<uint64_t, uint64_t> arc(from, to);
+    pair<uint64_t, uint64_t> arc(from, to);
     if (callgraph.count(arc) == 0)
       callgraph[arc] = 0;
     callgraph[arc]++;
@@ -1624,13 +1624,19 @@ enum gmon_entry_tag {
 
 void GprofUnwindSampleConsumer::record_gmon_out(const string& buildid, UnwindModuleStats& m)
 {
-  std::stringstream fs;
-  fs << output_dir << "/" << "gmon." << buildid << ".out"; /* TODO Refine naming scheme, test for / avoid collisions. */
-  string filename = fs.str();
+  string filename = output_dir + "/" + "gmon." + buildid + ".out";
+  string exe_symlink_path = output_dir + "/" + "gmon." + buildid + ".exe";
+  
+  string target_path = buildid_to_path[buildid];
+  if (symlink(target_path.c_str(), exe_symlink_path.c_str()) == -1) {
+    // Handle error, e.g., print errno or throw exception
+    cerr << "symlink failed: " << strerror(errno) << endl;
+    return;
+  }
 
   // plop buildid_to_path bits into per-gmon-out json files
 
-  std::ofstream of (filename, std::ios::binary);
+  ofstream of (filename, ios::binary);
   if (!of)
     {
       cerr << N_("buildid ") << buildid << " -- could not open '" << filename << "' for writing" << endl;
@@ -1798,10 +1804,10 @@ void GprofUnwindSampleConsumer::process(const UnwindSample *sample)
     return; // XXX: report/tabulate hit outside known modules
 
   /* TODO(REVIEW.5): Is it better to use the unconverted build_id_desc as hash key? */
-  std::stringstream bs;
-  bs << std::hex << std::setfill('0');
+  stringstream bs;
+  bs << hex << setfill('0');
   for (int i = 0; i < build_id_len; ++i)
-    bs << std::setw(2) << static_cast<int>(desc[i]);
+    bs << setw(2) << static_cast<int>(desc[i]);
   string buildid = bs.str();
 
   const char *mainfile;