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 COMMUNICATIONNETSTACK_NETSTACK_TIMIMG_H
16 #define COMMUNICATIONNETSTACK_NETSTACK_TIMIMG_H
17 
18 #include <map>
19 #include <ctime>
20 
21 namespace OHOS::NetStack::Timing {
22 
23 class Timer {
24 public:
25     const char* timerName_ = nullptr;
26     Timer();
27     void Start(time_t time);
28     void Start();
29     void Stop();
30     double Elapsed() const;
31 
32 private:
33     time_t startTime_ = 0;
34     time_t endTime_ = 0;
35 };
36 
37 class TimerMap {
38 public:
39     Timer& RecieveTimer(const char *const type);
40 
41 private:
42     std::map<const char *const, Timer> timerMap_;
43 };
44 
45 class TimeUtils {
46 public:
47     static time_t GetNowTimeMicroseconds();
48 
49     static double Microseconds2Milliseconds(time_t microseconds);
50 };
51 } // namespace OHOS::NetStack::Timing
52 #endif /* COMMUNICATIONNETSTACK_NETSTACK_TIMING_H */