1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 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 SCHED_STDTYPE_H 17 #define SCHED_STDTYPE_H 18 #include "base_stdtype.h" 19 20 namespace SysTuning { 21 namespace TraceStdtype { 22 class ThreadStateData : public CacheBase, public BatchCacheBase { 23 public: 24 TableRowId AppendThreadState(InternalTime ts, 25 InternalTime dur, 26 InternalCpu cpu, 27 InternalTid itid, 28 TableRowId idState); 29 void SetDuration(TableRowId index, InternalTime dur); 30 TableRowId UpdateDuration(TableRowId index, InternalTime ts); 31 bool End(TableRowId index, InternalTime ts); 32 void UpdateState(TableRowId index, TableRowId idState); 33 void SetArgSetId(TableRowId index, uint32_t setId); 34 void UpdateDuration(TableRowId index, InternalTime ts, TableRowId idState); 35 void UpdateTidAndPid(TableRowId index, InternalTid tid, InternalTid pid); 36 TableRowId UpdateDuration(TableRowId index, InternalTime ts, InternalCpu cpu, TableRowId idState); 37 void SortAllRowByTs(); Clear()38 void Clear() override 39 { 40 CacheBase::Clear(); 41 durations_.clear(); 42 itids_.clear(); 43 tids_.clear(); 44 pids_.clear(); 45 states_.clear(); 46 cpus_.clear(); 47 } ClearExportedData()48 void ClearExportedData() override 49 { 50 EraseElements(ids_, timeStamps_, durations_, itids_, tids_, pids_, states_, cpus_, argSetIds_); 51 } DursData()52 const std::deque<InternalTime> &DursData() const 53 { 54 return durations_; 55 } ItidsData()56 const std::deque<InternalTid> &ItidsData() const 57 { 58 return itids_; 59 } TidsData()60 const std::deque<InternalTid> &TidsData() const 61 { 62 return tids_; 63 } PidsData()64 const std::deque<InternalPid> &PidsData() const 65 { 66 return pids_; 67 } StatesData()68 const std::deque<DataIndex> &StatesData() const 69 { 70 return states_; 71 } CpusData()72 const std::deque<InternalCpu> &CpusData() const 73 { 74 return cpus_; 75 } ArgSetsData()76 const std::deque<uint32_t> &ArgSetsData() const 77 { 78 return argSetIds_; 79 } 80 81 private: 82 std::deque<InternalTime> durations_; 83 std::deque<InternalTid> itids_; 84 std::deque<InternalTid> tids_; 85 std::deque<InternalPid> pids_; 86 std::deque<DataIndex> states_; 87 std::deque<InternalCpu> cpus_; 88 std::deque<uint32_t> argSetIds_; 89 }; 90 struct SchedSliceRow { 91 uint64_t ts = INVALID_UINT64; 92 uint64_t dur = INVALID_UINT64; 93 uint64_t cpu = INVALID_UINT64; 94 uint32_t internalTid = INVALID_UINT32; 95 uint64_t endState = INVALID_UINT64; 96 int32_t priority = INVALID_INT32; 97 }; 98 class SchedSlice : public CacheBase, public CpuCacheBase, public BatchCacheBase { 99 public: 100 size_t AppendSchedSlice(const SchedSliceRow &schedSliceRow); 101 void SetDuration(size_t index, uint64_t duration); 102 void Update(uint64_t index, uint64_t ts, uint64_t state); 103 void UpdateEndState(uint64_t index, uint64_t state); 104 void UpdateArg(uint64_t index, uint32_t argsetId); 105 EndStatesData()106 const std::deque<uint64_t> &EndStatesData() const 107 { 108 return endStates_; 109 } 110 PriorityData()111 const std::deque<int32_t> &PriorityData() const 112 { 113 return priority_; 114 } 115 ArgSetData()116 const std::deque<uint32_t> &ArgSetData() const 117 { 118 return argSets_; 119 } TsEndData()120 const std::deque<uint64_t> &TsEndData() const 121 { 122 return tsEnds_; 123 } InternalPidsData()124 const std::deque<InternalPid> &InternalPidsData() const 125 { 126 return internalPids_; 127 } ReviseInternalPid(uint32_t row,InternalPid ipid)128 void ReviseInternalPid(uint32_t row, InternalPid ipid) 129 { 130 if (row < internalPids_.size()) { 131 internalPids_[row] = ipid; 132 } 133 } Clear()134 void Clear() override 135 { 136 CacheBase::Clear(); 137 CpuCacheBase::Clear(); 138 endStates_.clear(); 139 priority_.clear(); 140 internalPids_.clear(); 141 tsEnds_.clear(); 142 } ClearExportedData()143 void ClearExportedData() override 144 { 145 EraseElements(ids_, internalTids_, timeStamps_, durs_, cpus_, endStates_, priority_, internalPids_, tsEnds_, 146 argSets_); 147 } 148 149 private: 150 std::deque<InternalPid> internalPids_ = {}; 151 std::deque<uint64_t> tsEnds_ = {}; 152 std::deque<uint64_t> endStates_ = {}; 153 std::deque<int32_t> priority_ = {}; 154 std::deque<uint32_t> argSets_ = {}; 155 }; 156 class Raw : public CacheBase, public BatchCacheBase { 157 public: 158 size_t AppendRawData(uint64_t timeStamp, uint32_t name, uint32_t cpu, uint32_t internalTid); NameData()159 const std::deque<uint32_t> &NameData() const 160 { 161 return nameDeque_; 162 } CpuData()163 const std::deque<uint32_t> &CpuData() const 164 { 165 return cpuDeque_; 166 } Clear()167 void Clear() override 168 { 169 CacheBase::Clear(); 170 nameDeque_.clear(); 171 cpuDeque_.clear(); 172 } ClearExportedData()173 void ClearExportedData() override 174 { 175 EraseElements(internalTids_, timeStamps_, ids_, nameDeque_, cpuDeque_); 176 } 177 178 private: 179 std::deque<uint32_t> nameDeque_ = {}; 180 std::deque<uint32_t> cpuDeque_ = {}; 181 }; 182 183 class Instants : public CacheBase, public BatchCacheBase { 184 public: 185 size_t AppendInstantEventData(uint64_t timeStamp, 186 DataIndex nameIndex, 187 int64_t internalTid, 188 int64_t wakeupFromInternalPid); 189 NameIndexsData()190 const std::deque<DataIndex> &NameIndexsData() const 191 { 192 return NameIndexs_; 193 } WakeupFromPidsData()194 const std::deque<int64_t> &WakeupFromPidsData() const 195 { 196 return wakeupFromInternalPids_; 197 } Clear()198 void Clear() override 199 { 200 CacheBase::Clear(); 201 NameIndexs_.clear(); 202 wakeupFromInternalPids_.clear(); 203 } ClearExportedData()204 void ClearExportedData() override 205 { 206 EraseElements(internalTids_, timeStamps_, NameIndexs_, wakeupFromInternalPids_); 207 } 208 209 private: 210 std::deque<DataIndex> NameIndexs_; 211 std::deque<int64_t> wakeupFromInternalPids_; 212 }; 213 } // namespace TraceStdtype 214 } // namespace SysTuning 215 216 #endif // SCHED_STDTYPE_H 217