1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_RUNTIME_STATS_H_ 18 #define ART_RUNTIME_RUNTIME_STATS_H_ 19 20 #include <stdint.h> 21 22 #include "base/macros.h" 23 24 namespace art HIDDEN { 25 26 // These must match the values in dalvik.system.VMDebug. 27 enum StatKinds { 28 KIND_ALLOCATED_OBJECTS = 1<<0, 29 KIND_ALLOCATED_BYTES = 1<<1, 30 KIND_FREED_OBJECTS = 1<<2, 31 KIND_FREED_BYTES = 1<<3, 32 KIND_GC_INVOCATIONS = 1<<4, 33 KIND_CLASS_INIT_COUNT = 1<<5, 34 KIND_CLASS_INIT_TIME = 1<<6, 35 36 // These values exist for backward compatibility. 37 KIND_EXT_ALLOCATED_OBJECTS = 1<<12, 38 KIND_EXT_ALLOCATED_BYTES = 1<<13, 39 KIND_EXT_FREED_OBJECTS = 1<<14, 40 KIND_EXT_FREED_BYTES = 1<<15, 41 42 KIND_GLOBAL_ALLOCATED_OBJECTS = KIND_ALLOCATED_OBJECTS, 43 KIND_GLOBAL_ALLOCATED_BYTES = KIND_ALLOCATED_BYTES, 44 KIND_GLOBAL_FREED_OBJECTS = KIND_FREED_OBJECTS, 45 KIND_GLOBAL_FREED_BYTES = KIND_FREED_BYTES, 46 KIND_GLOBAL_GC_INVOCATIONS = KIND_GC_INVOCATIONS, 47 KIND_GLOBAL_CLASS_INIT_COUNT = KIND_CLASS_INIT_COUNT, 48 KIND_GLOBAL_CLASS_INIT_TIME = KIND_CLASS_INIT_TIME, 49 50 KIND_THREAD_ALLOCATED_OBJECTS = KIND_ALLOCATED_OBJECTS << 16, 51 KIND_THREAD_ALLOCATED_BYTES = KIND_ALLOCATED_BYTES << 16, 52 KIND_THREAD_FREED_OBJECTS = KIND_FREED_OBJECTS << 16, 53 KIND_THREAD_FREED_BYTES = KIND_FREED_BYTES << 16, 54 55 KIND_THREAD_GC_INVOCATIONS = KIND_GC_INVOCATIONS << 16, 56 57 // TODO: failedAllocCount, failedAllocSize 58 }; 59 60 /* 61 * Memory allocation profiler state. This is used both globally and 62 * per-thread. 63 */ 64 struct PACKED(4) RuntimeStats { RuntimeStatsRuntimeStats65 RuntimeStats() { 66 Clear(~0); 67 } 68 ClearRuntimeStats69 void Clear(int flags) { 70 if ((flags & KIND_ALLOCATED_OBJECTS) != 0) { 71 allocated_objects = 0; 72 } 73 if ((flags & KIND_ALLOCATED_BYTES) != 0) { 74 allocated_bytes = 0; 75 } 76 if ((flags & KIND_FREED_OBJECTS) != 0) { 77 freed_objects = 0; 78 } 79 if ((flags & KIND_FREED_BYTES) != 0) { 80 freed_bytes = 0; 81 } 82 if ((flags & KIND_GC_INVOCATIONS) != 0) { 83 gc_for_alloc_count = 0; 84 } 85 if ((flags & KIND_CLASS_INIT_COUNT) != 0) { 86 class_init_count = 0; 87 } 88 if ((flags & KIND_CLASS_INIT_TIME) != 0) { 89 class_init_time_ns = 0; 90 } 91 } 92 93 // Number of objects allocated. 94 uint64_t allocated_objects; 95 // Cumulative size of all objects allocated. 96 uint64_t allocated_bytes; 97 98 // Number of objects freed. 99 uint64_t freed_objects; 100 // Cumulative size of all freed objects. 101 uint64_t freed_bytes; 102 103 // Number of times an allocation triggered a GC. 104 uint64_t gc_for_alloc_count; 105 106 // Number of initialized classes. 107 uint64_t class_init_count; 108 // Cumulative time spent in class initialization. 109 uint64_t class_init_time_ns; 110 111 DISALLOW_COPY_AND_ASSIGN(RuntimeStats); 112 }; 113 114 } // namespace art 115 116 #endif // ART_RUNTIME_RUNTIME_STATS_H_ 117