GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/tracing/node_trace_writer.h Lines: 1 1 100.0 %
Date: 2017-12-18 Branches: 0 0 0.0 %

Line Branch Exec Source
1
#ifndef SRC_TRACING_NODE_TRACE_WRITER_H_
2
#define SRC_TRACING_NODE_TRACE_WRITER_H_
3
4
#include <sstream>
5
#include <queue>
6
7
#include "node_mutex.h"
8
#include "libplatform/v8-tracing.h"
9
#include "uv.h"
10
11
namespace node {
12
namespace tracing {
13
14
using v8::platform::tracing::TraceObject;
15
using v8::platform::tracing::TraceWriter;
16
17
class NodeTraceWriter : public TraceWriter {
18
 public:
19
  explicit NodeTraceWriter(uv_loop_t* tracing_loop);
20
  ~NodeTraceWriter();
21
22
  void AppendTraceEvent(TraceObject* trace_event) override;
23
  void Flush() override;
24
  void Flush(bool blocking);
25
26
  static const int kTracesPerFile = 1 << 19;
27
28
 private:
29
30
  struct WriteRequest {
30
    uv_fs_t req;
31
    NodeTraceWriter* writer;
32
    std::string str;
33
    int highest_request_id;
34
  };
35
36
  static void WriteCb(uv_fs_t* req);
37
  void OpenNewFileForStreaming();
38
  void WriteToFile(std::string&& str, int highest_request_id);
39
  void WriteSuffix();
40
  static void FlushSignalCb(uv_async_t* signal);
41
  void FlushPrivate();
42
  static void ExitSignalCb(uv_async_t* signal);
43
44
  uv_loop_t* tracing_loop_;
45
  // Triggers callback to initiate writing the contents of stream_ to disk.
46
  uv_async_t flush_signal_;
47
  // Triggers callback to close async objects, ending the tracing thread.
48
  uv_async_t exit_signal_;
49
  // Prevents concurrent R/W on state related to serialized trace data
50
  // before it's written to disk, namely stream_ and total_traces_.
51
  Mutex stream_mutex_;
52
  // Prevents concurrent R/W on state related to write requests.
53
  Mutex request_mutex_;
54
  // Allows blocking calls to Flush() to wait on a condition for
55
  // trace events to be written to disk.
56
  ConditionVariable request_cond_;
57
  // Used to wait until async handles have been closed.
58
  ConditionVariable exit_cond_;
59
  int fd_ = -1;
60
  std::queue<WriteRequest*> write_req_queue_;
61
  int num_write_requests_ = 0;
62
  int highest_request_id_completed_ = 0;
63
  int total_traces_ = 0;
64
  int file_num_ = 0;
65
  std::ostringstream stream_;
66
  TraceWriter* json_trace_writer_ = nullptr;
67
  bool exited_ = false;
68
};
69
70
}  // namespace tracing
71
}  // namespace node
72
73
#endif  // SRC_TRACING_NODE_TRACE_WRITER_H_