Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: runtime/vm/timeline.cc

Issue 1274953004: Use real process and thread ids when outputting trace-event (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/timeline.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <cstdlib> 5 #include <cstdlib>
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/json_stream.h" 8 #include "vm/json_stream.h"
9 #include "vm/lockers.h" 9 #include "vm/lockers.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/thread.h" 11 #include "vm/thread.h"
12 #include "vm/timeline.h" 12 #include "vm/timeline.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 DEFINE_FLAG(bool, trace_timeline, false, "Trace timeline code."); 16 DEFINE_FLAG(bool, trace_timeline, false, "Trace timeline code.");
17 DEFINE_FLAG(bool, complete_timeline, false, "Record the complete timeline"); 17 DEFINE_FLAG(bool, complete_timeline, false, "Record the complete timeline");
18 18
19 TimelineEvent::TimelineEvent() 19 TimelineEvent::TimelineEvent()
20 : timestamp0_(0), 20 : timestamp0_(0),
21 timestamp1_(0), 21 timestamp1_(0),
22 arguments_(NULL), 22 arguments_(NULL),
23 arguments_length_(0), 23 arguments_length_(0),
24 state_(0), 24 state_(0),
25 label_(NULL), 25 label_(NULL),
26 stream_(NULL), 26 stream_(NULL),
27 thread_(NULL) { 27 thread_(OSThread::kInvalidThreadId) {
28 } 28 }
29 29
30 30
31 TimelineEvent::~TimelineEvent() { 31 TimelineEvent::~TimelineEvent() {
32 Reset(); 32 Reset();
33 } 33 }
34 34
35 35
36 void TimelineEvent::Reset() { 36 void TimelineEvent::Reset() {
37 set_event_type(kNone); 37 set_event_type(kNone);
38 thread_ = NULL; 38 thread_ = OSThread::kInvalidThreadId;
39 stream_ = NULL; 39 stream_ = NULL;
40 label_ = NULL; 40 label_ = NULL;
41 FreeArguments(); 41 FreeArguments();
42 } 42 }
43 43
44 44
45 int64_t TimelineEvent::AsyncBegin(const char* label) { 45 int64_t TimelineEvent::AsyncBegin(const char* label) {
46 Init(kAsyncBegin, label); 46 Init(kAsyncBegin, label);
47 timestamp0_ = OS::GetCurrentTimeMicros(); 47 timestamp0_ = OS::GetCurrentTimeMicros();
48 ASSERT(stream_ != NULL); 48 ASSERT(stream_ != NULL);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 stream_ = stream; 164 stream_ = stream;
165 } 165 }
166 166
167 167
168 void TimelineEvent::Init(EventType event_type, 168 void TimelineEvent::Init(EventType event_type,
169 const char* label) { 169 const char* label) {
170 ASSERT(label != NULL); 170 ASSERT(label != NULL);
171 set_event_type(event_type); 171 set_event_type(event_type);
172 timestamp0_ = 0; 172 timestamp0_ = 0;
173 timestamp1_ = 0; 173 timestamp1_ = 0;
174 thread_ = Thread::Current(); 174 thread_ = OSThread::GetCurrentThreadId();
175 label_ = label; 175 label_ = label;
176 FreeArguments(); 176 FreeArguments();
177 } 177 }
178 178
179 179
180 static int64_t GetPid(Isolate* isolate) {
181 // Some mapping from Isolate* to an integer process id.
182 // TODO(Cutch): Investigate if process ids can be strings.
183 return static_cast<int64_t>(reinterpret_cast<uintptr_t>(isolate));
184 }
185
186
187 static int64_t GetTid(Thread* thread) {
188 // Some mapping from Thread* to an integer thread id.
189 // TODO(Cutch): Investigate if process ids can be strings.
190 return static_cast<int64_t>(reinterpret_cast<uintptr_t>(thread));
191 }
192
193
194 void TimelineEvent::PrintJSON(JSONStream* stream) const { 180 void TimelineEvent::PrintJSON(JSONStream* stream) const {
195 JSONObject obj(stream); 181 JSONObject obj(stream);
196 int64_t pid = GetPid(Isolate::Current()); 182 int64_t pid = OS::ProcessId();
197 int64_t tid = GetTid(thread_); 183 int64_t tid = OSThread::ThreadIdToIntPtr(thread_);
198 obj.AddProperty("name", label_); 184 obj.AddProperty("name", label_);
199 obj.AddProperty("cat", stream_->name()); 185 obj.AddProperty("cat", stream_->name());
200 obj.AddProperty64("tid", tid); 186 obj.AddProperty64("tid", tid);
201 obj.AddProperty64("pid", pid); 187 obj.AddProperty64("pid", pid);
202 obj.AddPropertyTimeMillis("ts", TimeOrigin()); 188 obj.AddPropertyTimeMillis("ts", TimeOrigin());
203 189
204 switch (event_type()) { 190 switch (event_type()) {
205 case kDuration: { 191 case kDuration: {
206 obj.AddProperty("ph", "X"); 192 obj.AddProperty("ph", "X");
207 obj.AddPropertyTimeMillis("dur", TimeDuration()); 193 obj.AddPropertyTimeMillis("dur", TimeDuration());
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 322
337 event_->SetArgument(i, name, buffer); 323 event_->SetArgument(i, name, buffer);
338 } 324 }
339 325
340 326
341 TimelineEventRecorder::TimelineEventRecorder() { 327 TimelineEventRecorder::TimelineEventRecorder() {
342 } 328 }
343 329
344 330
345 void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const { 331 void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const {
346 Isolate* isolate = Isolate::Current();
347 JSONObject obj(events);
348 int64_t pid = GetPid(isolate);
349 obj.AddProperty("ph", "M");
350 obj.AddProperty64("pid", pid);
351 obj.AddProperty("name", "process_name");
352 {
353 JSONObject args(&obj, "args");
354 args.AddProperty("name", isolate->debugger_name());
355 }
356 } 332 }
357 333
358 334
359 void TimelineEventRecorder::WriteTo(const char* directory) { 335 void TimelineEventRecorder::WriteTo(const char* directory) {
360 Isolate* isolate = Isolate::Current(); 336 Isolate* isolate = Isolate::Current();
361 337
362 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 338 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
363 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); 339 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
364 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); 340 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
365 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { 341 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 length_(0) { 580 length_(0) {
605 } 581 }
606 582
607 583
608 TimelineEvent* TimelineEventBlock::StartEvent() { 584 TimelineEvent* TimelineEventBlock::StartEvent() {
609 ASSERT(!IsFull()); 585 ASSERT(!IsFull());
610 return &events_[length_++]; 586 return &events_[length_++];
611 } 587 }
612 588
613 } // namespace dart 589 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/timeline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698