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

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

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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_analysis.cc ('k') | runtime/vm/timer.h » ('j') | 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 <cstring> 5 #include <cstring>
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 8
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
11 #include "vm/globals.h" 11 #include "vm/globals.h"
12 #include "vm/timeline.h" 12 #include "vm/timeline.h"
13 #include "vm/timeline_analysis.h" 13 #include "vm/timeline_analysis.h"
14 #include "vm/unit_test.h" 14 #include "vm/unit_test.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 #ifndef PRODUCT 18 #ifndef PRODUCT
19 19
20 class TimelineRecorderOverride : public ValueObject { 20 class TimelineRecorderOverride : public ValueObject {
21 public: 21 public:
22 explicit TimelineRecorderOverride(TimelineEventRecorder* new_recorder) 22 explicit TimelineRecorderOverride(TimelineEventRecorder* new_recorder)
23 : recorder_(Timeline::recorder()) { 23 : recorder_(Timeline::recorder()) {
24 Timeline::recorder_ = new_recorder; 24 Timeline::recorder_ = new_recorder;
25 } 25 }
26 26
27 ~TimelineRecorderOverride() { 27 ~TimelineRecorderOverride() { Timeline::recorder_ = recorder_; }
28 Timeline::recorder_ = recorder_;
29 }
30 28
31 private: 29 private:
32 TimelineEventRecorder* recorder_; 30 TimelineEventRecorder* recorder_;
33 }; 31 };
34 32
35 33
36 class TimelineTestHelper : public AllStatic { 34 class TimelineTestHelper : public AllStatic {
37 public: 35 public:
38 static void SetStream(TimelineEvent* event, TimelineStream* stream) { 36 static void SetStream(TimelineEvent* event, TimelineStream* stream) {
39 event->StreamInit(stream); 37 event->StreamInit(stream);
40 } 38 }
41 39
42 static void FakeThreadEvent( 40 static void FakeThreadEvent(TimelineEventBlock* block,
43 TimelineEventBlock* block, 41 intptr_t ftid,
44 intptr_t ftid, 42 const char* label = "fake",
45 const char* label = "fake", 43 TimelineStream* stream = NULL) {
46 TimelineStream* stream = NULL) {
47 TimelineEvent* event = block->StartEvent(); 44 TimelineEvent* event = block->StartEvent();
48 ASSERT(event != NULL); 45 ASSERT(event != NULL);
49 event->DurationBegin(label); 46 event->DurationBegin(label);
50 event->thread_ = OSThread::ThreadIdFromIntPtr(ftid); 47 event->thread_ = OSThread::ThreadIdFromIntPtr(ftid);
51 if (stream != NULL) { 48 if (stream != NULL) {
52 event->StreamInit(stream); 49 event->StreamInit(stream);
53 } 50 }
54 } 51 }
55 52
56 static void SetBlockThread(TimelineEventBlock* block, 53 static void SetBlockThread(TimelineEventBlock* block, intptr_t ftid) {
57 intptr_t ftid) {
58 block->thread_id_ = OSThread::ThreadIdFromIntPtr(ftid); 54 block->thread_id_ = OSThread::ThreadIdFromIntPtr(ftid);
59 } 55 }
60 56
61 static void FakeDuration( 57 static void FakeDuration(TimelineEventRecorder* recorder,
62 TimelineEventRecorder* recorder, 58 const char* label,
63 const char* label, 59 int64_t start,
64 int64_t start, 60 int64_t end) {
65 int64_t end) {
66 ASSERT(recorder != NULL); 61 ASSERT(recorder != NULL);
67 ASSERT(start < end); 62 ASSERT(start < end);
68 ASSERT(label != NULL); 63 ASSERT(label != NULL);
69 TimelineEvent* event = recorder->StartEvent(); 64 TimelineEvent* event = recorder->StartEvent();
70 ASSERT(event != NULL); 65 ASSERT(event != NULL);
71 event->Duration(label, start, end); 66 event->Duration(label, start, end);
72 event->Complete(); 67 event->Complete();
73 } 68 }
74 69
75 static void FakeBegin( 70 static void FakeBegin(TimelineEventRecorder* recorder,
76 TimelineEventRecorder* recorder, 71 const char* label,
77 const char* label, 72 int64_t start) {
78 int64_t start) {
79 ASSERT(recorder != NULL); 73 ASSERT(recorder != NULL);
80 ASSERT(label != NULL); 74 ASSERT(label != NULL);
81 ASSERT(start >= 0); 75 ASSERT(start >= 0);
82 TimelineEvent* event = recorder->StartEvent(); 76 TimelineEvent* event = recorder->StartEvent();
83 ASSERT(event != NULL); 77 ASSERT(event != NULL);
84 event->Begin(label, start); 78 event->Begin(label, start);
85 event->Complete(); 79 event->Complete();
86 } 80 }
87 81
88 static void FakeEnd( 82 static void FakeEnd(TimelineEventRecorder* recorder,
89 TimelineEventRecorder* recorder, 83 const char* label,
90 const char* label, 84 int64_t end) {
91 int64_t end) {
92 ASSERT(recorder != NULL); 85 ASSERT(recorder != NULL);
93 ASSERT(label != NULL); 86 ASSERT(label != NULL);
94 ASSERT(end >= 0); 87 ASSERT(end >= 0);
95 TimelineEvent* event = recorder->StartEvent(); 88 TimelineEvent* event = recorder->StartEvent();
96 ASSERT(event != NULL); 89 ASSERT(event != NULL);
97 event->End(label, end); 90 event->End(label, end);
98 event->Complete(); 91 event->Complete();
99 } 92 }
100 93
101 static void Clear(TimelineEventEndlessRecorder* recorder) { 94 static void Clear(TimelineEventEndlessRecorder* recorder) {
102 ASSERT(recorder != NULL); 95 ASSERT(recorder != NULL);
103 recorder->Clear(); 96 recorder->Clear();
104 } 97 }
105 98
106 static void FinishBlock(TimelineEventBlock* block) { 99 static void FinishBlock(TimelineEventBlock* block) { block->Finish(); }
107 block->Finish();
108 }
109 }; 100 };
110 101
111 102
112 TEST_CASE(TimelineEventIsValid) { 103 TEST_CASE(TimelineEventIsValid) {
113 // Create a test stream. 104 // Create a test stream.
114 TimelineStream stream; 105 TimelineStream stream;
115 stream.Init("testStream", true); 106 stream.Init("testStream", true);
116 107
117 TimelineEvent event; 108 TimelineEvent event;
118 TimelineTestHelper::SetStream(&event, &stream); 109 TimelineTestHelper::SetStream(&event, &stream);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 273
283 // Count the number of each event type seen. 274 // Count the number of each event type seen.
284 class EventCounterRecorder : public TimelineEventCallbackRecorder { 275 class EventCounterRecorder : public TimelineEventCallbackRecorder {
285 public: 276 public:
286 EventCounterRecorder() { 277 EventCounterRecorder() {
287 for (intptr_t i = 0; i < TimelineEvent::kNumEventTypes; i++) { 278 for (intptr_t i = 0; i < TimelineEvent::kNumEventTypes; i++) {
288 counts_[i] = 0; 279 counts_[i] = 0;
289 } 280 }
290 } 281 }
291 282
292 void OnEvent(TimelineEvent* event) { 283 void OnEvent(TimelineEvent* event) { counts_[event->event_type()]++; }
293 counts_[event->event_type()]++;
294 }
295 284
296 intptr_t CountFor(TimelineEvent::EventType type) { 285 intptr_t CountFor(TimelineEvent::EventType type) { return counts_[type]; }
297 return counts_[type];
298 }
299 286
300 private: 287 private:
301 intptr_t counts_[TimelineEvent::kNumEventTypes]; 288 intptr_t counts_[TimelineEvent::kNumEventTypes];
302 }; 289 };
303 290
304 291
305 TEST_CASE(TimelineEventCallbackRecorderBasic) { 292 TEST_CASE(TimelineEventCallbackRecorderBasic) {
306 EventCounterRecorder* recorder = new EventCounterRecorder(); 293 EventCounterRecorder* recorder = new EventCounterRecorder();
307 TimelineRecorderOverride override(recorder); 294 TimelineRecorderOverride override(recorder);
308 295
309 // Initial counts are all zero. 296 // Initial counts are all zero.
310 for (intptr_t i = TimelineEvent::kNone + 1; 297 for (intptr_t i = TimelineEvent::kNone + 1; i < TimelineEvent::kNumEventTypes;
311 i < TimelineEvent::kNumEventTypes;
312 i++) { 298 i++) {
313 EXPECT_EQ(0, recorder->CountFor(static_cast<TimelineEvent::EventType>(i))); 299 EXPECT_EQ(0, recorder->CountFor(static_cast<TimelineEvent::EventType>(i)));
314 } 300 }
315 301
316 // Create a test stream. 302 // Create a test stream.
317 TimelineStream stream; 303 TimelineStream stream;
318 stream.Init("testStream", true); 304 stream.Init("testStream", true);
319 305
320 TimelineEvent* event = NULL; 306 TimelineEvent* event = NULL;
321 307
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 pauses.Setup(); 882 pauses.Setup();
897 pauses.CalculatePauseTimesForThread(tid); 883 pauses.CalculatePauseTimesForThread(tid);
898 EXPECT(pauses.has_error()); 884 EXPECT(pauses.has_error());
899 } 885 }
900 TimelineTestHelper::Clear(recorder); 886 TimelineTestHelper::Clear(recorder);
901 } 887 }
902 888
903 #endif // !PRODUCT 889 #endif // !PRODUCT
904 890
905 } // namespace dart 891 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/timeline_analysis.cc ('k') | runtime/vm/timer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698