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

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

Issue 1314673008: Migrate logging infrastructure Isolate->Thread (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add TODO regarding filtering. 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 #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
18 #if defined(_MSC_VER) 17 #if defined(_MSC_VER)
19 #define ISL_Print(format, ...) \ 18 #define THR_Print(format, ...) \
20 Isolate::Current()->Log()->Print(format, __VA_ARGS__) 19 Thread::Current()->Log()->Print(format, __VA_ARGS__)
21 #else 20 #else
22 #define ISL_Print(format, ...) \ 21 #define THR_Print(format, ...) \
23 Isolate::Current()->Log()->Print(format, ##__VA_ARGS__) 22 Thread::Current()->Log()->Print(format, ##__VA_ARGS__)
24 #endif 23 #endif
25 24
26 #define ISL_VPrint(format, args) \ 25 #define THR_VPrint(format, args) \
27 Isolate::Current()->Log()->VPrint(format, args) 26 Thread::Current()->Log()->VPrint(format, args)
28 27
29 typedef void (*LogPrinter)(const char* str, ...); 28 typedef void (*LogPrinter)(const char* str, ...);
30 29
31 class Log { 30 class Log {
32 public: 31 public:
33 explicit Log(LogPrinter printer = OS::Print); 32 explicit Log(LogPrinter printer = OS::Print);
33 ~Log();
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
38 void VPrint(const char* format, va_list args); 38 void VPrint(const char* format, va_list args);
39 39
40 // Flush and truncate the log. The log is flushed starting at cursor 40 // Flush and truncate the log. The log is flushed starting at cursor
41 // and truncated to cursor afterwards. 41 // and truncated to cursor afterwards.
42 void Flush(const intptr_t cursor = 0); 42 void Flush(const intptr_t cursor = 0);
43 43
44 // Clears the log. 44 // Clears the log.
45 void Clear(); 45 void Clear();
46 46
47 // Current cursor. 47 // Current cursor.
48 intptr_t cursor() const; 48 intptr_t cursor() const;
49 49
50 // Returns false if we should drop log messages related to 'isolate'.
51 static bool ShouldLogForIsolate(const Isolate* isolate);
52
50 // A logger that does nothing. 53 // A logger that does nothing.
51 static Log* NoOpLog(); 54 static Log* NoOpLog();
52 55
53 private: 56 private:
54 void TerminateString(); 57 void TerminateString();
55 void EnableManualFlush(); 58 void EnableManualFlush();
56 void DisableManualFlush(); 59 void DisableManualFlush();
57 60
58 static Log noop_log_; 61 static Log noop_log_;
59 LogPrinter printer_; 62 LogPrinter printer_;
60 intptr_t manual_flush_; 63 intptr_t manual_flush_;
61 MallocGrowableArray<char> buffer_; 64 MallocGrowableArray<char> buffer_;
62 65
63 friend class LogBlock; 66 friend class LogBlock;
64 friend class LogTestHelper; 67 friend class LogTestHelper;
65 DISALLOW_COPY_AND_ASSIGN(Log); 68 DISALLOW_COPY_AND_ASSIGN(Log);
66 }; 69 };
67 70
68 71
69 // Causes all log messages to be buffered until destructor is called. 72 // Causes all log messages to be buffered until destructor is called.
70 // Can be nested. 73 // Can be nested.
71 class LogBlock : public StackResource { 74 class LogBlock : public StackResource {
72 public: 75 public:
73 LogBlock(Isolate* isolate, Log* log) 76 LogBlock(Thread* thread, Log* log) : StackResource(thread) {
74 : StackResource(isolate), 77 Initialize(log);
75 log_(log), cursor_(log->cursor()) {
76 CommonConstructor();
77 } 78 }
78 79
79 explicit LogBlock(Isolate* isolate); 80 explicit LogBlock(Thread* thread) : StackResource(thread) {
80 explicit LogBlock(Thread* thread); 81 Initialize(thread->Log());
81
82 LogBlock(Thread* thread, Log* log);
83
84 ~LogBlock() {
85 CommonDestructor();
86 } 82 }
87 83
84 ~LogBlock();
85
88 private: 86 private:
89 void CommonConstructor() { 87 void Initialize(Log* log);
90 log_->EnableManualFlush();
91 }
92 88
93 void CommonDestructor() {
94 log_->Flush(cursor_);
95 log_->DisableManualFlush();
96 }
97 Log* log_; 89 Log* log_;
98 const intptr_t cursor_; 90 intptr_t cursor_;
99 }; 91 };
100 92
101 } // namespace dart 93 } // namespace dart
102 94
103 #endif // VM_LOG_H_ 95 #endif // VM_LOG_H_
OLDNEW
« no previous file with comments | « runtime/vm/locations.cc ('k') | runtime/vm/log.cc » ('j') | runtime/vm/thread.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698