SkTime.h revision 74b43a9d4c5c602704f0af6a5706faacca45597a
1 2/* 3 * Copyright 2006 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10#ifndef SkTime_DEFINED 11#define SkTime_DEFINED 12 13#include "SkTypes.h" 14 15/** \class SkTime 16 Platform-implemented utilities to return time of day, and millisecond counter. 17*/ 18class SkTime { 19public: 20 struct DateTime { 21 uint16_t fYear; //!< e.g. 2005 22 uint8_t fMonth; //!< 1..12 23 uint8_t fDayOfWeek; //!< 0..6, 0==Sunday 24 uint8_t fDay; //!< 1..31 25 uint8_t fHour; //!< 0..23 26 uint8_t fMinute; //!< 0..59 27 uint8_t fSecond; //!< 0..59 28 }; 29 static void GetDateTime(DateTime*); 30 31 static SkMSec GetMSecs() { return GetNSecs() / 1000000; } 32 33 static SkNSec GetNSecs(); 34}; 35 36#if defined(SK_DEBUG) && defined(SK_BUILD_FOR_WIN32) 37 extern SkMSec gForceTickCount; 38#endif 39 40#define SK_TIME_FACTOR 1 41 42/////////////////////////////////////////////////////////////////////////////// 43 44class SkAutoTime { 45public: 46 // The label is not deep-copied, so its address must remain valid for the 47 // lifetime of this object 48 SkAutoTime(const char* label = NULL, SkMSec minToDump = 0) : fLabel(label) 49 { 50 fNow = SkTime::GetMSecs(); 51 fMinToDump = minToDump; 52 } 53 ~SkAutoTime() 54 { 55 SkMSec dur = SkTime::GetMSecs() - fNow; 56 if (dur >= fMinToDump) { 57 SkDebugf("%s %d\n", fLabel ? fLabel : "", dur); 58 } 59 } 60private: 61 const char* fLabel; 62 SkMSec fNow; 63 SkMSec fMinToDump; 64}; 65#define SkAutoTime(...) SK_REQUIRE_LOCAL_VAR(SkAutoTime) 66 67#endif 68