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

Unified Diff: runtime/vm/log.h

Issue 913503004: Per isolate Log with block support (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/log.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/log.h
diff --git a/runtime/vm/log.h b/runtime/vm/log.h
new file mode 100644
index 0000000000000000000000000000000000000000..be2f12676dd7723b39864a2ad94e45ddaaef773f
--- /dev/null
+++ b/runtime/vm/log.h
@@ -0,0 +1,91 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef VM_LOG_H_
+#define VM_LOG_H_
+
+#include "vm/allocation.h"
+#include "vm/growable_array.h"
+#include "vm/os.h"
+
+namespace dart {
+
+class Isolate;
+class LogBlock;
+class Thread;
+
+#define ISO_Print(format, ...) \
+ Isolate::Current()->Log()->Print(format, ##__VA_ARGS__)
srdjan 2015/02/09 18:34:17 When reading ISO_Print, I think of a standardized
Cutch 2015/02/09 18:51:20 Done.
+
+typedef void (*LogPrinter)(const char* str, ...);
+
+class Log {
+ public:
+ explicit Log(LogPrinter printer = OS::Print);
+
+ // Append a formatted string to the log.
+ void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
+
+ // Flush and truncate the log. The log is flushed starting at cursor
+ // and truncated to cursor afterwards.
+ void Flush(const intptr_t cursor = 0);
+
+ // Clears the log.
+ void Clear();
+
+ // Current cursor.
+ intptr_t cursor() const;
+
+ // A logger that does nothing.
+ static Log* NoOpLog();
+
+ private:
+ void TerminateString();
+ void EnableManualFlush();
+ void DisableManualFlush();
+
+ static Log noop_log_;
+ LogPrinter printer_;
+ intptr_t manual_flush_;
+ MallocGrowableArray<char> buffer_;
+
+ friend class LogBlock;
+ friend class LogTestHelper;
+ DISALLOW_COPY_AND_ASSIGN(Log);
+};
+
+
+class LogBlock : public StackResource {
srdjan 2015/02/09 18:34:17 Please add a brief comment.
Cutch 2015/02/09 18:51:20 Done.
+ public:
+ LogBlock(Isolate* isolate, Log* log)
+ : StackResource(isolate),
+ log_(log), cursor_(log->cursor()) {
+ CommonConstructor();
+ }
+
+ explicit LogBlock(Isolate* isolate);
+ explicit LogBlock(Thread* thread);
+
+ LogBlock(Thread* thread, Log* log);
+
+ ~LogBlock() {
+ CommonDestructor();
+ }
+
+ private:
+ void CommonConstructor() {
+ log_->EnableManualFlush();
+ }
+
+ void CommonDestructor() {
+ log_->Flush(cursor_);
+ log_->DisableManualFlush();
+ }
+ Log* log_;
+ intptr_t cursor_;
srdjan 2015/02/09 18:34:17 const ?
Cutch 2015/02/09 18:51:20 Done.
+};
+
+} // namespace dart
+
+#endif // VM_LOG_H_
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698