/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/substitute.h" | 
| 23 |  | #include "gutil/threading/thread_collision_warner.h" | 
| 24 |  | #include "util/scoped_cleanup.h" | 
| 25 |  | #include "util/time.h" | 
| 26 |  |  | 
| 27 |  | // If this scope times out, make a simple trace. | 
| 28 |  | // It will log the cost time only. | 
| 29 |  | // Timeout is chrono duration struct, eg: 5ms, 100 * 1s. | 
| 30 |  | #define SCOPED_SIMPLE_TRACE_IF_TIMEOUT(timeout) \ | 
| 31 | 54.3k |     SCOPED_SIMPLE_TRACE_TO_STREAM_IF_TIMEOUT(timeout, LOG(WARNING)) | 
| 32 |  |  | 
| 33 |  | // If this scope times out, then put simple trace to the stream. | 
| 34 |  | // Timeout is chrono duration struct, eg: 5ms, 100 * 1s. | 
| 35 |  | // For example: | 
| 36 |  | // | 
| 37 |  | //    std::string tag = "[foo]"; | 
| 38 |  | //    SCOPED_SIMPLE_TRACE_TO_STREAM_IF_TIMEOUT(5s, LOG(INFO) << tag); | 
| 39 |  | // | 
| 40 |  | #define SCOPED_SIMPLE_TRACE_TO_STREAM_IF_TIMEOUT(timeout, stream)                       \ | 
| 41 | 54.3k |     using namespace std::chrono_literals;                                               \ | 
| 42 | 54.3k |     auto VARNAME_LINENUM(scoped_simple_trace) = doris::MonotonicMicros();               \ | 
| 43 | 54.3k |     SCOPED_CLEANUP({                                                                    \ | 
| 44 | 54.3k |         auto VARNAME_LINENUM(timeout_us) =                                              \ | 
| 45 | 54.3k |                 std::chrono::duration_cast<std::chrono::microseconds>(timeout).count(); \ | 
| 46 | 54.3k |         auto VARNAME_LINENUM(cost_us) =                                                 \ | 
| 47 | 54.3k |                 doris::MonotonicMicros() - VARNAME_LINENUM(scoped_simple_trace);        \ | 
| 48 | 54.3k |         if (VARNAME_LINENUM(cost_us) >= VARNAME_LINENUM(timeout_us)) {                  \ | 
| 49 | 54.3k |             stream << "Simple trace cost(us): " << VARNAME_LINENUM(cost_us);            \ | 
| 50 | 54.3k |         }                                                                               \ | 
| 51 | 54.3k |     }) |