blob: 05d3fbb60f89d726c26de3590cec9a13837f9663 [file] [log] [blame]
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_RUNTIME_STATS_H_
18#define ART_RUNTIME_RUNTIME_STATS_H_
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070019
20#include <stdint.h>
21
22namespace art {
23
24// These must match the values in dalvik.system.VMDebug.
25enum StatKinds {
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,
33
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,
39
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,
47
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,
52
53 KIND_THREAD_GC_INVOCATIONS = KIND_GC_INVOCATIONS << 16,
54
55 // TODO: failedAllocCount, failedAllocSize
56};
57
58/*
59 * Memory allocation profiler state. This is used both globally and
60 * per-thread.
61 */
Ian Rogersdf1ce912012-11-27 17:07:11 -080062struct PACKED(4) RuntimeStats {
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070063 RuntimeStats() {
64 Clear(~0);
65 }
66
67 void Clear(int flags) {
68 if ((flags & KIND_ALLOCATED_OBJECTS) != 0) {
69 allocated_objects = 0;
70 }
71 if ((flags & KIND_ALLOCATED_BYTES) != 0) {
72 allocated_bytes = 0;
73 }
74 if ((flags & KIND_FREED_OBJECTS) != 0) {
75 freed_objects = 0;
76 }
77 if ((flags & KIND_FREED_BYTES) != 0) {
78 freed_bytes = 0;
79 }
80 if ((flags & KIND_GC_INVOCATIONS) != 0) {
81 gc_for_alloc_count = 0;
82 }
83 if ((flags & KIND_CLASS_INIT_COUNT) != 0) {
84 class_init_count = 0;
85 }
86 if ((flags & KIND_CLASS_INIT_TIME) != 0) {
87 class_init_time_ns = 0;
88 }
89 }
90
91 // Number of objects allocated.
92 int allocated_objects;
93 // Cumulative size of all objects allocated.
94 int allocated_bytes;
95
96 // Number of objects freed.
97 int freed_objects;
98 // Cumulative size of all freed objects.
99 int freed_bytes;
100
101 // Number of times an allocation triggered a GC.
102 int gc_for_alloc_count;
103
104 // Number of initialized classes.
105 int class_init_count;
106 // Cumulative time spent in class initialization.
107 uint64_t class_init_time_ns;
108
109 DISALLOW_COPY_AND_ASSIGN(RuntimeStats);
110};
111
112} // namespace art
113
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700114#endif // ART_RUNTIME_RUNTIME_STATS_H_