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 "include/core/SkTypes.h" 14 #include "include/private/SkMacros.h" 15 16 #include <cinttypes> 17 18 class SkString; 19 20 /** \class SkTime 21 Platform-implemented utilities to return time of day, and millisecond counter. 22 */ 23 class SK_API SkTime { 24 public: 25 struct DateTime { 26 int16_t fTimeZoneMinutes; // The number of minutes that GetDateTime() 27 // is ahead of or behind UTC. 28 uint16_t fYear; //!< e.g. 2005 29 uint8_t fMonth; //!< 1..12 30 uint8_t fDayOfWeek; //!< 0..6, 0==Sunday 31 uint8_t fDay; //!< 1..31 32 uint8_t fHour; //!< 0..23 33 uint8_t fMinute; //!< 0..59 34 uint8_t fSecond; //!< 0..59 35 36 void toISO8601(SkString* dst) const; 37 }; 38 static void GetDateTime(DateTime*); 39 GetSecs()40 static double GetSecs() { return GetNSecs() * 1e-9; } GetMSecs()41 static double GetMSecs() { return GetNSecs() * 1e-6; } 42 static double GetNSecs(); 43 }; 44 45 /////////////////////////////////////////////////////////////////////////////// 46 47 class SkAutoTime { 48 public: 49 // The label is not deep-copied, so its address must remain valid for the 50 // lifetime of this object 51 SkAutoTime(const char* label = nullptr) fLabel(label)52 : fLabel(label) 53 , fNow(SkTime::GetMSecs()) {} ~SkAutoTime()54 ~SkAutoTime() { 55 uint64_t dur = static_cast<uint64_t>(SkTime::GetMSecs() - fNow); 56 SkDebugf("%s %" PRIu64 "\n", fLabel ? fLabel : "", dur); 57 } 58 private: 59 const char* fLabel; 60 double fNow; 61 }; 62 63 #endif 64