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_buffer.h Lines: 4 6 66.7 %
Date: 2017-10-21 Branches: 1 4 25.0 %

Line Branch Exec Source
1
#ifndef SRC_TRACING_NODE_TRACE_BUFFER_H_
2
#define SRC_TRACING_NODE_TRACE_BUFFER_H_
3
4
#include "node_mutex.h"
5
#include "tracing/node_trace_writer.h"
6
#include "libplatform/v8-tracing.h"
7
8
#include <atomic>
9
10
namespace node {
11
namespace tracing {
12
13
using v8::platform::tracing::TraceBuffer;
14
using v8::platform::tracing::TraceBufferChunk;
15
using v8::platform::tracing::TraceObject;
16
17
// forward declaration
18
class NodeTraceBuffer;
19
20
6
class InternalTraceBuffer {
21
 public:
22
  InternalTraceBuffer(size_t max_chunks, uint32_t id,
23
                      NodeTraceWriter* trace_writer);
24
25
  TraceObject* AddTraceEvent(uint64_t* handle);
26
  TraceObject* GetEventByHandle(uint64_t handle);
27
  void Flush(bool blocking);
28
469
  bool IsFull() const {
29

469
    return total_chunks_ == max_chunks_ && chunks_[total_chunks_ - 1]->IsFull();
30
  }
31
  bool IsFlushing() const {
32
    return flushing_;
33
  }
34
35
 private:
36
  uint64_t MakeHandle(size_t chunk_index, uint32_t chunk_seq,
37
                      size_t event_index) const;
38
  void ExtractHandle(uint64_t handle, uint32_t* buffer_id, size_t* chunk_index,
39
                     uint32_t* chunk_seq, size_t* event_index) const;
40
499
  size_t Capacity() const { return max_chunks_ * TraceBufferChunk::kChunkSize; }
41
42
  Mutex mutex_;
43
  bool flushing_;
44
  size_t max_chunks_;
45
  NodeTraceWriter* trace_writer_;
46
  std::vector<std::unique_ptr<TraceBufferChunk>> chunks_;
47
  size_t total_chunks_ = 0;
48
  uint32_t current_chunk_seq_ = 1;
49
  uint32_t id_;
50
};
51
52
class NodeTraceBuffer : public TraceBuffer {
53
 public:
54
  NodeTraceBuffer(size_t max_chunks, NodeTraceWriter* trace_writer,
55
                  uv_loop_t* tracing_loop);
56
  ~NodeTraceBuffer();
57
58
  TraceObject* AddTraceEvent(uint64_t* handle) override;
59
  TraceObject* GetEventByHandle(uint64_t handle) override;
60
  bool Flush() override;
61
62
  static const size_t kBufferChunks = 1024;
63
64
 private:
65
  bool TryLoadAvailableBuffer();
66
  static void NonBlockingFlushSignalCb(uv_async_t* signal);
67
  static void ExitSignalCb(uv_async_t* signal);
68
69
  uv_loop_t* tracing_loop_;
70
  uv_async_t flush_signal_;
71
  uv_async_t exit_signal_;
72
  bool exited_ = false;
73
  // Used exclusively for exit logic.
74
  Mutex exit_mutex_;
75
  // Used to wait until async handles have been closed.
76
  ConditionVariable exit_cond_;
77
  std::unique_ptr<NodeTraceWriter> trace_writer_;
78
  std::atomic<InternalTraceBuffer*> current_buf_;
79
  InternalTraceBuffer buffer1_;
80
  InternalTraceBuffer buffer2_;
81
};
82
83
}  // namespace tracing
84
}  // namespace node
85
86
#endif  // SRC_TRACING_NODE_TRACE_BUFFER_H_