• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 CPU_FILTER_H
17 #define CPU_FILTER_H
18 
19 #include <cstdint>
20 #include <limits>
21 #include <map>
22 #include <string_view>
23 #include <tuple>
24 
25 #include "filter_base.h"
26 #include "trace_data_cache.h"
27 #include "trace_streamer_filters.h"
28 #include "ts_common.h"
29 
30 namespace SysTuning {
31 namespace TraceStreamer {
32 class TraceStreamerFilters;
33 class CpuFilter : private FilterBase {
34 public:
35     CpuFilter(TraceDataCache* dataCache, const TraceStreamerFilters* filter);
36     CpuFilter(const CpuFilter&) = delete;
37     CpuFilter& operator=(const CpuFilter&) = delete;
38     ~CpuFilter() override;
39 
40 public:
41     void InsertSwitchEvent(uint64_t ts,
42                            uint64_t cpu,
43                            uint64_t prevPid,
44                            uint64_t prevPior,
45                            uint64_t prevState,
46                            uint64_t nextPid,
47                            uint64_t nextPior);
48     void InsertWakeupEvent(uint64_t ts, uint64_t internalTid);
49     bool InsertProcessExitEvent(uint64_t ts, uint64_t cpu, uint64_t pid);
50     bool InsertProcessFreeEvent(uint64_t ts, uint64_t pid);
51     void Finish() const;
52     void Clear();
53 private:
54     void CheckWakeupEvent(uint64_t internalTid);
55     uint64_t RemberInternalTidInStateTable(uint64_t uid, uint64_t row, uint64_t state = TASK_INVALID);
56     uint64_t RowOfInternalTidInStateTable(uint64_t uid) const;
57     uint64_t StateOfInternalTidInStateTable(uint64_t uid) const;
58     std::map<uint64_t, uint64_t> cpuToRowThreadState_ = {};
59     std::map<uint64_t, uint64_t> cpuToRowSched_ = {};
60     std::map<uint64_t, uint64_t> lastWakeUpMsg_ = {};
61     struct TPthread {
62         uint64_t row_;
63         uint64_t state_;
64     };
65     std::map<uint64_t, TPthread> internalTidToRowThreadState_ = {};
66 };
67 } // namespace TraceStreamer
68 } // namespace SysTuning
69 #endif // CPU_FILTER_H
70