|
1 | 1 | #include "tracing/node_trace_writer.h" |
| 2 | +#include "tracing/trace_event_helper.h" |
2 | 3 |
|
3 | 4 | #include "util-inl.h" |
4 | 5 |
|
|
8 | 9 | namespace node { |
9 | 10 | namespace tracing { |
10 | 11 |
|
11 | | -void replace_substring(std::string* target, |
12 | | - const std::string& search, |
13 | | - const std::string& insert) { |
14 | | - size_t pos = target->find(search); |
15 | | - for (; pos != std::string::npos; pos = target->find(search, pos)) { |
16 | | - target->replace(pos, search.size(), insert); |
17 | | - pos += insert.size(); |
18 | | - } |
19 | | -} |
20 | | - |
21 | 12 | NodeTraceWriter::NodeTraceWriter(const std::string& log_file_pattern) |
22 | 13 | : log_file_pattern_(log_file_pattern) {} |
23 | 14 |
|
24 | | -std::string NodeTraceWriter::GetFilePath(const std::string& log_file_pattern, |
25 | | - int file_num) { |
26 | | - std::string filepath(log_file_pattern); |
27 | | - replace_substring(&filepath, "${pid}", std::to_string(uv_os_getpid())); |
28 | | - replace_substring(&filepath, "${rotation}", std::to_string(file_num)); |
29 | | - return filepath; |
30 | | -} |
31 | | - |
32 | 15 | void NodeTraceWriter::InitializeOnThread(uv_loop_t* loop) { |
33 | 16 | CHECK_NULL(tracing_loop_); |
34 | 17 | tracing_loop_ = loop; |
@@ -82,9 +65,7 @@ void NodeTraceWriter::OpenNewFileForStreaming() { |
82 | 65 | ++file_num_; |
83 | 66 | uv_fs_t req; |
84 | 67 |
|
85 | | - // Evaluate a JS-style template string, it accepts the values ${pid} and |
86 | | - // ${rotation} |
87 | | - std::string filepath(GetFilePath(log_file_pattern_, file_num_)); |
| 68 | + std::string filepath = GetTraceFilePath(log_file_pattern_, file_num_); |
88 | 69 |
|
89 | 70 | if (fd_ != -1) { |
90 | 71 | CHECK_EQ(uv_fs_close(nullptr, &req, fd_, nullptr), 0); |
|
0 commit comments