OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stdio.h> |
| 6 |
| 7 #include "src/v8.h" |
| 8 |
| 9 #include "src/sampler-thread.h" |
| 10 |
| 11 namespace v8 { |
| 12 |
| 13 void CodeEventPrinter::Create(const void* from, |
| 14 const int size, |
| 15 const std::string& name) { |
| 16 fprintf(stderr, |
| 17 "code-creation,,,%p,%d,%s\n", |
| 18 from, |
| 19 size, |
| 20 name.c_str()); |
| 21 } |
| 22 |
| 23 |
| 24 void CodeEventPrinter::Delete(const void* from) { |
| 25 fprintf(stderr, "code-delete,%p\n", from); |
| 26 } |
| 27 |
| 28 |
| 29 void CodeEventPrinter::Move(const void* from, const void* to) { |
| 30 fprintf(stderr, "code-move,%p,%p\n", from, to); |
| 31 } |
| 32 |
| 33 |
| 34 void CodeEventPrinter::SharedLibrary(const std::string& library_path, |
| 35 const void* start, |
| 36 const void* end) { |
| 37 fprintf(stderr, |
| 38 "shared-library,\"%s\",%p,%p\n", |
| 39 library_path.c_str(), |
| 40 start, |
| 41 end); |
| 42 } |
| 43 |
| 44 |
| 45 static const int kSamplerThreadStackSize = 64 * 1024; |
| 46 |
| 47 SamplerThread::SamplerThread(Isolate* isolate) |
| 48 : Thread(Thread::Options("d8:sampler", kSamplerThreadStackSize)), |
| 49 isolate_(isolate), |
| 50 done_sampling_(false) { |
| 51 CodeEventPrinter* codeEventHandler = new CodeEventPrinter(); |
| 52 Sampler::Install(isolate_, codeEventHandler); |
| 53 } |
| 54 |
| 55 |
| 56 void SamplerThread::Stop() { |
| 57 done_sampling_ = true; |
| 58 Join(); |
| 59 } |
| 60 |
| 61 |
| 62 void SamplerThread::Run() { |
| 63 Sample sample; |
| 64 int ctr = 0; |
| 65 while (!done_sampling_) { |
| 66 ctr++; |
| 67 Sample* sample_ptr = &sample; |
| 68 sample_ptr = Sampler::GetSample(isolate_, sample_ptr); |
| 69 if (sample_ptr != NULL) { |
| 70 for (unsigned int i = 0; i < sample_ptr->frames_count; i++) { |
| 71 if (i == 0) |
| 72 fprintf(stderr, "tick,,%d,,,,", ctr); |
| 73 if (i != (unsigned)(sample_ptr->frames_count - 1)) |
| 74 fprintf(stderr, "%p,", sample_ptr->stack[i]); |
| 75 else |
| 76 fprintf(stderr, "%p\n", sample_ptr->stack[i]); |
| 77 } |
| 78 } else { |
| 79 return; |
| 80 } |
| 81 base::OS::Sleep(1); |
| 82 } |
| 83 } |
| 84 |
| 85 } // namespace v8 |
OLD | NEW |