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

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

Issue 328663008: Add support to trace warnings in TraceBuffer. (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/isolate.h"
6 #include "vm/json_stream.h" 6 #include "vm/json_stream.h"
7 #include "vm/object.h"
7 #include "vm/os.h" 8 #include "vm/os.h"
8 #include "vm/trace_buffer.h" 9 #include "vm/trace_buffer.h"
9 10
10 namespace dart { 11 namespace dart {
11 12
12 TraceBuffer::TraceBuffer(Isolate* isolate, intptr_t capacity) 13 TraceBuffer::TraceBuffer(Isolate* isolate, intptr_t capacity)
13 : isolate_(isolate), ring_capacity_(capacity) { 14 : isolate_(isolate), ring_capacity_(capacity) {
14 ring_cursor_ = 0; 15 ring_cursor_ = 0;
15 ring_ = reinterpret_cast<TraceBufferEntry*>( 16 ring_ = reinterpret_cast<TraceBufferEntry*>(
16 calloc(ring_capacity_, sizeof(TraceBufferEntry))); // NOLINT 17 calloc(ring_capacity_, sizeof(TraceBufferEntry))); // NOLINT
(...skipping 16 matching lines...) Expand all
33 isolate->set_trace_buffer(trace_buffer); 34 isolate->set_trace_buffer(trace_buffer);
34 } 35 }
35 36
36 37
37 void TraceBuffer::Clear() { 38 void TraceBuffer::Clear() {
38 for (intptr_t i = 0; i < ring_capacity_; i++) { 39 for (intptr_t i = 0; i < ring_capacity_; i++) {
39 TraceBufferEntry& entry = ring_[i]; 40 TraceBufferEntry& entry = ring_[i];
40 entry.micros = 0; 41 entry.micros = 0;
41 free(entry.message); 42 free(entry.message);
42 entry.message = NULL; 43 entry.message = NULL;
44 entry.message_is_escaped = false;
43 } 45 }
44 ring_cursor_ = 0; 46 ring_cursor_ = 0;
45 } 47 }
46 48
47 49
48 void TraceBuffer::Fill(TraceBufferEntry* entry, int64_t micros, char* msg) { 50 void TraceBuffer::Fill(TraceBufferEntry* entry, int64_t micros,
51 char* msg, bool msg_is_escaped) {
49 if (entry->message != NULL) { 52 if (entry->message != NULL) {
50 // Recycle TraceBufferEntry. 53 // Recycle TraceBufferEntry.
51 free(entry->message); 54 free(entry->message);
52 } 55 }
53 entry->message = msg; 56 entry->message = msg;
57 entry->message_is_escaped = msg_is_escaped;
54 entry->micros = micros; 58 entry->micros = micros;
55 } 59 }
56 60
57 61
58 void TraceBuffer::AppendTrace(int64_t micros, char* message) { 62 void TraceBuffer::AppendTrace(int64_t micros, char* msg, bool msg_is_escaped) {
59 const intptr_t index = ring_cursor_; 63 const intptr_t index = ring_cursor_;
60 TraceBufferEntry* trace_entry = &ring_[index]; 64 TraceBufferEntry* trace_entry = &ring_[index];
61 Fill(trace_entry, micros, message); 65 Fill(trace_entry, micros, msg, msg_is_escaped);
62 ring_cursor_ = RingIndex(ring_cursor_ + 1); 66 ring_cursor_ = RingIndex(ring_cursor_ + 1);
63 } 67 }
64 68
65 69
66 void TraceBuffer::Trace(int64_t micros, const char* message) { 70 void TraceBuffer::Trace(int64_t micros, const char* msg, bool msg_is_escaped) {
67 ASSERT(message != NULL); 71 ASSERT(msg != NULL);
68 char* message_copy = strdup(message); 72 char* message_copy = strdup(msg);
69 AppendTrace(micros, message_copy); 73 AppendTrace(micros, message_copy, msg_is_escaped);
70 } 74 }
71 75
72 76
73 void TraceBuffer::Trace(const char* message) { 77 void TraceBuffer::Trace(const char* msg, bool msg_is_escaped) {
74 Trace(OS::GetCurrentTimeMicros(), message); 78 Trace(OS::GetCurrentTimeMicros(), msg, msg_is_escaped);
75 } 79 }
76 80
77 81
78 void TraceBuffer::TraceF(const char* format, ...) { 82 void TraceBuffer::TraceF(const char* format, ...) {
79 int64_t micros = OS::GetCurrentTimeMicros(); 83 const int64_t micros = OS::GetCurrentTimeMicros();
80 va_list args; 84 va_list args;
81 va_start(args, format); 85 va_start(args, format);
82 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 86 const intptr_t len = OS::VSNPrint(NULL, 0, format, args);
83 va_end(args); 87 va_end(args);
84 char* p = reinterpret_cast<char*>(malloc(len+1)); 88 char* p = reinterpret_cast<char*>(malloc(len+1));
85 va_start(args, format); 89 va_start(args, format);
86 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); 90 const intptr_t len2 = OS::VSNPrint(p, len+1, format, args);
87 va_end(args); 91 va_end(args);
88 ASSERT(len == len2); 92 ASSERT(len == len2);
89 AppendTrace(micros, p); 93 AppendTrace(micros, p);
90 } 94 }
91 95
92 96
93 void TraceBuffer::PrintToJSONStream(JSONStream* stream) const { 97 void TraceBuffer::PrintToJSONStream(JSONStream* stream) const {
94 JSONObject json_trace_buffer(stream); 98 JSONObject json_trace_buffer(stream);
95 json_trace_buffer.AddProperty("type", "TraceBuffer"); 99 json_trace_buffer.AddProperty("type", "TraceBuffer");
96 // TODO(johnmccutchan): Send cursor position in response. 100 // TODO(johnmccutchan): Send cursor position in response.
(...skipping 17 matching lines...) Expand all
114 const TraceBufferEntry& entry = ring_[index]; 118 const TraceBufferEntry& entry = ring_[index];
115 if (entry.empty()) { 119 if (entry.empty()) {
116 // Empty entry, stop. 120 // Empty entry, stop.
117 break; 121 break;
118 } 122 }
119 JSONObject trace_entry(&json_trace_buffer_array); 123 JSONObject trace_entry(&json_trace_buffer_array);
120 trace_entry.AddProperty("type", "TraceBufferEntry"); 124 trace_entry.AddProperty("type", "TraceBufferEntry");
121 double seconds = static_cast<double>(entry.micros) / 125 double seconds = static_cast<double>(entry.micros) /
122 static_cast<double>(kMicrosecondsPerSecond); 126 static_cast<double>(kMicrosecondsPerSecond);
123 trace_entry.AddProperty("time", seconds); 127 trace_entry.AddProperty("time", seconds);
124 trace_entry.AddProperty("message", entry.message); 128 if (entry.message_is_escaped) {
129 trace_entry.AddPropertyNoEscape("message", entry.message);
130 } else {
131 trace_entry.AddProperty("message", entry.message);
132 }
125 } 133 }
126 } 134 }
127 135
128 } // namespace dart 136 } // 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