blob: 6ed7fd50b54c5be537cb7f7a0c9e32348ae179d8 [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.
Ian Rogersdd7624d2014-03-14 17:43:00 -070092 uint64_t allocated_objects;
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070093 // Cumulative size of all objects allocated.
Ian Rogersdd7624d2014-03-14 17:43:00 -070094 uint64_t allocated_bytes;
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070095
96 // Number of objects freed.
Ian Rogersdd7624d2014-03-14 17:43:00 -070097 uint64_t freed_objects;
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070098 // Cumulative size of all freed objects.
Ian Rogersdd7624d2014-03-14 17:43:00 -070099 uint64_t freed_bytes;
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700100
101 // Number of times an allocation triggered a GC.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700102 uint64_t gc_for_alloc_count;
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700103
104 // Number of initialized classes.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700105 uint64_t class_init_count;
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700106 // 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_