blob: b5014ef51df9f1cedcc30057956943e8e6d55f43 [file] [log] [blame]
The Android Open Source Project52d4c302009-03-03 19:29:09 -08001// Copyright 2006 The Android Open Source Project
2
3#include <stdio.h>
4#include <unistd.h>
5#include <stdlib.h>
6#include <inttypes.h>
7#include <assert.h>
8#include "trace_reader.h"
9#include "bitvector.h"
10#include "parse_options.h"
11#include "armdis.h"
12
13typedef TraceReader<> TraceReaderType;
14
15#include "parse_options-inl.h"
16#include "callstack.h"
17
18class MyFrame : public StackFrame<symbol_type> {
19 public:
20 void push(int stackLevel, uint64_t time, CallStackBase *base);
21 void pop(int stackLevel, uint64_t time, CallStackBase *base);
22};
23
24typedef CallStack<MyFrame> CallStackType;
25
26void MyFrame::push(int stackLevel, uint64_t time, CallStackBase *base)
27{
28 printf("%llu en thr %d %3d", time, base->getId(), stackLevel);
29 for (int ii = 0; ii < stackLevel; ++ii)
30 printf(".");
31 printf(" 0x%08x %s\n", addr, function->name);
32}
33
34void MyFrame::pop(int stackLevel, uint64_t time, CallStackBase *base)
35{
36 printf("%llu x thr %d %3d", time, base->getId(), stackLevel);
37 for (int ii = 0; ii < stackLevel; ++ii)
38 printf(".");
39 printf(" 0x%08x %s\n", addr, function->name);
40}
41
42static const int kNumStackFrames = 500;
43static const int kMaxThreads = (32 * 1024);
44CallStackType *stacks[kMaxThreads];
45
46static uint64_t debugTime;
47
48void Usage(const char *program)
49{
50 fprintf(stderr, "Usage: %s [options] trace_name elf_file\n",
51 program);
52 OptionsUsage();
53}
54
55int main(int argc, char **argv)
56{
57 ParseOptions(argc, argv);
58 if (argc - optind != 2) {
59 Usage(argv[0]);
60 exit(1);
61 }
62
63 char *qemu_trace_file = argv[optind++];
64 char *elf_file = argv[optind++];
65 TraceReaderType *trace = new TraceReaderType;
66 trace->Open(qemu_trace_file);
67 trace->ReadKernelSymbols(elf_file);
68 trace->SetRoot(root);
69 TraceHeader *qheader = trace->GetHeader();
70 uint64_t startTime = qheader->start_sec;
71 startTime = (startTime << 32) | qheader->start_usec;
72
73 BBEvent event;
74 while (1) {
75 BBEvent ignored;
76 symbol_type *function;
77
78 if (GetNextValidEvent(trace, &event, &ignored, &function))
79 break;
80 if (event.bb_num == 0)
81 break;
82
83 // Get the stack for the current thread
84 CallStackType *pStack = stacks[event.pid];
85
86 // If the stack does not exist, then allocate a new one.
87 if (pStack == NULL) {
88 pStack = new CallStackType(event.pid, kNumStackFrames, trace);
89 stacks[event.pid] = pStack;
90 }
91 if (debugTime != 0 && event.time >= debugTime)
92 printf("debug time: %lld\n", debugTime);
93
94 // Update the stack
95 pStack->updateStack(&event, function);
96 }
97
98 for (int ii = 0; ii < kMaxThreads; ++ii) {
99 if (stacks[ii])
100 stacks[ii]->popAll(event.time);
101 }
102
103 delete trace;
104 return 0;
105}