Skip to content

[XRay][account] add account test for nonempty exit mismatch #93564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

tomershafir
Copy link
Contributor

@tomershafir tomershafir commented May 28, 2024

  • Add llvm-xray account regression test for an exit mismatch with a non empty stack (its a different code path than empty stack).
  • Align empty stack test case name.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the xray label May 28, 2024
@llvmbot
Copy link
Member

llvmbot commented May 28, 2024

@llvm/pr-subscribers-xray

Author: Tomer Shafir (tomershafir)

Changes
  • Add llvm-xray account regression test for an exit mismatch with a non empty stack (its a different code path than empty stack).
  • Align empty stack test case name.
  • Add some comments.

Full diff: https://github.com/llvm/llvm-project/pull/93564.diff

4 Files Affected:

  • (renamed) llvm/test/tools/llvm-xray/X86/account-exit-mismatch-empty-stack-error.yaml ()
  • (added) llvm/test/tools/llvm-xray/X86/account-exit-mismatch-non-empty-stack-error.yaml (+34)
  • (modified) llvm/test/tools/llvm-xray/X86/account-keep-going.yaml (+2-2)
  • (modified) llvm/tools/llvm-xray/xray-account.cpp (+3)
diff --git a/llvm/test/tools/llvm-xray/X86/account-empty-stack-error.yaml b/llvm/test/tools/llvm-xray/X86/account-exit-mismatch-empty-stack-error.yaml
similarity index 100%
rename from llvm/test/tools/llvm-xray/X86/account-empty-stack-error.yaml
rename to llvm/test/tools/llvm-xray/X86/account-exit-mismatch-empty-stack-error.yaml
diff --git a/llvm/test/tools/llvm-xray/X86/account-exit-mismatch-non-empty-stack-error.yaml b/llvm/test/tools/llvm-xray/X86/account-exit-mismatch-non-empty-stack-error.yaml
new file mode 100644
index 0000000000000..d2b0da0536bb4
--- /dev/null
+++ b/llvm/test/tools/llvm-xray/X86/account-exit-mismatch-non-empty-stack-error.yaml
@@ -0,0 +1,34 @@
+#RUN: not llvm-xray account %s -o - -m %S/Inputs/simple-instrmap.yaml -d 2>&1 | FileCheck %s
+#RUN: llvm-xray account %s -k -o - -m %S/Inputs/simple-instrmap.yaml -d 2>&1 | FileCheck %s --check-prefix=KEEPGOING
+
+---
+header:
+  version: 1
+  type: 0
+  constant-tsc: true
+  nonstop-tsc: true
+  cycle-frequency: 0
+records:
+# Generalizes empty stack error test case, where an exit record doesn't match an entry record
+# on a non empty stack with sibling call deduction. This can happen for example when an
+# instrumented function does a 'fork()', where the child process will not see
+# the entry record but see the exit record. This is completely valid data,
+# which should be handled with grace (i.e. we treat it as an error, but since
+# the llvm-xray account tool has an option to keep going, gives the user a
+# chance to retry).
+  - { type: 0, func-id: 1, cpu: 1, thread: 1, kind: function-enter, tsc: 10000 }
+  - { type: 0, func-id: 2, cpu: 1, thread: 1, kind: function-enter, tsc: 10001 }
+  - { type: 0, func-id: 3, cpu: 1, thread: 1, kind: function-enter, tsc: 10002 }
+  - { type: 0, func-id: 3, cpu: 1, thread: 1, kind: function-exit,  tsc: 10003 }
+  - { type: 0, func-id: 1, cpu: 1, thread: 1, kind: function-exit,  tsc: 10004 }
+  - { type: 0, func-id: 4, cpu: 1, thread: 1, kind: function-exit,  tsc: 10004 }
+...
+
+#CHECK:      Error processing record: {{.*}}
+#CHECK-NEXT: Thread ID: 1
+#CHECK-NEXT: {{.*}}
+#CHECK-NEXT: llvm-xray: Failed accounting function calls in file '{{.*}}'.
+
+#KEEPGOING:      Error processing record: {{.*}}
+#KEEPGOING-NEXT: Thread ID: 1
+#KEEPGOING-NEXT: {{.*}}
diff --git a/llvm/test/tools/llvm-xray/X86/account-keep-going.yaml b/llvm/test/tools/llvm-xray/X86/account-keep-going.yaml
index 76011ee8e6e5e..fb1a8f422bad7 100644
--- a/llvm/test/tools/llvm-xray/X86/account-keep-going.yaml
+++ b/llvm/test/tools/llvm-xray/X86/account-keep-going.yaml
@@ -7,8 +7,8 @@ header:
   nonstop-tsc: true
   cycle-frequency: 0
 records:
-# We want to test the case for when we see spurious exits, but keep going
-# anyway ignoring the records in the process.
+# We want to test the case for when we see spurious exits without sibling call deduction, 
+# but keep going anyway ignoring the records in the process.
   - { type: 0, func-id: 1, cpu: 1, thread: 111, kind: function-enter, tsc: 10000 }
   - { type: 0, func-id: 2, cpu: 1, thread: 111, kind: function-enter, tsc: 10001 }
   - { type: 0, func-id: 3, cpu: 1, thread: 111, kind: function-enter, tsc: 10002 }
diff --git a/llvm/tools/llvm-xray/xray-account.cpp b/llvm/tools/llvm-xray/xray-account.cpp
index 24a3552cfb91e..d3380ad8820ad 100644
--- a/llvm/tools/llvm-xray/xray-account.cpp
+++ b/llvm/tools/llvm-xray/xray-account.cpp
@@ -198,6 +198,7 @@ bool LatencyAccountant::accountRecord(const XRayRecord &Record) {
       break;
     }
 
+    // A sibling call, need to be deduced
     if (!DeduceSiblingCalls)
       return false;
 
@@ -207,6 +208,8 @@ bool LatencyAccountant::accountRecord(const XRayRecord &Record) {
                       [&](const std::pair<const int32_t, uint64_t> &E) {
                         return E.first == Record.FuncId;
                       });
+    // Gracefully return when an exit doesn't match any entry on a non empty stack, 
+    // e.g. it can happen on a fork()
     if (Parent == ThreadStack.Stack.rend())
       return false;
 

@tomershafir tomershafir changed the title [compiler-rt][XRay]: add account test for nonempty exit mismatch [XRay][account] add account test for nonempty exit mismatch May 28, 2024
@tomershafir tomershafir force-pushed the xray-account-add-test-exit-mismatch-nonempty branch 3 times, most recently from 3ca95ee to 534a67b Compare May 29, 2024 07:50
@tomershafir tomershafir force-pushed the xray-account-add-test-exit-mismatch-nonempty branch from 534a67b to e7c8d0a Compare August 25, 2024 14:01
@tomershafir
Copy link
Contributor Author

@MaskRay hey, maybe you can take a look?

Copy link
Member

@deanberris deanberris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please wait for @MaskRay 😄

@tomershafir tomershafir force-pushed the xray-account-add-test-exit-mismatch-nonempty branch from e7c8d0a to 25adf8b Compare October 11, 2024 10:19
@tomershafir
Copy link
Contributor Author

@MaskRay Can you pls merge this?

@tomershafir
Copy link
Contributor Author

@MaskRay ping

@MaskRay MaskRay merged commit 6d3d952 into llvm:main Jan 1, 2025
7 checks passed
Copy link

github-actions bot commented Jan 1, 2025

@tomershafir Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@tomershafir tomershafir deleted the xray-account-add-test-exit-mismatch-nonempty branch January 1, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants