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 15class SkString; 16 17/** \class SkTime 18 Platform-implemented utilities to return time of day, and millisecond counter. 19*/ 20class SkTime { 21public: 22 struct DateTime { 23 int16_t fTimeZoneMinutes; // The number of minutes that GetDateTime() 24 // is ahead of or behind UTC. 25 uint16_t fYear; //!< e.g. 2005 26 uint8_t fMonth; //!< 1..12 27 uint8_t fDayOfWeek; //!< 0..6, 0==Sunday 28 uint8_t fDay; //!< 1..31 29 uint8_t fHour; //!< 0..23 30 uint8_t fMinute; //!< 0..59 31 uint8_t fSecond; //!< 0..59 32 33 void toISO8601(SkString* dst) const; 34 }; 35 static void GetDateTime(DateTime*); 36 37 static SkMSec GetMSecs(); 38}; 39 40#if defined(SK_DEBUG) && defined(SK_BUILD_FOR_WIN32) 41 extern SkMSec gForceTickCount; 42#endif 43 44#define SK_TIME_FACTOR 1 45 46/////////////////////////////////////////////////////////////////////////////// 47 48class SkAutoTime { 49public: 50 // The label is not deep-copied, so its address must remain valid for the 51 // lifetime of this object 52 SkAutoTime(const char* label = NULL, SkMSec minToDump = 0) : fLabel(label) 53 { 54 fNow = SkTime::GetMSecs(); 55 fMinToDump = minToDump; 56 } 57 ~SkAutoTime() 58 { 59 SkMSec dur = SkTime::GetMSecs() - fNow; 60 if (dur >= fMinToDump) { 61 SkDebugf("%s %d\n", fLabel ? fLabel : "", dur); 62 } 63 } 64private: 65 const char* fLabel; 66 SkMSec fNow; 67 SkMSec fMinToDump; 68}; 69#define SkAutoTime(...) SK_REQUIRE_LOCAL_VAR(SkAutoTime) 70 71#endif 72