Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef VM_LOG_H_ | 5 #ifndef VM_LOG_H_ |
| 6 #define VM_LOG_H_ | 6 #define VM_LOG_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/growable_array.h" | 9 #include "vm/growable_array.h" |
| 10 #include "vm/os.h" | 10 #include "vm/os.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class Isolate; | |
| 15 class LogBlock; | 14 class LogBlock; |
| 16 class Thread; | 15 class Thread; |
| 17 | 16 |
| 17 // TODO(koda): Rename ISL_* -> THR_*. | |
|
Ivan Posva
2015/09/08 21:22:22
Why not do the rename right now?
koda
2015/09/09 00:26:57
Done.
| |
| 18 #if defined(_MSC_VER) | 18 #if defined(_MSC_VER) |
| 19 #define ISL_Print(format, ...) \ | 19 #define ISL_Print(format, ...) \ |
| 20 Isolate::Current()->Log()->Print(format, __VA_ARGS__) | 20 Thread::Current()->Log()->Print(format, __VA_ARGS__) |
| 21 #else | 21 #else |
| 22 #define ISL_Print(format, ...) \ | 22 #define ISL_Print(format, ...) \ |
| 23 Isolate::Current()->Log()->Print(format, ##__VA_ARGS__) | 23 Thread::Current()->Log()->Print(format, ##__VA_ARGS__) |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #define ISL_VPrint(format, args) \ | 26 #define ISL_VPrint(format, args) \ |
| 27 Isolate::Current()->Log()->VPrint(format, args) | 27 Thread::Current()->Log()->VPrint(format, args) |
| 28 | 28 |
| 29 typedef void (*LogPrinter)(const char* str, ...); | 29 typedef void (*LogPrinter)(const char* str, ...); |
| 30 | 30 |
| 31 class Log { | 31 class Log { |
| 32 public: | 32 public: |
| 33 explicit Log(LogPrinter printer = OS::Print); | 33 explicit Log(LogPrinter printer = OS::Print); |
| 34 | 34 |
| 35 // Append a formatted string to the log. | 35 // Append a formatted string to the log. |
| 36 void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 36 void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 37 | 37 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 63 friend class LogBlock; | 63 friend class LogBlock; |
| 64 friend class LogTestHelper; | 64 friend class LogTestHelper; |
| 65 DISALLOW_COPY_AND_ASSIGN(Log); | 65 DISALLOW_COPY_AND_ASSIGN(Log); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 | 68 |
| 69 // Causes all log messages to be buffered until destructor is called. | 69 // Causes all log messages to be buffered until destructor is called. |
| 70 // Can be nested. | 70 // Can be nested. |
| 71 class LogBlock : public StackResource { | 71 class LogBlock : public StackResource { |
| 72 public: | 72 public: |
| 73 LogBlock(Isolate* isolate, Log* log) | 73 LogBlock(Thread* thread, Log* log) |
| 74 : StackResource(isolate), | 74 : StackResource(thread), |
| 75 log_(log), cursor_(log->cursor()) { | 75 log_(log), cursor_(log->cursor()) { |
| 76 CommonConstructor(); | 76 CommonConstructor(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 explicit LogBlock(Isolate* isolate); | |
| 80 explicit LogBlock(Thread* thread); | 79 explicit LogBlock(Thread* thread); |
|
Ivan Posva
2015/09/08 21:22:22
Is there a particular reason to have this construc
koda
2015/09/09 00:26:57
Done.
| |
| 81 | 80 |
| 82 LogBlock(Thread* thread, Log* log); | |
| 83 | |
| 84 ~LogBlock() { | 81 ~LogBlock() { |
| 85 CommonDestructor(); | 82 CommonDestructor(); |
|
Ivan Posva
2015/09/08 21:22:22
ditto.
Please move to .cc file and remove the unn
koda
2015/09/09 00:26:57
Done.
| |
| 86 } | 83 } |
| 87 | 84 |
| 88 private: | 85 private: |
| 89 void CommonConstructor() { | 86 void CommonConstructor() { |
| 90 log_->EnableManualFlush(); | 87 log_->EnableManualFlush(); |
| 91 } | 88 } |
| 92 | 89 |
| 93 void CommonDestructor() { | 90 void CommonDestructor() { |
| 94 log_->Flush(cursor_); | 91 log_->Flush(cursor_); |
| 95 log_->DisableManualFlush(); | 92 log_->DisableManualFlush(); |
| 96 } | 93 } |
| 97 Log* log_; | 94 Log* log_; |
| 98 const intptr_t cursor_; | 95 const intptr_t cursor_; |
| 99 }; | 96 }; |
| 100 | 97 |
| 101 } // namespace dart | 98 } // namespace dart |
| 102 | 99 |
| 103 #endif // VM_LOG_H_ | 100 #endif // VM_LOG_H_ |
| OLD | NEW |