GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/tracing/agent.cc Lines: 36 36 100.0 %
Date: 2017-06-14 Branches: 7 10 70.0 %

Line Branch Exec Source
1
#include "tracing/agent.h"
2
3
#include <sstream>
4
#include <string>
5
6
#include "env-inl.h"
7
#include "libplatform/libplatform.h"
8
9
namespace node {
10
namespace tracing {
11
12
using v8::platform::tracing::TraceConfig;
13
using std::string;
14
15
3
Agent::Agent() {}
16
17
3
void Agent::Start(v8::Platform* platform, const string& enabled_categories) {
18
3
  platform_ = platform;
19
20
3
  int err = uv_loop_init(&tracing_loop_);
21
3
  CHECK_EQ(err, 0);
22
23
3
  NodeTraceWriter* trace_writer = new NodeTraceWriter(&tracing_loop_);
24
  TraceBuffer* trace_buffer = new NodeTraceBuffer(
25
3
      NodeTraceBuffer::kBufferChunks, trace_writer, &tracing_loop_);
26
27
3
  tracing_controller_ = new TracingController();
28
29
3
  TraceConfig* trace_config = new TraceConfig();
30
3
  if (!enabled_categories.empty()) {
31
1
    std::stringstream category_list(enabled_categories);
32
3
    while (category_list.good()) {
33
1
      std::string category;
34
1
      getline(category_list, category, ',');
35
1
      trace_config->AddIncludedCategory(category.c_str());
36
2
    }
37
  } else {
38
2
    trace_config->AddIncludedCategory("v8");
39
2
    trace_config->AddIncludedCategory("node");
40
  }
41
42
  // This thread should be created *after* async handles are created
43
  // (within NodeTraceWriter and NodeTraceBuffer constructors).
44
  // Otherwise the thread could shut down prematurely.
45
3
  err = uv_thread_create(&thread_, ThreadCb, this);
46
3
  CHECK_EQ(err, 0);
47
48
3
  tracing_controller_->Initialize(trace_buffer);
49
3
  tracing_controller_->StartTracing(trace_config);
50
3
  v8::platform::SetTracingController(platform, tracing_controller_);
51
3
}
52
53
3
void Agent::Stop() {
54
3
  if (!IsStarted()) {
55
3
    return;
56
  }
57
  // Perform final Flush on TraceBuffer. We don't want the tracing controller
58
  // to flush the buffer again on destruction of the V8::Platform.
59
3
  tracing_controller_->StopTracing();
60
3
  tracing_controller_->Initialize(nullptr);
61
3
  tracing_controller_ = nullptr;
62
63
  // Thread should finish when the tracing loop is stopped.
64
3
  uv_thread_join(&thread_);
65
3
  v8::platform::SetTracingController(platform_, nullptr);
66
}
67
68
// static
69
3
void Agent::ThreadCb(void* arg) {
70
3
  Agent* agent = static_cast<Agent*>(arg);
71
3
  uv_run(&agent->tracing_loop_, UV_RUN_DEFAULT);
72
3
}
73
74
}  // namespace tracing
75
}  // namespace node