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

Unified Diff: gpu/command_buffer/service/memory_tracking.h

Issue 10796096: Add tracing of all memory allocated in all contexts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add global memory usage tracking Created 8 years, 5 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
Index: gpu/command_buffer/service/memory_tracking.h
diff --git a/gpu/command_buffer/service/memory_tracking.h b/gpu/command_buffer/service/memory_tracking.h
new file mode 100644
index 0000000000000000000000000000000000000000..3661ddb2b80a2372d330f4b801790b9830c4b69b
--- /dev/null
+++ b/gpu/command_buffer/service/memory_tracking.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2012 The Chromium 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 GPU_COMMAND_BUFFER_SERVICE_MEMORY_TRACKING_H_
+#define GPU_COMMAND_BUFFER_SERVICE_MEMORY_TRACKING_H_
+
+#include <string>
+#include "base/basictypes.h"
+#include "base/debug/trace_event.h"
+
+namespace gpu {
+namespace gles2 {
+
+// A MemoryTracker is used to propagate per-ContextGroup memory usage
+// statistics to the global GpuMemoryManager.
+class MemoryTracker : public base::RefCounted<MemoryTracker> {
+ public:
+ virtual ~MemoryTracker() {};
+ virtual void TrackMemoryAllocatedChange(size_t old_size, size_t new_size) = 0;
+};
+
+// A MemoryTypeTracker tracks the use of a particular type of memory (buffer,
+// texture, or renderbuffer) and forward the result to a specified
+// MemoryTracker.
+class MemoryTypeTracker {
+ public:
+ MemoryTypeTracker(
+ MemoryTracker* memory_tracker,
+ const char* trace_category,
+ const char* trace_name)
+ : memory_tracker_(memory_tracker),
+ trace_category_(trace_category),
+ trace_name_(trace_name),
+ has_updated_mem_represented_(false),
+ last_updated_mem_represented_(0) {
+ }
+
+ void UpdateMemRepresented(size_t mem_represented) {
+ if (!has_updated_mem_represented_ &&
+ mem_represented == last_updated_mem_represented_) {
+ return;
+ }
+ if (memory_tracker_) {
+ memory_tracker_->TrackMemoryAllocatedChange(
+ last_updated_mem_represented_,
+ mem_represented);
+ }
+ has_updated_mem_represented_ = true;
+ last_updated_mem_represented_ = mem_represented;
+ TRACE_COUNTER_ID1(trace_category_,
+ trace_name_,
+ memory_tracker_ ? memory_tracker_ : this,
+ last_updated_mem_represented_);
+ }
+
+ private:
+ MemoryTracker* memory_tracker_;
greggman 2012/07/27 19:39:43 style: indenting. 2 spaces not 3
ccameron 2012/07/27 20:14:34 Done.
+ const char* trace_category_;
+ const char* trace_name_;
+ bool has_updated_mem_represented_;
+ size_t last_updated_mem_represented_;
+};
greggman 2012/07/27 19:39:43 DISALLOW_COPY_AND_ASSIGN(MemoryTypeTracker); ?
ccameron 2012/07/27 20:14:34 Done. Added this to MemoryTracker and GpuCommandB
+
+} // namespace gles2
+} // namespace gpu
+
+#endif // GPU_COMMAND_BUFFER_SERVICE_MEMORY_TRACKING_H_

Powered by Google App Engine
This is Rietveld 408576698