| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/gn/trace.h" | 5 #include "tools/gn/trace.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 thread_id_(thread_id) { | 116 thread_id_(thread_id) { |
| 117 } | 117 } |
| 118 | 118 |
| 119 TraceItem::~TraceItem() { | 119 TraceItem::~TraceItem() { |
| 120 } | 120 } |
| 121 | 121 |
| 122 ScopedTrace::ScopedTrace(TraceItem::Type t, const std::string& name) | 122 ScopedTrace::ScopedTrace(TraceItem::Type t, const std::string& name) |
| 123 : item_(nullptr), done_(false) { | 123 : item_(nullptr), done_(false) { |
| 124 if (trace_log) { | 124 if (trace_log) { |
| 125 item_ = new TraceItem(t, name, base::PlatformThread::CurrentId()); | 125 item_ = new TraceItem(t, name, base::PlatformThread::CurrentId()); |
| 126 item_->set_begin(base::TimeTicks::HighResNow()); | 126 item_->set_begin(base::TimeTicks::Now()); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 ScopedTrace::ScopedTrace(TraceItem::Type t, const Label& label) | 130 ScopedTrace::ScopedTrace(TraceItem::Type t, const Label& label) |
| 131 : item_(nullptr), done_(false) { | 131 : item_(nullptr), done_(false) { |
| 132 if (trace_log) { | 132 if (trace_log) { |
| 133 item_ = new TraceItem(t, label.GetUserVisibleName(false), | 133 item_ = new TraceItem(t, label.GetUserVisibleName(false), |
| 134 base::PlatformThread::CurrentId()); | 134 base::PlatformThread::CurrentId()); |
| 135 item_->set_begin(base::TimeTicks::HighResNow()); | 135 item_->set_begin(base::TimeTicks::Now()); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 ScopedTrace::~ScopedTrace() { | 139 ScopedTrace::~ScopedTrace() { |
| 140 Done(); | 140 Done(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ScopedTrace::SetToolchain(const Label& label) { | 143 void ScopedTrace::SetToolchain(const Label& label) { |
| 144 if (item_) | 144 if (item_) |
| 145 item_->set_toolchain(label.GetUserVisibleName(false)); | 145 item_->set_toolchain(label.GetUserVisibleName(false)); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ScopedTrace::SetCommandLine(const base::CommandLine& cmdline) { | 148 void ScopedTrace::SetCommandLine(const base::CommandLine& cmdline) { |
| 149 if (item_) | 149 if (item_) |
| 150 item_->set_cmdline(FilePathToUTF8(cmdline.GetArgumentsString())); | 150 item_->set_cmdline(FilePathToUTF8(cmdline.GetArgumentsString())); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void ScopedTrace::Done() { | 153 void ScopedTrace::Done() { |
| 154 if (!done_) { | 154 if (!done_) { |
| 155 done_ = true; | 155 done_ = true; |
| 156 if (trace_log) { | 156 if (trace_log) { |
| 157 item_->set_end(base::TimeTicks::HighResNow()); | 157 item_->set_end(base::TimeTicks::Now()); |
| 158 AddTrace(item_); | 158 AddTrace(item_); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 void EnableTracing() { | 163 void EnableTracing() { |
| 164 if (!trace_log) | 164 if (!trace_log) |
| 165 trace_log = new TraceLog; | 165 trace_log = new TraceLog; |
| 166 } | 166 } |
| 167 | 167 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 310 } |
| 311 out << "}"; | 311 out << "}"; |
| 312 } | 312 } |
| 313 | 313 |
| 314 out << "]}"; | 314 out << "]}"; |
| 315 | 315 |
| 316 std::string out_str = out.str(); | 316 std::string out_str = out.str(); |
| 317 base::WriteFile(file_name, out_str.data(), | 317 base::WriteFile(file_name, out_str.data(), |
| 318 static_cast<int>(out_str.size())); | 318 static_cast<int>(out_str.size())); |
| 319 } | 319 } |
| OLD | NEW |