/root/doris/be/src/pipeline/pipeline_tracing.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
18 | | #pragma once |
19 | | |
20 | | #include <concurrentqueue.h> |
21 | | #include <fmt/core.h> |
22 | | #include <gen_cpp/Types_types.h> |
23 | | #include <parallel_hashmap/phmap.h> |
24 | | |
25 | | #include <cstdint> |
26 | | #include <filesystem> |
27 | | |
28 | | #include "common/config.h" |
29 | | #include "util/hash_util.hpp" // IWYU pragma: keep |
30 | | #include "util/thrift_util.h" |
31 | | #include "util/time.h" |
32 | | |
33 | | namespace doris::pipeline { |
34 | | |
35 | | struct ScheduleRecord { |
36 | | TUniqueId query_id; |
37 | | std::string task_id; |
38 | | uint32_t core_id; |
39 | | uint64_t thread_id; |
40 | | uint64_t start_time; |
41 | | uint64_t end_time; |
42 | | std::string state_name; |
43 | | |
44 | 0 | bool operator<(const ScheduleRecord& rhs) const { return start_time < rhs.start_time; } |
45 | 0 | std::string to_string(uint64_t append_value) const { |
46 | 0 | return fmt::format("{}|{}|{}|{}|{}|{}|{}|{}\n", doris::to_string(query_id), task_id, |
47 | 0 | core_id, thread_id, start_time, end_time, state_name, append_value); |
48 | 0 | } |
49 | | }; |
50 | | |
51 | | // all tracing datas of ONE specific query |
52 | | using OneQueryTraces = moodycamel::ConcurrentQueue<ScheduleRecord>; |
53 | | |
54 | | // belongs to exec_env, for all query, if enable |
55 | | // curl http://{host}:{web_server_port}/api/running_pipeline_tasks |
56 | | class PipelineTracerContext { |
57 | | public: |
58 | | enum class RecordType { |
59 | | None, // disable |
60 | | PerQuery, // record per query. one query one file. |
61 | | Periodic // record per times. one timeslice one file. |
62 | | }; |
63 | | void record(ScheduleRecord record); // record one schedule record |
64 | | void end_query(TUniqueId query_id, |
65 | | uint64_t workload_group); // tell context this query is end. may leads to dump. |
66 | | Status change_record_params(const std::map<std::string, std::string>& params); |
67 | | |
68 | 0 | bool enabled() const { return !(_dump_type == RecordType::None); } |
69 | | |
70 | | private: |
71 | | void _dump(TUniqueId query_id); // dump data to disk. one query or all. |
72 | | |
73 | | std::mutex _data_lock; // lock for map, not map items. |
74 | | phmap::flat_hash_map<TUniqueId, OneQueryTraces> _datas; |
75 | | std::mutex _tg_lock; //TODO: use an lockfree DS |
76 | | phmap::flat_hash_map<TUniqueId, uint64_t> _id_to_workload_group; |
77 | | |
78 | | RecordType _dump_type = RecordType::None; |
79 | | decltype(MonotonicSeconds()) _last_dump_time; |
80 | | decltype(MonotonicSeconds()) _dump_interval_s = |
81 | | 60; // effective iff Periodic mode. 1 minute default. |
82 | | }; |
83 | | } // namespace doris::pipeline |