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

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

Issue 1314673008: Migrate logging infrastructure Isolate->Thread (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix test. Created 5 years, 3 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
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 "vm/log.h" 5 #include "vm/log.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/thread.h" 8 #include "vm/thread.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 DEFINE_FLAG(bool, force_log_flush, false, "Always flush log messages."); 12 DEFINE_FLAG(bool, force_log_flush, false, "Always flush log messages.");
13 13
14 DEFINE_FLAG(charp, isolate_log_filter, NULL,
15 "Log isolates whose name include the filter. "
16 "Default: service isolate log messages are suppressed.");
17
14 Log::Log(LogPrinter printer) 18 Log::Log(LogPrinter printer)
15 : printer_(printer), 19 : printer_(printer),
16 manual_flush_(0), 20 manual_flush_(0),
17 buffer_(0) { 21 buffer_(0) {
18 } 22 }
19 23
20 24
25 Log::~Log() {
26 // Did someone enable manual flushing and then forgot to Flush?
27 ASSERT(cursor() == 0);
28 }
29
30
31 Log* Log::Current() {
32 Thread* thread = Thread::Current();
33 Isolate* isolate = thread->isolate();
34 if (isolate != NULL && Log::ShouldLogForIsolate(isolate)) {
35 return thread->log();
36 } else {
37 return Log::NoOpLog();
38 }
39 }
40
41
21 void Log::Print(const char* format, ...) { 42 void Log::Print(const char* format, ...) {
22 if (this == NoOpLog()) { 43 if (this == NoOpLog()) {
23 return; 44 return;
24 } 45 }
25 46
26 va_list args; 47 va_list args;
27 va_start(args, format); 48 va_start(args, format);
28 VPrint(format, args); 49 VPrint(format, args);
29 va_end(args); 50 va_end(args);
30 } 51 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 106 }
86 buffer_.TruncateTo(0); 107 buffer_.TruncateTo(0);
87 } 108 }
88 109
89 110
90 intptr_t Log::cursor() const { 111 intptr_t Log::cursor() const {
91 return buffer_.length(); 112 return buffer_.length();
92 } 113 }
93 114
94 115
116 bool Log::ShouldLogForIsolate(const Isolate* isolate) {
117 if (FLAG_isolate_log_filter == NULL) {
118 if (isolate->is_service_isolate()) {
119 // By default, do not log for the service isolate.
120 return false;
121 }
122 return true;
123 }
124 const char* name = isolate->name();
125 ASSERT(name != NULL);
126 if (strstr(name, FLAG_isolate_log_filter) == NULL) {
127 // Filter does not match, do not log for this isolate.
128 return false;
129 }
130 return true;
131 }
132
133
95 Log Log::noop_log_; 134 Log Log::noop_log_;
96 Log* Log::NoOpLog() { 135 Log* Log::NoOpLog() {
97 return &noop_log_; 136 return &noop_log_;
98 } 137 }
99 138
100 139
101 void Log::TerminateString() { 140 void Log::TerminateString() {
102 buffer_.Add('\0'); 141 buffer_.Add('\0');
103 } 142 }
104 143
105 144
106 void Log::EnableManualFlush() { 145 void Log::EnableManualFlush() {
107 manual_flush_++; 146 manual_flush_++;
108 } 147 }
109 148
110 149
111 void Log::DisableManualFlush() { 150 void Log::DisableManualFlush() {
112 manual_flush_--; 151 manual_flush_--;
113 ASSERT(manual_flush_ >= 0); 152 ASSERT(manual_flush_ >= 0);
114 if (manual_flush_ == 0) { 153 if (manual_flush_ == 0) {
115 Flush(); 154 Flush();
116 } 155 }
117 } 156 }
118 157
119 158
120 LogBlock::LogBlock(Thread* thread, Log* log) 159 void LogBlock::Initialize() {
121 : StackResource(thread), 160 log_->EnableManualFlush();
122 log_(log), cursor_(log->cursor()) {
123 CommonConstructor();
124 } 161 }
125 162
126 163
127 LogBlock::LogBlock(Isolate* isolate) 164 LogBlock::~LogBlock() {
128 : StackResource(isolate), 165 log_->Flush(cursor_);
129 log_(isolate->Log()), cursor_(isolate->Log()->cursor()) { 166 log_->DisableManualFlush();
130 CommonConstructor();
131 }
132
133
134 LogBlock::LogBlock(Thread* thread)
135 : StackResource(thread),
136 log_(thread->isolate()->Log()),
137 cursor_(thread->isolate()->Log()->cursor()) {
138 CommonConstructor();
139 } 167 }
140 168
141 } // namespace dart 169 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/log.h ('k') | runtime/vm/log_test.cc » ('j') | runtime/vm/thread.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698