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
16 #include "util.h"
17
18 #include <cerrno>
19 #include <chrono>
20
21 #include <sys/time.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24
25 #include "window_manager_hilog.h"
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "Util"};
30 }
GetSysClockTime()31 int64_t GetSysClockTime()
32 {
33 struct timespec ts = { 0, 0 };
34 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
35 WLOGFE("clock_gettime failed:%{public}d", errno);
36 return 0;
37 }
38 return (ts.tv_sec * 1000 * 1000) + (ts.tv_nsec / 1000); // 1000 is for convert time units.
39 }
40
GetMillisTime()41 int64_t GetMillisTime()
42 {
43 auto timeNow = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now());
44 auto tmp = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow.time_since_epoch());
45 return tmp.count();
46 }
47
48 } // namespace Rosen
49 } // namespace OHOS