1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifndef UTIL_TIME_FORMAT_H
16 #define UTIL_TIME_FORMAT_H
17
18 #include <chrono>
19 #include <string>
20 #include <unordered_map>
21 #include "internal_inc/types.h"
22
23 namespace ffrt {
24 typedef enum {
25 MILLISECOND,
26 MICROSECOND,
27 } TimeUnitT;
28
29 std::string FormatDateString4SystemClock(const std::chrono::system_clock::time_point& timePoint,
30 TimeUnitT timeUnit = MILLISECOND);
31 std::string FormatDateString4SteadyClock(uint64_t steadyClockTimeStamp, TimeUnitT timeUnit = MILLISECOND);
32 std::string FormatDateString4CntCt(uint64_t cntCtTimeStamp, TimeUnitT timeUnit = MILLISECOND);
33 std::string FormatDateToString(uint64_t timeStamp);
34 uint64_t Arm64CntFrq(void);
35 uint64_t Arm64CntCt(void);
36 uint64_t TimeStampCntvct();
37 uint64_t ConvertCntvctToUs(uint64_t cntCt);
38 uint64_t ConvertUsToCntvct(uint64_t time);
39 uint64_t ConvertTscToSteadyClockCount(uint64_t cntCt);
40
TimeStamp(void)41 inline uint64_t TimeStamp(void)
42 {
43 #if defined(__aarch64__)
44 uint64_t tsc = 1;
45 asm volatile("mrs %0, cntvct_el0" : "=r" (tsc));
46 return tsc;
47 #else
48 return static_cast<uint64_t>(std::chrono::time_point_cast<std::chrono::microseconds>(
49 std::chrono::steady_clock::now()).time_since_epoch().count());
50 #endif
51 }
52 }
53 #endif // UTIL_TIME_FORAMT_H
54