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