summaryrefslogtreecommitdiff
path: root/src/tracing/agent.cc
diff options
context:
space:
mode:
authormisterpoe <raymondksi@gmail.com>2016-08-05 14:04:25 -0700
committerMatt Loring <mattloring@google.com>2016-12-20 12:31:09 -0800
commitba4847e879424ad173289e8fb96cc86a09ee899b (patch)
treea0d4d9135b3f3872325517a226bb6bcd7b751923 /src/tracing/agent.cc
parent613798335c4313176dfa9f3bafc1fada82293428 (diff)
downloadandroid-node-v8-ba4847e879424ad173289e8fb96cc86a09ee899b.tar.gz
android-node-v8-ba4847e879424ad173289e8fb96cc86a09ee899b.tar.bz2
android-node-v8-ba4847e879424ad173289e8fb96cc86a09ee899b.zip
src: Node Tracing Controller
This commit adds support for trace-event tracing to Node.js. It provides a mechanism to centralize tracing information generated by V8, Node core, and userspace code. It includes: - A trace writer responsible for serializing traces and cycling the output files so that no individual file becomes to large. - A buffer for aggregating traces to allow for batched flushes. - An agent which initializes the tracing controller and ensures that trace serialization is done on a separate thread. - A set of macros for generating trace events. - Tests and documentation. Author: Raymond Kang <raymondksi@gmail.com> Author: Kelvin Jin <kelvinjin@google.com> Author: Matthew Loring <mattloring@google.com> Author: Jason Ginchereau <jasongin@microsoft.com> PR-URL: https://github.com/nodejs/node/pull/9304 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Josh Gavant <josh.gavant@outlook.com>
Diffstat (limited to 'src/tracing/agent.cc')
-rw-r--r--src/tracing/agent.cc72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/tracing/agent.cc b/src/tracing/agent.cc
new file mode 100644
index 0000000000..97a3e11a2c
--- /dev/null
+++ b/src/tracing/agent.cc
@@ -0,0 +1,72 @@
+#include "tracing/agent.h"
+
+#include <sstream>
+#include <string>
+
+#include "env-inl.h"
+#include "libplatform/libplatform.h"
+
+namespace node {
+namespace tracing {
+
+using v8::platform::tracing::TraceConfig;
+
+Agent::Agent() {}
+
+void Agent::Start(v8::Platform* platform, const char* enabled_categories) {
+ platform_ = platform;
+
+ int err = uv_loop_init(&tracing_loop_);
+ CHECK_EQ(err, 0);
+
+ NodeTraceWriter* trace_writer = new NodeTraceWriter(&tracing_loop_);
+ TraceBuffer* trace_buffer = new NodeTraceBuffer(
+ NodeTraceBuffer::kBufferChunks, trace_writer, &tracing_loop_);
+
+ tracing_controller_ = new TracingController();
+
+ TraceConfig* trace_config = new TraceConfig();
+ if (enabled_categories) {
+ std::stringstream category_list(enabled_categories);
+ while (category_list.good()) {
+ std::string category;
+ getline(category_list, category, ',');
+ trace_config->AddIncludedCategory(category.c_str());
+ }
+ } else {
+ trace_config->AddIncludedCategory("v8");
+ trace_config->AddIncludedCategory("node");
+ }
+
+ // This thread should be created *after* async handles are created
+ // (within NodeTraceWriter and NodeTraceBuffer constructors).
+ // Otherwise the thread could shut down prematurely.
+ err = uv_thread_create(&thread_, ThreadCb, this);
+ CHECK_EQ(err, 0);
+
+ tracing_controller_->Initialize(trace_buffer);
+ tracing_controller_->StartTracing(trace_config);
+ v8::platform::SetTracingController(platform, tracing_controller_);
+}
+
+void Agent::Stop() {
+ if (!IsStarted()) {
+ return;
+ }
+ // Perform final Flush on TraceBuffer. We don't want the tracing controller
+ // to flush the buffer again on destruction of the V8::Platform.
+ tracing_controller_->StopTracing();
+ delete tracing_controller_;
+ // Thread should finish when the tracing loop is stopped.
+ uv_thread_join(&thread_);
+ v8::platform::SetTracingController(platform_, nullptr);
+}
+
+// static
+void Agent::ThreadCb(void* arg) {
+ Agent* agent = static_cast<Agent*>(arg);
+ uv_run(&agent->tracing_loop_, UV_RUN_DEFAULT);
+}
+
+} // namespace tracing
+} // namespace node