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

Unified Diff: src/base/ring-buffer.h

Issue 2413243002: Introduce a CompilerDispatcherTracer and track how long jobs take (Closed)
Patch Set: updates Created 4 years, 2 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 | « BUILD.gn ('k') | src/compiler-dispatcher/compiler-dispatcher-job.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/ring-buffer.h
diff --git a/src/base/ring-buffer.h b/src/base/ring-buffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..b347977640587e12893bd2ff77d9c8120628c834
--- /dev/null
+++ b/src/base/ring-buffer.h
@@ -0,0 +1,54 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_BASE_RING_BUFFER_H_
+#define V8_BASE_RING_BUFFER_H_
+
+#include "src/base/macros.h"
+
+namespace v8 {
+namespace base {
+
+template <typename T>
+class RingBuffer {
+ public:
+ RingBuffer() { Reset(); }
+ static const int kSize = 10;
+ void Push(const T& value) {
+ if (count_ == kSize) {
+ elements_[start_++] = value;
+ if (start_ == kSize) start_ = 0;
+ } else {
+ DCHECK_EQ(start_, 0);
+ elements_[count_++] = value;
+ }
+ }
+
+ int Count() const { return count_; }
+
+ template <typename Callback>
+ T Sum(Callback callback, const T& initial) const {
+ int j = start_ + count_ - 1;
+ if (j >= kSize) j -= kSize;
+ T result = initial;
+ for (int i = 0; i < count_; i++) {
+ result = callback(result, elements_[j]);
+ if (--j == -1) j += kSize;
+ }
+ return result;
+ }
+
+ void Reset() { start_ = count_ = 0; }
+
+ private:
+ T elements_[kSize];
+ int start_;
+ int count_;
+ DISALLOW_COPY_AND_ASSIGN(RingBuffer);
+};
+
+} // namespace base
+} // namespace v8
+
+#endif // V8_BASE_RING_BUFFER_H_
« no previous file with comments | « BUILD.gn ('k') | src/compiler-dispatcher/compiler-dispatcher-job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698