[BUG] simpleperf associates wrong header file for lambda

Open Beginner friendly
#2,262 6 comments 0 reactions 1 assignee View on GitHub

@Jake-The-Human is already working on this.

Since Nov 2, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, cpp, python
Domain
devtools

Research direction

Start in pprof_proto_generator.py, where Function.key and get_function_id handle function deduplication and source file attribution. Trace how inlined frames pass source_file, then check existing tests for PprofProfileGenerator and add coverage showing same-named operator() frames from different headers remain distinct. Done when multi-trial profiles preserve each frame's source header consistently.

Written by the indexing model from the issue text.

Description

bug
Description

When llvm-symbolizer resolves inlined C++ lambdas or functors with --functions=linkage --demangle, it reports the unqualified function name operator(). Because Function.key in PprofProfileGenerator previously deduplicated functions solely by (name_id, dso_name_id) without source_filename_id, all inlined operator() frames within a binary shared a single Function record whose source_filename_id was overwritten by whichever sampled location was processed last. Across multi-trial profile aggregations, nondeterministic sampling caused the same inlined call site to be attributed to different header files in different trials, splitting identical call chains into separate flame graph branches.

For example, consider file Foo.cc that implements Foo class, has Foo::Bar() function that calls a lambda, and uses std::unique_ptr and std::vector. On different simpleperf runs, the lambda's operator() may be randomly associated with Foo.cc, unique_ptr.h, or vector.h.

A solution is to include source_filename_id in Function.key and pass the resolved source_file when creating or looking up Function records for inlined frames so that inlined functions with the same name in different files receive distinct Function entries.

Here's a patch that should solve this:

--- a/pprof_proto_generator.py
+++ b/pprof_proto_generator.py
@@ -249,17 +249,19 @@ class Mapping(object):
 
 class Function(object):
 
-    def __init__(self, name_id, dso_name_id, vaddr_in_dso):
+    def __init__(
+        self, name_id, dso_name_id, vaddr_in_dso, source_filename_id=0
+    ):
         self.id = -1  # unset
         self.name_id = name_id
         self.dso_name_id = dso_name_id
         self.vaddr_in_dso = vaddr_in_dso
-        self.source_filename_id = 0
+        self.source_filename_id = source_filename_id
         self.start_line = 0
 
     @property
     def key(self):
-        return (self.name_id, self.dso_name_id)
+        return (self.name_id, self.dso_name_id, self.source_filename_id)
 
 
 # pylint: disable=no-member
@@ -530,10 +532,17 @@ class PprofProfileGenerator(object):
     def get_mapping(self, mapping_id):
         return self.mapping_list[mapping_id - 1] if mapping_id > 0 else None
 
-    def get_function_id(self, name, dso_name, vaddr_in_file):
+    def get_function_id(
+        self, name, dso_name, vaddr_in_file, source_filename=''
+    ):
         if name == 'unknown':
             return 0
-        function = Function(self.get_string_id(name), self.get_string_id(dso_name), vaddr_in_file)
+        function = Function(
+            self.get_string_id(name),
+            self.get_string_id(dso_name),
+            vaddr_in_file,
+            self.get_string_id(source_filename),
+        )
         exist_function = self.function_map.get(function.key)
         if exist_function:
             return exist_function.id
@@ -604,7 +613,9 @@ class PprofProfileGenerator(object):
                     # accurate when proguard mapping file is given.
                     function_id = orig_function_id
                 else:
-                    function_id = self.get_function_id(function_name, dso_name, 0)
+                    function_id = self.get_function_id(
+                        function_name, dso_name, 0, source_file
+                    )
                 if function_id == 0:
                     continue
                 location.lines.append(self.add_line(source_file, source_line, function_id))
I am using a supported NDK
  • I have checked and the NDK I'm using is currently supported
Affected versions

r27

Dominant language
No language data
Stars
2.3k
Forks
311
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/ndk

All issues in android/ndk

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.