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

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

Issue 327803003: Provide the isolate with a trace buffer, but do not allocate one by default. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/trace_buffer.h ('k') | runtime/vm/trace_buffer_test.cc » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "vm/isolate.h"
5 #include "vm/json_stream.h" 6 #include "vm/json_stream.h"
6 #include "vm/os.h" 7 #include "vm/os.h"
7 #include "vm/trace_buffer.h" 8 #include "vm/trace_buffer.h"
8 9
9 namespace dart { 10 namespace dart {
10 11
11 TraceBuffer::TraceBuffer(intptr_t capacity) : ring_capacity_(capacity) { 12 TraceBuffer::TraceBuffer(Isolate* isolate, intptr_t capacity)
13 : isolate_(isolate), ring_capacity_(capacity) {
12 ring_cursor_ = 0; 14 ring_cursor_ = 0;
13 Init(); 15 ring_ = reinterpret_cast<TraceBufferEntry*>(
16 calloc(ring_capacity_, sizeof(TraceBufferEntry))); // NOLINT
14 } 17 }
15 18
16 19
17 TraceBuffer::~TraceBuffer() { 20 TraceBuffer::~TraceBuffer() {
18 ASSERT(ring_ != NULL); 21 ASSERT(ring_ != NULL);
19 Clear(); 22 Clear();
20 free(ring_); 23 free(ring_);
24 if (isolate_ != NULL) {
25 isolate_->set_trace_buffer(NULL);
26 isolate_ = NULL;
27 }
21 } 28 }
22 29
23 30
24 void TraceBuffer::Init() { 31 void TraceBuffer::Init(Isolate* isolate, intptr_t capacity) {
25 ring_ = reinterpret_cast<TraceBufferEntry*>( 32 TraceBuffer* trace_buffer = new TraceBuffer(isolate, capacity);
26 calloc(ring_capacity_, sizeof(TraceBufferEntry))); // NOLINT 33 isolate->set_trace_buffer(trace_buffer);
27 } 34 }
28 35
29 36
30 void TraceBuffer::Clear() { 37 void TraceBuffer::Clear() {
31 for (intptr_t i = 0; i < ring_capacity_; i++) { 38 for (intptr_t i = 0; i < ring_capacity_; i++) {
32 TraceBufferEntry& entry = ring_[i]; 39 TraceBufferEntry& entry = ring_[i];
33 entry.micros = 0; 40 entry.micros = 0;
34 free(entry.message); 41 free(entry.message);
35 entry.message = NULL; 42 entry.message = NULL;
36 } 43 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 JSONObject trace_entry(&json_trace_buffer_array); 119 JSONObject trace_entry(&json_trace_buffer_array);
113 trace_entry.AddProperty("type", "TraceBufferEntry"); 120 trace_entry.AddProperty("type", "TraceBufferEntry");
114 double seconds = static_cast<double>(entry.micros) / 121 double seconds = static_cast<double>(entry.micros) /
115 static_cast<double>(kMicrosecondsPerSecond); 122 static_cast<double>(kMicrosecondsPerSecond);
116 trace_entry.AddProperty("time", seconds); 123 trace_entry.AddProperty("time", seconds);
117 trace_entry.AddProperty("message", entry.message); 124 trace_entry.AddProperty("message", entry.message);
118 } 125 }
119 } 126 }
120 127
121 } // namespace dart 128 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/trace_buffer.h ('k') | runtime/vm/trace_buffer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698