• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "sched_stdtype.h"
17 namespace SysTuning {
18 namespace TraceStdtype {
AppendThreadState(InternalTime ts,InternalTime dur,InternalCpu cpu,InternalTid itid,TableRowId idState)19 TableRowId ThreadStateData::AppendThreadState(InternalTime ts,
20                                               InternalTime dur,
21                                               InternalCpu cpu,
22                                               InternalTid itid,
23                                               TableRowId idState)
24 {
25     ids_.emplace_back(id_++);
26     timeStamps_.emplace_back(ts);
27     durations_.emplace_back(dur);
28     itids_.emplace_back(itid);
29     tids_.emplace_back(INVALID_UINT32);
30     pids_.emplace_back(INVALID_UINT32);
31     states_.emplace_back(idState);
32     cpus_.emplace_back(cpu);
33     argSetIds_.emplace_back(INVALID_UINT32);
34     return Size() - 1;
35 }
36 
SetDuration(TableRowId index,InternalTime dur)37 void ThreadStateData::SetDuration(TableRowId index, InternalTime dur)
38 {
39     durations_[index] = dur;
40 }
41 
SortAllRowByTs()42 void ThreadStateData::SortAllRowByTs()
43 {
44     std::deque<InternalTime> timeStampsTemp;
45     timeStampsTemp = std::move(timeStamps_);
46     std::multimap<uint64_t, uint32_t> timeStampsToIdMap = {};
47     for (auto id = 0; id < timeStampsTemp.size(); ++id) {
48         timeStampsToIdMap.insert({timeStampsTemp[id], id});
49     }
50     std::deque<InternalTime> durationsTemp;
51     std::deque<InternalTid> itidsTemp;
52     std::deque<InternalTid> tidsTemp;
53     std::deque<InternalPid> pidsTemp;
54     std::deque<DataIndex> statesTemp;
55     std::deque<InternalCpu> cpusTemp;
56     std::deque<uint32_t> argSetIdsTemp;
57     durationsTemp = std::move(durations_);
58     itidsTemp = std::move(itids_);
59     tidsTemp = std::move(tids_);
60     pidsTemp = std::move(pids_);
61     statesTemp = std::move(states_);
62     cpusTemp = std::move(cpus_);
63     argSetIdsTemp = std::move(argSetIds_);
64     for (auto itor = timeStampsToIdMap.begin(); itor != timeStampsToIdMap.end(); itor++) {
65         timeStamps_.emplace_back(timeStampsTemp[itor->second]);
66         durations_.emplace_back(durationsTemp[itor->second]);
67         itids_.emplace_back(itidsTemp[itor->second]);
68         tids_.emplace_back(tidsTemp[itor->second]);
69         pids_.emplace_back(pidsTemp[itor->second]);
70         states_.emplace_back(statesTemp[itor->second]);
71         cpus_.emplace_back(cpusTemp[itor->second]);
72         argSetIds_.emplace_back(argSetIdsTemp[itor->second]);
73     }
74 }
75 
UpdateDuration(TableRowId index,InternalTime ts)76 TableRowId ThreadStateData::UpdateDuration(TableRowId index, InternalTime ts)
77 {
78     if (durations_[index] == INVALID_TIME) {
79         durations_[index] = ts - timeStamps_[index];
80     }
81     return itids_[index];
82 }
83 
End(TableRowId index,InternalTime ts)84 bool ThreadStateData::End(TableRowId index, InternalTime ts)
85 {
86     if (durations_[index] == INVALID_TIME) {
87         durations_[index] = -1;
88         return false;
89     }
90     return true;
91 }
UpdateState(TableRowId index,TableRowId idState)92 void ThreadStateData::UpdateState(TableRowId index, TableRowId idState)
93 {
94     states_[index] = idState;
95 }
SetArgSetId(TableRowId index,uint32_t setId)96 void ThreadStateData::SetArgSetId(TableRowId index, uint32_t setId)
97 {
98     argSetIds_[index] = setId;
99 }
100 
UpdateDuration(TableRowId index,InternalTime ts,TableRowId idState)101 void ThreadStateData::UpdateDuration(TableRowId index, InternalTime ts, TableRowId idState)
102 {
103     durations_[index] = ts - timeStamps_[index];
104     states_[index] = idState;
105 }
106 
UpdateTidAndPid(TableRowId index,InternalTid tid,InternalTid pid)107 void ThreadStateData::UpdateTidAndPid(TableRowId index, InternalTid tid, InternalTid pid)
108 {
109     tids_[index] = tid;
110     pids_[index] = pid;
111 }
112 
UpdateDuration(TableRowId index,InternalTime ts,InternalCpu cpu,TableRowId idState)113 TableRowId ThreadStateData::UpdateDuration(TableRowId index, InternalTime ts, InternalCpu cpu, TableRowId idState)
114 {
115     cpus_[index] = cpu;
116     durations_[index] = ts - timeStamps_[index];
117     states_[index] = idState;
118     return itids_[index];
119 }
120 
AppendSchedSlice(const SchedSliceRow & schedSliceRow)121 size_t SchedSlice::AppendSchedSlice(const SchedSliceRow &schedSliceRow)
122 {
123     ids_.emplace_back(id_++);
124     timeStamps_.emplace_back(schedSliceRow.ts);
125     durs_.emplace_back(schedSliceRow.dur);
126     cpus_.emplace_back(schedSliceRow.cpu);
127     tsEnds_.emplace_back(0);
128     internalTids_.emplace_back(schedSliceRow.internalTid);
129     endStates_.emplace_back(schedSliceRow.endState);
130     priority_.emplace_back(schedSliceRow.priority);
131     argSets_.emplace_back(INVALID_UINT32);
132     internalPids_.emplace_back(INVALID_UINT32);
133     return Size() - 1;
134 }
135 
SetDuration(size_t index,uint64_t duration)136 void SchedSlice::SetDuration(size_t index, uint64_t duration)
137 {
138     durs_[index] = duration;
139     tsEnds_[index] = timeStamps_[index] + duration;
140 }
141 
Update(uint64_t index,uint64_t ts,uint64_t state)142 void SchedSlice::Update(uint64_t index, uint64_t ts, uint64_t state)
143 {
144     durs_[index] = ts - timeStamps_[index];
145     endStates_[index] = state;
146 }
147 
UpdateEndState(uint64_t index,uint64_t state)148 void SchedSlice::UpdateEndState(uint64_t index, uint64_t state)
149 {
150     endStates_[index] = state;
151 }
152 
UpdateArg(uint64_t index,uint32_t argsetId)153 void SchedSlice::UpdateArg(uint64_t index, uint32_t argsetId)
154 {
155     argSets_[index] = argsetId;
156 }
157 
AppendRawData(uint64_t timeStamp,uint32_t name,uint32_t cpu,uint32_t internalTid)158 size_t Raw::AppendRawData(uint64_t timeStamp, uint32_t name, uint32_t cpu, uint32_t internalTid)
159 {
160     ids_.emplace_back(id_++);
161     timeStamps_.emplace_back(timeStamp);
162     nameDeque_.emplace_back(name);
163     cpuDeque_.emplace_back(cpu);
164     internalTids_.emplace_back(internalTid);
165     return Size() - 1;
166 }
167 
AppendInstantEventData(uint64_t timeStamp,DataIndex nameIndex,int64_t internalTid,int64_t wakeupFromInternalPid)168 size_t Instants::AppendInstantEventData(uint64_t timeStamp,
169                                         DataIndex nameIndex,
170                                         int64_t internalTid,
171                                         int64_t wakeupFromInternalPid)
172 {
173     internalTids_.emplace_back(internalTid);
174     timeStamps_.emplace_back(timeStamp);
175     NameIndexs_.emplace_back(nameIndex);
176     wakeupFromInternalPids_.emplace_back(wakeupFromInternalPid);
177     return Size() - 1;
178 }
179 } // namespace TraceStdtype
180 } // namespace SysTuning
181