| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 240a86d commit 863ce4a
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | #include "node_v8_platform-inl.h" | |
| 8 | 8 | #include "permission/permission.h" | |
| 9 | 9 | #include "tracing/agent.h" | |
| 10 | - #include "tracing/node_trace_writer.h" | ||
| 10 | + #include "tracing/trace_event_helper.h" | ||
| 11 | 11 | #include "util-inl.h" | |
| 12 | 12 | ||
| 13 | 13 | #include <set> | |
@@ -90,7 +90,7 @@ void NodeCategorySet::Enable(const FunctionCallbackInfo<Value>& args) { | |||
| 90 | 90 | THROW_IF_INSUFFICIENT_PERMISSIONS( | |
| 91 | 91 | category_set->env(), | |
| 92 | 92 | permission::PermissionScope::kFileSystemWrite, | |
| 93 | - tracing::NodeTraceWriter::GetFilePath( | ||
| 93 | + tracing::GetTraceFilePath( | ||
| 94 | 94 | per_process::cli_options->trace_event_file_pattern, 1)); | |
| 95 | 95 | auto* agent = tracing::Agent::GetInstance(); | |
| 96 | 96 | agent->StartTracing(per_process::cli_options->trace_event_categories); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | #include "env-inl.h" | |
| 7 | 7 | #include "node_options.h" | |
| 8 | 8 | #include "trace_event.h" | |
| 9 | + #include "trace_event_helper.h" | ||
| 9 | 10 | ||
| 10 | 11 | #include "trace_event_perfetto.h" | |
| 11 | 12 | ||
@@ -21,16 +22,6 @@ constexpr uint64_t kReadPeriodMs = 5000; | |||
| 21 | 22 | // trace file grows without bound. | |
| 22 | 23 | constexpr uint64_t kMaxFileSizeBytes = 64 * 1024 * 1024; // 64 MiB | |
| 23 | 24 | ||
| 24 | - void replace_substring(std::string* target, | ||
| 25 | - std::string_view search, | ||
| 26 | - std::string_view insert) { | ||
| 27 | - size_t pos = target->find(search); | ||
| 28 | - for (; pos != std::string::npos; pos = target->find(search, pos)) { | ||
| 29 | - target->replace(pos, search.size(), insert); | ||
| 30 | - pos += insert.size(); | ||
| 31 | - } | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | 25 | std::set<std::string> flatten( | |
| 35 | 26 | const std::unordered_map<int, std::multiset<std::string>>& map) { | |
| 36 | 27 | std::set<std::string> result; | |
@@ -104,9 +95,7 @@ class SimpleWriter : public TraceWriter { | |||
| 104 | 95 | ++file_num_; | |
| 105 | 96 | uv_fs_t req; | |
| 106 | 97 | ||
| 107 | - std::string filepath(log_file_pattern_); | ||
| 108 | - replace_substring(&filepath, "${pid}", std::to_string(uv_os_getpid())); | ||
| 109 | - replace_substring(&filepath, "${rotation}", std::to_string(file_num_)); | ||
| 98 | + std::string filepath = GetTraceFilePath(log_file_pattern_, file_num_); | ||
| 110 | 99 | ||
| 111 | 100 | if (fd_ >= 0) { | |
| 112 | 101 | uv_fs_close(loop_, &req, fd_, nullptr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 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,27 +9,9 @@ | |||
| 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); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,9 +21,6 @@ class NodeTraceWriter : public AsyncTraceWriter { | |||
| 21 | 21 | explicit NodeTraceWriter(const std::string& log_file_pattern); | |
| 22 | 22 | ~NodeTraceWriter() override; | |
| 23 | 23 | ||
| 24 | - static std::string GetFilePath(const std::string& log_file_pattern, | ||
| 25 | - int file_num); | ||
| 26 | - | ||
| 27 | 24 | void InitializeOnThread(uv_loop_t* loop) override; | |
| 28 | 25 | void AppendTraceEvent(TraceObject* trace_event) override; | |
| 29 | 26 | void Flush(bool blocking) override; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,9 @@ | |||
| 1 | 1 | #include "tracing/trace_event_helper.h" | |
| 2 | 2 | #include "node.h" | |
| 3 | + #include "uv.h" | ||
| 4 | + | ||
| 5 | + #include <string> | ||
| 6 | + #include <string_view> | ||
| 3 | 7 | ||
| 4 | 8 | namespace node { | |
| 5 | 9 | namespace tracing { | |
@@ -14,6 +18,26 @@ void TraceEventHelper::SetTracingController(v8::TracingController* controller) { | |||
| 14 | 18 | g_controller = controller; | |
| 15 | 19 | } | |
| 16 | 20 | ||
| 21 | + namespace { | ||
| 22 | + void replace_substring(std::string* target, | ||
| 23 | + std::string_view search, | ||
| 24 | + std::string_view insert) { | ||
| 25 | + size_t pos = target->find(search); | ||
| 26 | + for (; pos != std::string::npos; pos = target->find(search, pos)) { | ||
| 27 | + target->replace(pos, search.size(), insert); | ||
| 28 | + pos += insert.size(); | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + } // namespace | ||
| 32 | + | ||
| 33 | + std::string GetTraceFilePath(std::string_view log_file_pattern, int file_num) { | ||
| 34 | + // Evaluate a JS-style template string that accepts ${pid} and ${rotation}. | ||
| 35 | + std::string filepath(log_file_pattern); | ||
| 36 | + replace_substring(&filepath, "${pid}", std::to_string(uv_os_getpid())); | ||
| 37 | + replace_substring(&filepath, "${rotation}", std::to_string(file_num)); | ||
| 38 | + return filepath; | ||
| 39 | + } | ||
| 40 | + | ||
| 17 | 41 | } // namespace tracing | |
| 18 | 42 | ||
| 19 | 43 | v8::TracingController* GetTracingController() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,15 @@ | |||
| 5 | 5 | ||
| 6 | 6 | #include "v8-platform.h" | |
| 7 | 7 | ||
| 8 | + #include <string> | ||
| 9 | + #include <string_view> | ||
| 10 | + | ||
| 8 | 11 | namespace node::tracing { | |
| 9 | 12 | ||
| 13 | + // Expands a trace log file pattern into a concrete path, substituting ${pid} | ||
| 14 | + // and ${rotation}. | ||
| 15 | + std::string GetTraceFilePath(std::string_view log_file_pattern, int file_num); | ||
| 16 | + | ||
| 10 | 17 | class TraceEventHelper { | |
| 11 | 18 | public: | |
| 12 | 19 | static v8::TracingController* GetTracingController(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments