diff options
author | misterpoe <raymondksi@gmail.com> | 2016-08-05 14:04:25 -0700 |
---|---|---|
committer | Matt Loring <mattloring@google.com> | 2016-12-20 12:31:09 -0800 |
commit | ba4847e879424ad173289e8fb96cc86a09ee899b (patch) | |
tree | a0d4d9135b3f3872325517a226bb6bcd7b751923 /src/tracing/node_trace_writer.h | |
parent | 613798335c4313176dfa9f3bafc1fada82293428 (diff) | |
download | android-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/node_trace_writer.h')
-rw-r--r-- | src/tracing/node_trace_writer.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/tracing/node_trace_writer.h b/src/tracing/node_trace_writer.h new file mode 100644 index 0000000000..5813db0ab1 --- /dev/null +++ b/src/tracing/node_trace_writer.h @@ -0,0 +1,74 @@ +#ifndef SRC_NODE_TRACE_WRITER_H_ +#define SRC_NODE_TRACE_WRITER_H_ + +#include <sstream> +#include <queue> + +#include "node_mutex.h" +#include "libplatform/v8-tracing.h" +#include "uv.h" + +namespace node { +namespace tracing { + +using v8::platform::tracing::TraceObject; +using v8::platform::tracing::TraceWriter; +using v8::platform::tracing::TracingController; + +class NodeTraceWriter : public TraceWriter { + public: + NodeTraceWriter(uv_loop_t* tracing_loop); + ~NodeTraceWriter(); + + void AppendTraceEvent(TraceObject* trace_event) override; + void Flush() override; + void Flush(bool blocking); + + static const int kTracesPerFile = 1 << 19; + + private: + struct WriteRequest { + uv_fs_t req; + NodeTraceWriter* writer; + std::string str; + int highest_request_id; + }; + + static void WriteCb(uv_fs_t* req); + void OpenNewFileForStreaming(); + void WriteToFile(std::string&& str, int highest_request_id); + void WriteSuffix(); + static void FlushSignalCb(uv_async_t* signal); + void FlushPrivate(); + static void ExitSignalCb(uv_async_t* signal); + + uv_loop_t* tracing_loop_; + // Triggers callback to initiate writing the contents of stream_ to disk. + uv_async_t flush_signal_; + // Triggers callback to close async objects, ending the tracing thread. + uv_async_t exit_signal_; + // Prevents concurrent R/W on state related to serialized trace data + // before it's written to disk, namely stream_ and total_traces_. + Mutex stream_mutex_; + // Prevents concurrent R/W on state related to write requests. + Mutex request_mutex_; + // Allows blocking calls to Flush() to wait on a condition for + // trace events to be written to disk. + ConditionVariable request_cond_; + // Used to wait until async handles have been closed. + ConditionVariable exit_cond_; + int fd_ = -1; + std::queue<WriteRequest*> write_req_queue_; + int num_write_requests_ = 0; + int highest_request_id_completed_ = 0; + int total_traces_ = 0; + int file_num_ = 0; + std::ostringstream stream_; + TraceWriter* json_trace_writer_ = nullptr; + bool exited_ = false; +}; + +} // namespace tracing +} // namespace node + +#endif // SRC_NODE_TRACE_WRITER_H_ |