blob: f2e32b21a5dd9192630ff69ac539ca7c61972424 [file] [log] [blame]
The Android Open Source Projectd245d1d2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2007 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
17#ifndef ANDROID_TIMER_PROBE_H
18#define ANDROID_TIMER_PROBE_H
19
20#if 0 && defined(HAVE_POSIX_CLOCKS)
21#define ENABLE_TIMER_PROBE 1
22#else
23#define ENABLE_TIMER_PROBE 0
24#endif
25
26#if ENABLE_TIMER_PROBE
27
28#include <time.h>
29#include <sys/time.h>
30#include <utils/Vector.h>
31
32#define TIMER_PROBE(tag) \
33 static int _timer_slot_; \
34 android::TimerProbe probe(tag, &_timer_slot_)
35#define TIMER_PROBE_END() probe.end()
36#else
37#define TIMER_PROBE(tag)
38#define TIMER_PROBE_END()
39#endif
40
41#if ENABLE_TIMER_PROBE
42namespace android {
43
44class TimerProbe {
45public:
46 TimerProbe(const char tag[], int* slot);
47 void end();
48 ~TimerProbe();
49private:
50 struct Bucket {
51 int mStart, mReal, mProcess, mThread, mCount;
52 const char* mTag;
53 int* mSlotPtr;
54 int mIndent;
55 };
56 static Vector<Bucket> gBuckets;
57 static TimerProbe* gExecuteChain;
58 static int gIndent;
59 static timespec gRealBase;
60 TimerProbe* mNext;
61 static uint32_t ElapsedTime(const timespec& start, const timespec& end);
62 void print(const timespec& r, const timespec& p, const timespec& t) const;
63 timespec mRealStart, mPStart, mTStart;
64 const char* mTag;
65 int mIndent;
66 int mBucket;
67};
68
69}; // namespace android
70
71#endif
72#endif