when we skip the call stack starting with an external address, we should also skip the bottom LBR entry, otherwise it will cause a truncated context issue.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 | A truncated context might still be helpful to the sample loader inliner. We saw this happened to some SPEC2006 benchmarks. What issue did it cause to you? |
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 | Sorry for the confusion. This line is for the non-address line like empty line. This patch is for the issue like below external address1 .. address2 address3 LBR entry The first one is an external address1, so we need also skip the address2 and address3. otherwise, the missing part is the top frame, it will make the unwinder incorrect. For the right truncated context, it's like below address1 address2 external address3 .. LBR entry Here the truncated part is at the bottom, then the compiler can use this for the inliner. The tool can handle this case. |
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 | Oh I see. Thanks for explaining. So with your change, we now restart when seeing an empty line. And we continue scanning even with an empty call stack to avoid breaking the samples into two parts, with the second part being a truncated call stack? |
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 | Yeah, exactly. Our internal prototype didn't have this issue since the whole trace file is split by the '\n\n', so it will always ensure a whole sample and avoid breaking into two parts. But for llvm-profgen, it's processed line by line and previously it will start parsing new sample when the call stack is empty which will cause this bug when the first address is an external one. |
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 | Sounds good. Is it possible to add a test based on the current test binaries? |
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 | Yeah, Good idea! I can manually create a perfscript for this. |
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 | Just copy another sample and added a fake top address on it. with out this fix, it will generate wrong profile count. |
LGTM, thanks for the fix!
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
453–454 | Nit: comment may be updated to reflect the truncated callstack case. |
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
413 | This is tricky, because the underlying TraceStream read line by line .. you see in line 408 StringRef FrameStr which use StringRef, if we hoist TraceIt.advance();, the internal string instance will be freed. That means we must ensure to use the StringRef before call advance. have the comments in TraceStream. | |
414 | yeah, I think so. For the perf generated perfscript, I saw the only case is a log line at the head of the file, shouldn't have comments in other place. Here the comments are most for the regression test, but as you see we have to make sure it's not mixed in the sample. |
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 | A comment line at the beginning of a callstack sample should still be OK, but not for a comment in the middle of a callstack sample. Previously we would just skip the frames following a comment. Will a continue work here if we need comments? |
Ah,I misuse it.. let me change the title.
llvm/tools/llvm-profgen/PerfReader.cpp | ||
---|---|---|
414 |
Sorry I just make mistakes to explain, it could have comments between different sample but not in the middle of sample(as Hongtao reminded), like: ... address1 address2 LBR ;legal comment address3 ;illegal comment address4 LBR
continue might not work here. because we could have MMAP event, like: ; comment1 MMAP_Event_.. address1 ... So it will also skip the MMAP line, that's why we return false to defer parsing the next line to parseEventOrSample. |
line 413 and line 416 can be hoisted to line 409?