2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ART_RUNTIME_RUNTIME_STATS_H_
18 #define ART_RUNTIME_RUNTIME_STATS_H_
24 // These must match the values in dalvik.system.VMDebug.
26 KIND_ALLOCATED_OBJECTS = 1<<0,
27 KIND_ALLOCATED_BYTES = 1<<1,
28 KIND_FREED_OBJECTS = 1<<2,
29 KIND_FREED_BYTES = 1<<3,
30 KIND_GC_INVOCATIONS = 1<<4,
31 KIND_CLASS_INIT_COUNT = 1<<5,
32 KIND_CLASS_INIT_TIME = 1<<6,
34 // These values exist for backward compatibility.
35 KIND_EXT_ALLOCATED_OBJECTS = 1<<12,
36 KIND_EXT_ALLOCATED_BYTES = 1<<13,
37 KIND_EXT_FREED_OBJECTS = 1<<14,
38 KIND_EXT_FREED_BYTES = 1<<15,
40 KIND_GLOBAL_ALLOCATED_OBJECTS = KIND_ALLOCATED_OBJECTS,
41 KIND_GLOBAL_ALLOCATED_BYTES = KIND_ALLOCATED_BYTES,
42 KIND_GLOBAL_FREED_OBJECTS = KIND_FREED_OBJECTS,
43 KIND_GLOBAL_FREED_BYTES = KIND_FREED_BYTES,
44 KIND_GLOBAL_GC_INVOCATIONS = KIND_GC_INVOCATIONS,
45 KIND_GLOBAL_CLASS_INIT_COUNT = KIND_CLASS_INIT_COUNT,
46 KIND_GLOBAL_CLASS_INIT_TIME = KIND_CLASS_INIT_TIME,
48 KIND_THREAD_ALLOCATED_OBJECTS = KIND_ALLOCATED_OBJECTS << 16,
49 KIND_THREAD_ALLOCATED_BYTES = KIND_ALLOCATED_BYTES << 16,
50 KIND_THREAD_FREED_OBJECTS = KIND_FREED_OBJECTS << 16,
51 KIND_THREAD_FREED_BYTES = KIND_FREED_BYTES << 16,
53 KIND_THREAD_GC_INVOCATIONS = KIND_GC_INVOCATIONS << 16,
55 // TODO: failedAllocCount, failedAllocSize
59 * Memory allocation profiler state. This is used both globally and
62 struct PACKED(4) RuntimeStats {
67 void Clear(int flags) {
68 if ((flags & KIND_ALLOCATED_OBJECTS) != 0) {
69 allocated_objects = 0;
71 if ((flags & KIND_ALLOCATED_BYTES) != 0) {
74 if ((flags & KIND_FREED_OBJECTS) != 0) {
77 if ((flags & KIND_FREED_BYTES) != 0) {
80 if ((flags & KIND_GC_INVOCATIONS) != 0) {
81 gc_for_alloc_count = 0;
83 if ((flags & KIND_CLASS_INIT_COUNT) != 0) {
86 if ((flags & KIND_CLASS_INIT_TIME) != 0) {
87 class_init_time_ns = 0;
91 // Number of objects allocated.
92 uint64_t allocated_objects;
93 // Cumulative size of all objects allocated.
94 uint64_t allocated_bytes;
96 // Number of objects freed.
97 uint64_t freed_objects;
98 // Cumulative size of all freed objects.
101 // Number of times an allocation triggered a GC.
102 uint64_t gc_for_alloc_count;
104 // Number of initialized classes.
105 uint64_t class_init_count;
106 // Cumulative time spent in class initialization.
107 uint64_t class_init_time_ns;
109 DISALLOW_COPY_AND_ASSIGN(RuntimeStats);
114 #endif // ART_RUNTIME_RUNTIME_STATS_H_