| Index: src/sampler-thread.cc
|
| diff --git a/src/sampler-thread.cc b/src/sampler-thread.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..98ad0be9b73fe50f0803afdd0d30e16b4a302df8
|
| --- /dev/null
|
| +++ b/src/sampler-thread.cc
|
| @@ -0,0 +1,85 @@
|
| +// Copyright 2014 the V8 project authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <stdio.h>
|
| +
|
| +#include "src/v8.h"
|
| +
|
| +#include "src/sampler-thread.h"
|
| +
|
| +namespace v8 {
|
| +
|
| +void CodeEventPrinter::Create(const void* from,
|
| + const int size,
|
| + const std::string& name) {
|
| + fprintf(stderr,
|
| + "code-creation,,,%p,%d,%s\n",
|
| + from,
|
| + size,
|
| + name.c_str());
|
| +}
|
| +
|
| +
|
| +void CodeEventPrinter::Delete(const void* from) {
|
| + fprintf(stderr, "code-delete,%p\n", from);
|
| +}
|
| +
|
| +
|
| +void CodeEventPrinter::Move(const void* from, const void* to) {
|
| + fprintf(stderr, "code-move,%p,%p\n", from, to);
|
| +}
|
| +
|
| +
|
| +void CodeEventPrinter::SharedLibrary(const std::string& library_path,
|
| + const void* start,
|
| + const void* end) {
|
| + fprintf(stderr,
|
| + "shared-library,\"%s\",%p,%p\n",
|
| + library_path.c_str(),
|
| + start,
|
| + end);
|
| +}
|
| +
|
| +
|
| +static const int kSamplerThreadStackSize = 64 * 1024;
|
| +
|
| +SamplerThread::SamplerThread(Isolate* isolate)
|
| + : Thread(Thread::Options("d8:sampler", kSamplerThreadStackSize)),
|
| + isolate_(isolate),
|
| + done_sampling_(false) {
|
| + CodeEventPrinter* codeEventHandler = new CodeEventPrinter();
|
| + Sampler::Install(isolate_, codeEventHandler);
|
| +}
|
| +
|
| +
|
| +void SamplerThread::Stop() {
|
| + done_sampling_ = true;
|
| + Join();
|
| +}
|
| +
|
| +
|
| +void SamplerThread::Run() {
|
| + Sample sample;
|
| + int ctr = 0;
|
| + while (!done_sampling_) {
|
| + ctr++;
|
| + Sample* sample_ptr = &sample;
|
| + sample_ptr = Sampler::GetSample(isolate_, sample_ptr);
|
| + if (sample_ptr != NULL) {
|
| + for (unsigned int i = 0; i < sample_ptr->frames_count; i++) {
|
| + if (i == 0)
|
| + fprintf(stderr, "tick,,%d,,,,", ctr);
|
| + if (i != (unsigned)(sample_ptr->frames_count - 1))
|
| + fprintf(stderr, "%p,", sample_ptr->stack[i]);
|
| + else
|
| + fprintf(stderr, "%p\n", sample_ptr->stack[i]);
|
| + }
|
| + } else {
|
| + return;
|
| + }
|
| + base::OS::Sleep(1);
|
| + }
|
| +}
|
| +
|
| +} // namespace v8
|
|
|