The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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_CPUGAUGE_H |
| 18 | #define ANDROID_CPUGAUGE_H |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <sys/types.h> |
| 26 | |
| 27 | #include <utils/Timers.h> |
| 28 | |
| 29 | #include <ui/SurfaceComposerClient.h> |
| 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | class CPUGauge : public Thread |
| 34 | { |
| 35 | public: |
| 36 | CPUGauge( const sp<ISurfaceComposer>& composer, |
| 37 | nsecs_t interval=s2ns(1), |
| 38 | int clock=SYSTEM_TIME_THREAD, |
| 39 | int refclock=SYSTEM_TIME_MONOTONIC); |
| 40 | |
| 41 | ~CPUGauge(); |
| 42 | |
| 43 | const sp<SurfaceComposerClient>& session() const; |
| 44 | |
| 45 | void sample(); |
| 46 | |
| 47 | inline float cpuUsage() const { return mCpuUsage; } |
| 48 | inline float idle() const { return mIdleTime; } |
| 49 | |
| 50 | private: |
| 51 | virtual void onFirstRef(); |
| 52 | virtual status_t readyToRun(); |
| 53 | virtual bool threadLoop(); |
| 54 | |
| 55 | Mutex mLock; |
| 56 | |
| 57 | sp<SurfaceComposerClient> mSession; |
| 58 | |
| 59 | const nsecs_t mInterval; |
| 60 | const int mClock; |
| 61 | const int mRefClock; |
| 62 | |
| 63 | nsecs_t mReferenceTime; |
| 64 | nsecs_t mReferenceWorkingTime; |
| 65 | float mCpuUsage; |
| 66 | nsecs_t mRefIdleTime; |
| 67 | float mIdleTime; |
| 68 | FILE* mFd; |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | }; // namespace android |
| 73 | |
| 74 | #endif // ANDROID_CPUGAUGE_H |