Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: src/sampler-thread.cc

Issue 499483002: [WIP] A sampler thread in d8 for consuming the new API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/log.cc ('K') | « src/sampler-thread.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« src/log.cc ('K') | « src/sampler-thread.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698