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

Unified Diff: runtime/vm/dart_api_state.h

Issue 2650583014: Added tracking of memory usage within ApiNativeScopes. Usage to be displayed within Observatory. (Closed)
Patch Set: Added unit test + fixed typo Created 3 years, 11 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 | « no previous file | runtime/vm/dart_api_state.cc » ('j') | runtime/vm/zone.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_state.h
diff --git a/runtime/vm/dart_api_state.h b/runtime/vm/dart_api_state.h
index 3ca4f728b0da255ed68ab03ba171bb7cbb50a1b6..7946ef8ea5bfcc50162865e52d0b0efcb7e5ee69 100644
--- a/runtime/vm/dart_api_state.h
+++ b/runtime/vm/dart_api_state.h
@@ -674,11 +674,18 @@ class ApiNativeScope {
ASSERT(Current() == NULL);
OSThread::SetThreadLocal(Api::api_native_key_,
reinterpret_cast<uword>(this));
+ // We manually increment the memory usage counter since there is memory
+ // initially allocated within the zone on creation.
+ IncrementNativeScopeMemoryUsage(zone_.GetZone()->CapacityInBytes());
}
~ApiNativeScope() {
ASSERT(Current() == this);
OSThread::SetThreadLocal(Api::api_native_key_, 0);
+ // We must also manually decrement the memory usage counter since the native
+ // is still holding it's initial memory and ~Zone() won't be able to
+ // determine which memory usage counter to decrement.
+ DecrementNativeScopeMemoryUsage(zone_.GetZone()->CapacityInBytes());
}
static inline ApiNativeScope* Current() {
@@ -686,6 +693,16 @@ class ApiNativeScope {
OSThread::GetThreadLocal(Api::api_native_key_));
}
+ static intptr_t current_memory_usage() { return current_memory_usage_; }
+
+ static void IncrementNativeScopeMemoryUsage(intptr_t size) {
+ AtomicOperations::IncrementBy(&current_memory_usage_, size);
+ }
+
+ static void DecrementNativeScopeMemoryUsage(intptr_t size) {
+ AtomicOperations::DecrementBy(&current_memory_usage_, size);
+ }
+
Zone* zone() {
Zone* result = zone_.GetZone();
ASSERT(result->handles()->CountScopedHandles() == 0);
@@ -694,6 +711,9 @@ class ApiNativeScope {
}
private:
+ // The current total memory usage within ApiNativeScopes.
+ static intptr_t current_memory_usage_;
+
ApiZone zone_;
};
« no previous file with comments | « no previous file | runtime/vm/dart_api_state.cc » ('j') | runtime/vm/zone.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698