xref: /llvm-project/lldb/test/API/commands/trace/TestTraceDumpInfo.py (revision a50ea2f76f993f65c8756067f7ad5a21e560b0c9)
1import lldb
2from intelpt_testcase import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5from lldbsuite.test.decorators import *
6
7
8class TestTraceDumpInfo(TraceIntelPTTestCaseBase):
9    def testErrorMessages(self):
10        # We first check the output when there are no targets
11        self.expect(
12            "thread trace dump info",
13            substrs=[
14                "error: invalid target, create a target using the 'target create' command"
15            ],
16            error=True,
17        )
18
19        # We now check the output when there's a non-running target
20        self.expect(
21            "target create "
22            + os.path.join(self.getSourceDir(), "intelpt-trace", "a.out")
23        )
24
25        self.expect(
26            "thread trace dump info",
27            substrs=["error: Command requires a current process."],
28            error=True,
29        )
30
31        # Now we check the output when there's a running target without a trace
32        self.expect("b main")
33        self.expect("run")
34
35        self.expect(
36            "thread trace dump info",
37            substrs=["error: Process is not being traced"],
38            error=True,
39        )
40
41    def testDumpRawTraceSize(self):
42        self.expect(
43            "trace load -v "
44            + os.path.join(self.getSourceDir(), "intelpt-trace", "trace.json"),
45            substrs=["intel-pt"],
46        )
47
48        self.expect(
49            "thread trace dump info",
50            substrs=[
51                """thread #1: tid = 3842849
52
53  Trace technology: intel-pt
54
55  Total number of trace items: 28
56
57  Memory usage:
58    Raw trace size: 4 KiB""",
59                """
60
61  Events:
62    Number of individual events: 7
63      software disabled tracing: 2
64      hardware disabled tracing: 4
65      trace synchronization point: 1""",
66            ],
67            patterns=["Decoding instructions: \d.\d\ds"],
68        )
69
70    def testDumpRawTraceSizeJSON(self):
71        self.expect(
72            "trace load -v "
73            + os.path.join(self.getSourceDir(), "intelpt-trace", "trace.json"),
74            substrs=["intel-pt"],
75        )
76
77        self.expect(
78            "thread trace dump info --json ",
79            substrs=[
80                """{
81  "traceTechnology": "intel-pt",
82  "threadStats": {
83    "tid": 3842849,
84    "traceItemsCount": 28,""",
85                """
86    },
87    "events": {
88      "totalCount": 7,
89      "individualCounts": {
90        "software disabled tracing": 2,
91        "hardware disabled tracing": 4,
92        "trace synchronization point": 1
93      }
94    },
95    "errors": {
96      "totalCount": 0,
97      "libiptErrors": {},
98      "fatalErrors": 0,
99      "otherErrors": 0
100    }
101  },
102  "globalStats": {
103    "timingInSeconds": {}
104  }
105}""",
106            ],
107        )
108