/root/doris/be/src/util/trace.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | #pragma once |
18 | | |
19 | | #include <butil/macros.h> |
20 | | |
21 | | #include "gutil/ref_counted.h" |
22 | | #include "gutil/strings/stringpiece.h" |
23 | | #include "gutil/strings/substitute.h" |
24 | | #include "gutil/threading/thread_collision_warner.h" |
25 | | #include "util/scoped_cleanup.h" |
26 | | #include "util/spinlock.h" |
27 | | #include "util/time.h" |
28 | | |
29 | | // If this scope times out, make a simple trace. |
30 | | // It will log the cost time only. |
31 | | // Timeout is chrono duration struct, eg: 5ms, 100 * 1s. |
32 | | #define SCOPED_SIMPLE_TRACE_IF_TIMEOUT(timeout) \ |
33 | 139 | SCOPED_SIMPLE_TRACE_TO_STREAM_IF_TIMEOUT(timeout, LOG(WARNING)) |
34 | | |
35 | | // If this scope times out, then put simple trace to the stream. |
36 | | // Timeout is chrono duration struct, eg: 5ms, 100 * 1s. |
37 | | // For example: |
38 | | // |
39 | | // std::string tag = "[foo]"; |
40 | | // SCOPED_SIMPLE_TRACE_TO_STREAM_IF_TIMEOUT(5s, LOG(INFO) << tag); |
41 | | // |
42 | | #define SCOPED_SIMPLE_TRACE_TO_STREAM_IF_TIMEOUT(timeout, stream) \ |
43 | 139 | using namespace std::chrono_literals; \ |
44 | 139 | auto VARNAME_LINENUM(scoped_simple_trace) = doris::MonotonicMicros(); \ |
45 | 139 | SCOPED_CLEANUP({ \ |
46 | 139 | auto VARNAME_LINENUM(timeout_us) = \ |
47 | 139 | std::chrono::duration_cast<std::chrono::microseconds>(timeout).count(); \ |
48 | 139 | auto VARNAME_LINENUM(cost_us) = \ |
49 | 139 | doris::MonotonicMicros() - VARNAME_LINENUM(scoped_simple_trace); \ |
50 | 139 | if (VARNAME_LINENUM(cost_us) >= VARNAME_LINENUM(timeout_us)) { \ |
51 | 139 | stream << "Simple trace cost(us): " << VARNAME_LINENUM(cost_us); \ |
52 | 139 | } \ |
53 | 139 | }) |