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 */
27 struct Thread; // extern
31 bool dvmProfilingStartup(void);
32 void dvmProfilingShutdown(void);
35 * Method trace state. This is currently global. In theory we could make
36 * most of this per-thread.
38 struct MethodTraceState {
40 pthread_mutex_t startStopLock;
41 pthread_cond_t threadExitCond;
49 volatile int curOffset;
55 * Memory allocation profiler state. This is used both globally and
58 * If you add a field here, zero it out in dvmStartAllocCounting().
60 struct AllocProfState {
61 bool enabled; // is allocation tracking enabled?
63 int allocCount; // #of objects allocated
64 int allocSize; // cumulative size of objects
66 int failedAllocCount; // #of times an allocation failed
67 int failedAllocSize; // cumulative size of failed allocations
69 int freeCount; // #of objects freed
70 int freeSize; // cumulative size of freed objects
72 int gcCount; // #of times an allocation triggered a GC
74 int classInitCount; // #of initialized classes
75 u8 classInitTime; // cumulative time spent in class init (nsec)
80 * Start/stop method tracing.
82 void dvmMethodTraceStart(const char* traceFileName, int traceFd, int bufferSize,
83 int flags, bool directToDdms);
84 bool dvmIsMethodTraceActive(void);
85 void dvmMethodTraceStop(void);
88 * Start/stop emulator tracing.
90 void dvmEmulatorTraceStart(void);
91 void dvmEmulatorTraceStop(void);
94 * Start/stop Dalvik instruction counting.
96 void dvmStartInstructionCounting();
97 void dvmStopInstructionCounting();
100 * Bit flags for dvmMethodTraceStart "flags" argument. These must match
101 * the values in android.os.Debug.
104 TRACE_ALLOC_COUNTS = 0x01,
108 * Call these when a method enters or exits.
110 #define TRACE_METHOD_ENTER(_self, _method) \
112 if (_self->interpBreak.ctl.subMode & kSubModeMethodTrace) \
113 dvmMethodTraceAdd(_self, _method, METHOD_TRACE_ENTER); \
114 if (_self->interpBreak.ctl.subMode & kSubModeEmulatorTrace) \
115 dvmEmitEmulatorTrace(_method, METHOD_TRACE_ENTER); \
117 #define TRACE_METHOD_EXIT(_self, _method) \
119 if (_self->interpBreak.ctl.subMode & kSubModeMethodTrace) \
120 dvmMethodTraceAdd(_self, _method, METHOD_TRACE_EXIT); \
121 if (_self->interpBreak.ctl.subMode & kSubModeEmulatorTrace) \
122 dvmEmitEmulatorTrace(_method, METHOD_TRACE_EXIT); \
124 #define TRACE_METHOD_UNROLL(_self, _method) \
126 if (_self->interpBreak.ctl.subMode & kSubModeMethodTrace) \
127 dvmMethodTraceAdd(_self, _method, METHOD_TRACE_UNROLL); \
128 if (_self->interpBreak.ctl.subMode & kSubModeEmulatorTrace) \
129 dvmEmitEmulatorTrace(_method, METHOD_TRACE_UNROLL); \
132 void dvmMethodTraceAdd(struct Thread* self, const Method* method, int action);
133 void dvmEmitEmulatorTrace(const Method* method, int action);
135 void dvmMethodTraceGCBegin(void);
136 void dvmMethodTraceGCEnd(void);
137 void dvmMethodTraceClassPrepBegin(void);
138 void dvmMethodTraceClassPrepEnd(void);
140 extern "C" void dvmFastMethodTraceEnter(const Method* method, struct Thread* self);
141 extern "C" void dvmFastMethodTraceExit(struct Thread* self);
142 extern "C" void dvmFastNativeMethodTraceExit(const Method* method, struct Thread* self);
145 * Start/stop alloc counting.
147 void dvmStartAllocCounting(void);
148 void dvmStopAllocCounting(void);
154 * Enumeration for the two "action" bits.
157 METHOD_TRACE_ENTER = 0x00, // method entry
158 METHOD_TRACE_EXIT = 0x01, // method exit
159 METHOD_TRACE_UNROLL = 0x02, // method exited by exception unrolling
160 // 0x03 currently unused
163 #define TOKEN_CHAR '*'
164 #define TRACE_VERSION 1
167 * Common definitions, shared with the dump tool.
169 #define METHOD_ACTION_MASK 0x03 /* two bits */
170 #define METHOD_ID(_method) ((_method) & (~METHOD_ACTION_MASK))
171 #define METHOD_ACTION(_method) (((unsigned int)(_method)) & METHOD_ACTION_MASK)
172 #define METHOD_COMBINE(_method, _action) ((_method) | (_action))
174 #endif /*_DALVIK_PROFILE*/