1/* 2 * Copyright (C) 2011 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_FILTERFW_FILTERPACKS_BASE_TIME_UTIL_H 18#define ANDROID_FILTERFW_FILTERPACKS_BASE_TIME_UTIL_H 19 20#include <string> 21#include <utils/RefBase.h> 22 23#define LOG_MFF_RUNNING_TIMES 0 24 25namespace android { 26namespace filterfw { 27 28uint64_t getTimeUs(); 29 30class NamedStopWatch : public RefBase { 31 public: 32 static const uint64_t kDefaultLoggingPeriodInFrames; 33 34 explicit NamedStopWatch(const std::string& name); 35 void Start(); 36 void Stop(); 37 38 void SetName(const std::string& name) { mName = name; } 39 void SetLoggingPeriodInFrames(uint64_t numFrames) { 40 mLoggingPeriodInFrames = numFrames; 41 } 42 43 const std::string& Name() const { return mName; } 44 uint64_t NumCalls() const { return mNumCalls; } 45 uint64_t TotalUSec() const { return mTotalUSec; } 46 47 private: 48 std::string mName; 49 uint64_t mLoggingPeriodInFrames; 50 uint64_t mStartUSec; 51 uint64_t mNumCalls; 52 uint64_t mTotalUSec; 53}; 54 55class ScopedTimer { 56 public: 57 explicit ScopedTimer(const std::string& stop_watch_name); 58 explicit ScopedTimer(NamedStopWatch* watch) 59 : mWatch(watch) { mWatch->Start(); } 60 ~ScopedTimer() { mWatch->Stop(); } 61 62 private: 63 NamedStopWatch* mWatch; 64}; 65 66} // namespace filterfw 67} // namespace android 68 69#endif // ANDROID_FILTERFW_FILTERPACKS_BASE_TIME_UTIL_H 70