From 59d89a2bf1c867878985ea7b48e6474ce1865e4a Mon Sep 17 00:00:00 2001 From: Jack Veenstra Date: Sat, 9 May 2009 11:44:53 -0700 Subject: Add a "-d time" option to stack_dump to dump the stack at the given time. --- emulator/qtools/stack_dump.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'emulator') diff --git a/emulator/qtools/stack_dump.cpp b/emulator/qtools/stack_dump.cpp index b5014ef..35ee61c 100644 --- a/emulator/qtools/stack_dump.cpp +++ b/emulator/qtools/stack_dump.cpp @@ -15,6 +15,9 @@ typedef TraceReader<> TraceReaderType; #include "parse_options-inl.h" #include "callstack.h" +static uint64_t debugTime; +static uint64_t dumpTime = 0; + class MyFrame : public StackFrame { public: void push(int stackLevel, uint64_t time, CallStackBase *base); @@ -25,6 +28,8 @@ typedef CallStack CallStackType; void MyFrame::push(int stackLevel, uint64_t time, CallStackBase *base) { + if (dumpTime > 0) + return; printf("%llu en thr %d %3d", time, base->getId(), stackLevel); for (int ii = 0; ii < stackLevel; ++ii) printf("."); @@ -33,6 +38,8 @@ void MyFrame::push(int stackLevel, uint64_t time, CallStackBase *base) void MyFrame::pop(int stackLevel, uint64_t time, CallStackBase *base) { + if (dumpTime > 0) + return; printf("%llu x thr %d %3d", time, base->getId(), stackLevel); for (int ii = 0; ii < stackLevel; ++ii) printf("."); @@ -43,8 +50,6 @@ static const int kNumStackFrames = 500; static const int kMaxThreads = (32 * 1024); CallStackType *stacks[kMaxThreads]; -static uint64_t debugTime; - void Usage(const char *program) { fprintf(stderr, "Usage: %s [options] trace_name elf_file\n", @@ -52,9 +57,29 @@ void Usage(const char *program) OptionsUsage(); } +bool localParseOptions(int argc, char **argv) +{ + bool err = false; + while (!err) { + int opt = getopt(argc, argv, "+d:"); + if (opt == -1) + break; + switch (opt) { + case 'd': + dumpTime = strtoull(optarg, NULL, 0); + break; + default: + err = true; + break; + } + } + return err; +} + int main(int argc, char **argv) { ParseOptions(argc, argv); + localParseOptions(argc, argv); if (argc - optind != 2) { Usage(argv[0]); exit(1); @@ -66,9 +91,6 @@ int main(int argc, char **argv) trace->Open(qemu_trace_file); trace->ReadKernelSymbols(elf_file); trace->SetRoot(root); - TraceHeader *qheader = trace->GetHeader(); - uint64_t startTime = qheader->start_sec; - startTime = (startTime << 32) | qheader->start_usec; BBEvent event; while (1) { @@ -93,6 +115,13 @@ int main(int argc, char **argv) // Update the stack pStack->updateStack(&event, function); + + // If the user requested a stack dump at a certain time, + // and we are at that time, then dump the stack and exit. + if (dumpTime > 0 && event.time >= dumpTime) { + pStack->showStack(stdout); + break; + } } for (int ii = 0; ii < kMaxThreads; ++ii) { -- cgit v1.1