1 /*
2 * Copyright (c) 2023 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 __FFRT_PERF_H__
17 #define __FFRT_PERF_H__
18 #include "ffrt_trace.h"
19
20 // default disabled for ffrt, enable it for debugging or playback
21 #ifdef FFRT_PERF_ENABLE
22 struct PerfEU {
23 static constexpr size_t qos_max = 15;
24 static inline std::atomic_int worker_num[qos_max] = {0};
25 static inline const char* worker_num_tag[qos_max] = {
26 "qos0_wrk",
27 "qos1_wrk",
28 "qos2_wrk",
29 "qos3_wrk",
30 "qos4_wrk",
31 "qos5_wrk",
32 "qos6_wrk",
33 "qos7_wrk",
34 "qos8_wrk",
35 "qos9_wrk",
36 "qos10_wrk",
37 "qos11_wrk",
38 "qos12_wrk",
39 "qos13_wrk",
40 "qos14_wrk"
41 };
42
43 static inline const char* task_num_tag[qos_max] = {
44 "qos0_tsk",
45 "qos1_tsk",
46 "qos2_tsk",
47 "qos3_tsk",
48 "qos4_tsk",
49 "qos5_tsk",
50 "qos6_tsk",
51 "qos7_tsk",
52 "qos8_tsk",
53 "qos9_tsk",
54 "qos10_tsk",
55 "qos11_tsk",
56 "qos12_tsk",
57 "qos13_tsk",
58 "qos14_tsk"
59 };
60 };
61
FFRTPerfWorkerIdle(int qos)62 inline void FFRTPerfWorkerIdle(int qos)
63 {
64 if (qos >= 0 && qos < static_cast<int>(PerfEU::qos_max)) {
65 FFRT_TRACE_COUNT(PerfEU::worker_num_tag[qos],
66 PerfEU::worker_num[qos].fetch_sub(1, std::memory_order_relaxed) - 1);
67 }
68 }
69
FFRTPerfWorkerAwake(int qos)70 inline void FFRTPerfWorkerAwake(int qos)
71 {
72 if (qos >= 0 && qos < static_cast<int>(PerfEU::qos_max)) {
73 FFRT_TRACE_COUNT(PerfEU::worker_num_tag[qos],
74 PerfEU::worker_num[qos].fetch_add(1, std::memory_order_relaxed) + 1);
75 }
76 }
77
FFRTPerfTaskNum(int qos,int taskn)78 inline void FFRTPerfTaskNum(int qos, int taskn)
79 {
80 if (qos >= 0 && qos < static_cast<int>(PerfEU::qos_max)) {
81 FFRT_TRACE_COUNT(PerfEU::task_num_tag[qos], taskn);
82 }
83 }
84
85 #define FFRT_PERF_WORKER_IDLE(qos) FFRTPerfWorkerIdle(qos)
86 #define FFRT_PERF_WORKER_AWAKE(qos) FFRTPerfWorkerAwake(qos)
87 #define FFRT_PERF_TASK_NUM(qos, taskn) FFRTPerfTaskNum(qos, taskn)
88 #else
89 #define FFRT_PERF_WORKER_IDLE(qos)
90 #define FFRT_PERF_WORKER_AWAKE(qos)
91 #define FFRT_PERF_TASK_NUM(qos, taskn)
92 #endif
93
94 #endif // __FFRT_PERF_H__