• 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 PROCESS_FILTER_H
17 #define PROCESS_FILTER_H
18 
19 #include <tuple>
20 
21 #include "filter_base.h"
22 #include "trace_data_cache.h"
23 #include "trace_streamer_filters.h"
24 
25 namespace SysTuning {
26 namespace TraceStreamer {
27 class ProcessFilter : private FilterBase {
28 public:
29     ProcessFilter(TraceDataCache* dataCache, const TraceStreamerFilters* filter);
30     ~ProcessFilter() override;
31 
32     uint32_t UpdateOrCreateProcessWithName(uint32_t pid, std::string_view name);
33     uint32_t UpdateOrCreateThreadWithName(uint64_t timeStamp, uint32_t tid, std::string_view name);
34     uint32_t UpdateOrCreateThreadWithPidAndName(uint32_t tid, uint32_t pid, std::string_view name);
35     uint32_t GetOrCreateThreadWithPid(uint32_t tid, uint32_t pid);
36     uint32_t UpdateOrCreateThread(uint64_t timeStamp, uint32_t tid);
37     InternalPid GetInternalPid(uint32_t pid) const;
38     InternalPid GetOrCreateInternalPid(uint64_t timeStamp, uint32_t pid);
39     bool IsThreadNameEmpty(uint32_t tid) const;
40     InternalTid GetInternalTid(uint32_t tid) const;
41     std::vector<InternalTid>& GetInternalTids(uint32_t tid);
42     uint32_t UpdateOrCreateThreadWithNameIndex(uint64_t timeStamp, uint32_t tid, DataIndex threadNameIndex);
43     void AddProcessMemory(uint32_t ipid);
44     void AddThreadSliceNum(uint32_t itid);
45     void AddCpuStateCount(uint32_t itid);
46     void AddProcessSliceNum(uint32_t ipid);
47     void Clear();
48 
49 private:
50     std::tuple<uint32_t, TraceStdtype::Process*> CreateProcessMaybe(uint32_t pid, uint64_t startT);
51     std::tuple<uint32_t, TraceStdtype::Thread*> NewThread(uint32_t tid);
52     std::tuple<uint32_t, TraceStdtype::Process*> NewProcess(uint32_t pid);
53 
54     InternalTid GetInternalTid(uint32_t tid, uint32_t pid) const;
55 
56 private:
57     std::multimap<uint32_t, uint32_t> tidMappingSet_ = {};
58     std::vector<InternalTid> tmpTids_ = {};
59     std::map<uint32_t, uint32_t> pidToInternalPidMap_ = {};
60 };
61 } // namespace TraceStreamer
62 } // namespace SysTuning
63 
64 #endif // PROCESS_FILTER_H
65