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

Side by Side 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: Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/dart_api_state.cc » ('j') | runtime/vm/zone.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 RUNTIME_VM_DART_API_STATE_H_ 5 #ifndef RUNTIME_VM_DART_API_STATE_H_
6 #define RUNTIME_VM_DART_API_STATE_H_ 6 #define RUNTIME_VM_DART_API_STATE_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 ~ApiNativeScope() { 679 ~ApiNativeScope() {
680 ASSERT(Current() == this); 680 ASSERT(Current() == this);
681 OSThread::SetThreadLocal(Api::api_native_key_, 0); 681 OSThread::SetThreadLocal(Api::api_native_key_, 0);
682 } 682 }
683 683
684 static inline ApiNativeScope* Current() { 684 static inline ApiNativeScope* Current() {
685 return reinterpret_cast<ApiNativeScope*>( 685 return reinterpret_cast<ApiNativeScope*>(
686 OSThread::GetThreadLocal(Api::api_native_key_)); 686 OSThread::GetThreadLocal(Api::api_native_key_));
687 } 687 }
688 688
689 static intptr_t current_memory_usage() { return current_memory_usage_; }
690
691 static void IncrementNativeScopeMemoryUsage(intptr_t size) {
692 AtomicOperations::IncrementBy(&current_memory_usage_, size);
693 }
694
695 static void DecrementNativeScopeMemoryUsage(intptr_t size) {
696 AtomicOperations::DecrementBy(&current_memory_usage_, size);
697 }
698
689 Zone* zone() { 699 Zone* zone() {
690 Zone* result = zone_.GetZone(); 700 Zone* result = zone_.GetZone();
691 ASSERT(result->handles()->CountScopedHandles() == 0); 701 ASSERT(result->handles()->CountScopedHandles() == 0);
692 ASSERT(result->handles()->CountZoneHandles() == 0); 702 ASSERT(result->handles()->CountZoneHandles() == 0);
693 return result; 703 return result;
694 } 704 }
695 705
696 private: 706 private:
707 // The current total memory usage within ApiNativeScopes.
708 static intptr_t current_memory_usage_;
709
697 ApiZone zone_; 710 ApiZone zone_;
698 }; 711 };
699 712
700 713
701 // Api growable arrays use a zone for allocation. The constructor 714 // Api growable arrays use a zone for allocation. The constructor
702 // picks the zone from the current isolate if in an isolate 715 // picks the zone from the current isolate if in an isolate
703 // environment. When outside an isolate environment it picks the zone 716 // environment. When outside an isolate environment it picks the zone
704 // from the current native scope. 717 // from the current native scope.
705 template <typename T> 718 template <typename T>
706 class ApiGrowableArray : public BaseGrowableArray<T, ValueObject> { 719 class ApiGrowableArray : public BaseGrowableArray<T, ValueObject> {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 ref->set_callback(callback); 854 ref->set_callback(callback);
842 ref->set_is_queued_for_finalization(false); 855 ref->set_is_queued_for_finalization(false);
843 // This may trigger GC, so it must be called last. 856 // This may trigger GC, so it must be called last.
844 ref->SetExternalSize(external_size, isolate); 857 ref->SetExternalSize(external_size, isolate);
845 return ref; 858 return ref;
846 } 859 }
847 860
848 } // namespace dart 861 } // namespace dart
849 862
850 #endif // RUNTIME_VM_DART_API_STATE_H_ 863 #endif // RUNTIME_VM_DART_API_STATE_H_
OLDNEW
« 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