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.
18 * Android's method call profiling goodies.
20 #ifndef _DALVIK_PROFILE
21 #define _DALVIK_PROFILE
23 #ifndef NOT_VM /* for utilities that sneakily include this file */
31 struct Thread; // extern
35 bool dvmProfilingStartup(void);
36 void dvmProfilingShutdown(void);
39 * Method trace state. This is currently global. In theory we could make
40 * most of this per-thread.
42 typedef struct MethodTraceState {
44 pthread_mutex_t startStopLock;
45 pthread_cond_t threadExitCond;
53 volatile int curOffset;
59 * Memory allocation profiler state. This is used both globally and
62 * If you add a field here, zero it out in dvmStartAllocCounting().
64 typedef struct AllocProfState {
65 bool enabled; // is allocation tracking enabled?
67 int allocCount; // #of objects allocated
68 int allocSize; // cumulative size of objects
70 int failedAllocCount; // #of times an allocation failed
71 int failedAllocSize; // cumulative size of failed allocations
73 int freeCount; // #of objects freed
74 int freeSize; // cumulative size of freed objects
76 int gcCount; // #of times an allocation triggered a GC
78 int classInitCount; // #of initialized classes
79 u8 classInitTime; // cumulative time spent in class init (nsec)
84 * Start/stop method tracing.
86 void dvmMethodTraceStart(const char* traceFileName, int traceFd, int bufferSize,
87 int flags, bool directToDdms);
88 bool dvmIsMethodTraceActive(void);
89 void dvmMethodTraceStop(void);
92 * Start/stop emulator tracing.
94 void dvmEmulatorTraceStart(void);
95 void dvmEmulatorTraceStop(void);
98 * Start/stop Dalvik instruction counting.
100 void dvmStartInstructionCounting();
101 void dvmStopInstructionCounting();
104 * Bit flags for dvmMethodTraceStart "flags" argument. These must match
105 * the values in android.os.Debug.
108 TRACE_ALLOC_COUNTS = 0x01,
112 * Call these when a method enters or exits.
114 #define TRACE_METHOD_ENTER(_self, _method) \
116 if (_self->interpBreak.ctl.subMode & kSubModeMethodTrace) \
117 dvmMethodTraceAdd(_self, _method, METHOD_TRACE_ENTER); \
118 if (_self->interpBreak.ctl.subMode & kSubModeEmulatorTrace) \
119 dvmEmitEmulatorTrace(_method, METHOD_TRACE_ENTER); \
121 #define TRACE_METHOD_EXIT(_self, _method) \
123 if (_self->interpBreak.ctl.subMode & kSubModeMethodTrace) \
124 dvmMethodTraceAdd(_self, _method, METHOD_TRACE_EXIT); \
125 if (_self->interpBreak.ctl.subMode & kSubModeEmulatorTrace) \
126 dvmEmitEmulatorTrace(_method, METHOD_TRACE_EXIT); \
128 #define TRACE_METHOD_UNROLL(_self, _method) \
130 if (_self->interpBreak.ctl.subMode & kSubModeMethodTrace) \
131 dvmMethodTraceAdd(_self, _method, METHOD_TRACE_UNROLL); \
132 if (_self->interpBreak.ctl.subMode & kSubModeEmulatorTrace) \
133 dvmEmitEmulatorTrace(_method, METHOD_TRACE_UNROLL); \
136 void dvmMethodTraceAdd(struct Thread* self, const Method* method, int action);
137 void dvmEmitEmulatorTrace(const Method* method, int action);
139 void dvmMethodTraceGCBegin(void);
140 void dvmMethodTraceGCEnd(void);
141 void dvmMethodTraceClassPrepBegin(void);
142 void dvmMethodTraceClassPrepEnd(void);
144 void dvmFastMethodTraceEnter(const Method* method, struct Thread* self);
145 void dvmFastMethodTraceExit(struct Thread* self);
146 void dvmFastNativeMethodTraceExit(const Method* method, struct Thread* self);
149 * Start/stop alloc counting.
151 void dvmStartAllocCounting(void);
152 void dvmStopAllocCounting(void);
158 * Enumeration for the two "action" bits.
161 METHOD_TRACE_ENTER = 0x00, // method entry
162 METHOD_TRACE_EXIT = 0x01, // method exit
163 METHOD_TRACE_UNROLL = 0x02, // method exited by exception unrolling
164 // 0x03 currently unused
167 #define TOKEN_CHAR '*'
168 #define TRACE_VERSION 1
171 * Common definitions, shared with the dump tool.
173 #define METHOD_ACTION_MASK 0x03 /* two bits */
174 #define METHOD_ID(_method) ((_method) & (~METHOD_ACTION_MASK))
175 #define METHOD_ACTION(_method) (((unsigned int)(_method)) & METHOD_ACTION_MASK)
176 #define METHOD_COMBINE(_method, _action) ((_method) | (_action))
182 #endif /*_DALVIK_PROFILE*/