1 /* 2 * Copyright (C) 2021 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 #ifndef MEDIA_TIME_MONITOR_H 17 #define MEDIA_TIME_MONITOR_H 18 19 #include <string> 20 #include <mutex> 21 #include <map> 22 #include <sys/time.h> 23 24 namespace OHOS { 25 namespace Media { 26 class __attribute__((visibility("default"))) TimeMonitor { 27 public: 28 explicit TimeMonitor(const std::string &objectName); 29 ~TimeMonitor(); 30 void StartTime(); 31 void FinishTime(); 32 33 private: 34 enum TimeValType { 35 TIME_VAL_MS = 1000, /* sec to ms */ 36 TIME_VAL_US = 1000000, /* sec to us */ 37 TIME_VAL_NS = 1000000000, /* sec to ns */ 38 }; 39 int64_t Timeval2Sec(const timeval &tv, TimeValType valType) const; 40 std::string objectName_ = "Unknown"; 41 struct timeval startTime_ = {}; 42 struct timeval finishTime_ = {}; 43 bool isStart_ = false; 44 }; 45 } // namespace Media 46 } // namespace OHOS 47 #endif // MEDIA_TIME_MONITOR_H 48