Apollo 10.0
自动驾驶开放平台
perf_util.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
17
18#include "cyber/common/log.h"
19
20namespace {
21std::string func_name_simplified(const std::string& str) {
22 constexpr char kLeftBracket = '(';
23 constexpr char kSpace = ' ';
24
25 auto end = str.find(kLeftBracket);
26 auto begin = str.rfind(kSpace, end);
27
28 if (begin == std::string::npos) {
29 return str.substr(0, end);
30 } else if (end == std::string::npos) {
31 return str.substr(begin + 1);
32 } else {
33 return str.substr(begin + 1, end - begin - 1);
34 }
35}
36} // namespace
37
39
40namespace apollo {
41namespace common {
42namespace util {
43
44std::string function_signature(const std::string& func_name,
45 const std::string& indicator) {
46 auto simplified_name = func_name_simplified(func_name);
47 if (indicator.empty()) {
48 return simplified_name;
49 }
50 return absl::StrCat(indicator, "_", simplified_name);
51}
52
53void Timer::Start() { start_time_ = Time::Now(); }
54
55int64_t Timer::End(const std::string& msg) {
56 end_time_ = Time::Now();
57 int64_t elapsed_time = (end_time_ - start_time_).ToNanosecond() / 1e6;
58 ADEBUG << "TIMER " << msg << " elapsed_time: " << elapsed_time << " ms";
59
60 // start new timer.
61 start_time_ = end_time_;
62 return elapsed_time;
63}
64
65} // namespace util
66} // namespace common
67} // namespace apollo
int64_t End(const std::string &msg)
Definition perf_util.cc:55
Cyber has builtin time type Time.
Definition time.h:31
static Time Now()
get the current time.
Definition time.cc:57
#define ADEBUG
Definition log.h:41
std::string function_signature(const std::string &func_name, const std::string &indicator)
Definition perf_util.cc:44
class register implement
Definition arena_queue.h:37