[llvm] [XRay][account] add account test for nonempty exit mismatch (PR #93564)
Tomer Shafir via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 23:24:45 PDT 2024
https://github.com/tomershafir updated https://github.com/llvm/llvm-project/pull/93564
>From 084d6e3207796e0f42a50b0d79b08a4db8a67038 Mon Sep 17 00:00:00 2001
From: tomershafir <tomer.shafir8 at gmail.com>
Date: Tue, 28 May 2024 18:21:00 +0300
Subject: [PATCH] [compiler-rt][XRay]: add account test for nonempty exit
mismatch
---
...ount-exit-mismatch-empty-stack-error.yaml} | 0
...t-exit-mismatch-non-empty-stack-error.yaml | 31 +++++++++++++++++++
.../llvm-xray/X86/account-keep-going.yaml | 4 +--
llvm/tools/llvm-xray/xray-account.cpp | 3 ++
4 files changed, 36 insertions(+), 2 deletions(-)
rename llvm/test/tools/llvm-xray/X86/{account-empty-stack-error.yaml => account-exit-mismatch-empty-stack-error.yaml} (100%)
create mode 100644 llvm/test/tools/llvm-xray/X86/account-exit-mismatch-non-empty-stack-error.yaml
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..9387a8dfa9436
--- /dev/null
+++ b/llvm/test/tools/llvm-xray/X86/account-exit-mismatch-non-empty-stack-error.yaml
@@ -0,0 +1,31 @@
+#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: 4, cpu: 1, thread: 1, kind: function-exit, tsc: 10001 }
+ - { type: 0, func-id: 1, cpu: 1, thread: 1, kind: function-exit, tsc: 10002 }
+...
+
+#CHECK: Error processing record: {{.*}}
+#CHECK-NEXT: Thread ID: 1
+#CHECK-NEXT: {{(#[0-9]+.*\n)+}}
+#CHECK-NEXT: llvm-xray: Failed accounting function calls in file '{{.*}}'.
+
+#KEEPGOING: Error processing record: {{.*}}
+#KEEPGOING-NEXT: Thread ID: 1
+#KEEPGOING-NEXT: {{(#[0-9]+.*\n)+}}
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;
More information about the llvm-commits
mailing list