• 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 #include "render_service_stdtype.h"
16 
17 namespace SysTuning {
18 namespace TraceStdtype {
AppendFrame(uint64_t ts,uint32_t ipid,uint32_t itid,uint32_t vsyncId,uint64_t callStackSliceId)19 size_t FrameSlice::AppendFrame(uint64_t ts, uint32_t ipid, uint32_t itid, uint32_t vsyncId, uint64_t callStackSliceId)
20 {
21     timeStamps_.emplace_back(ts);
22     ipids_.emplace_back(ipid);
23     internalTids_.emplace_back(itid);
24     vsyncIds_.emplace_back(vsyncId);
25     callStackIds_.emplace_back(callStackSliceId);
26     endTss_.emplace_back(INVALID_UINT64);
27     dsts_.emplace_back(INVALID_UINT64);
28     ids_.emplace_back(ids_.size());
29     durs_.emplace_back(INVALID_UINT64);
30     types_.emplace_back(0);
31     flags_.emplace_back(INVALID_UINT8);
32     srcs_.emplace_back("");
33     depths_.emplace_back(0);
34     frameNos_.emplace_back(0);
35     return Size() - 1;
36 }
AppendFrame(uint64_t ts,uint32_t ipid,uint32_t itid,uint32_t vsyncId,uint64_t callStackSliceId,uint64_t end,uint8_t type)37 size_t FrameSlice::AppendFrame(uint64_t ts,
38                                uint32_t ipid,
39                                uint32_t itid,
40                                uint32_t vsyncId,
41                                uint64_t callStackSliceId,
42                                uint64_t end,
43                                uint8_t type)
44 {
45     auto row = AppendFrame(ts, ipid, itid, vsyncId, callStackSliceId);
46     SetEndTime(row, end);
47     SetType(row, type);
48     depths_.emplace_back(0);
49     frameNos_.emplace_back(0);
50     durs_[row] = end - ts;
51     return row;
52 }
53 
UpdateDepth()54 void FrameSlice::UpdateDepth()
55 {
56     DoubleMap<uint32_t, uint8_t, std::shared_ptr<std::vector<uint64_t>>> ipidAndTypesToVEndTime(nullptr);
57     for (auto row = 0; row < Size(); row++) {
58         if (flags_[row] == flagValue_) {
59             continue;
60         }
61         auto endTime = timeStamps_[row] + durs_[row];
62         auto vEndTimes = ipidAndTypesToVEndTime.Find(ipids_[row], types_[row]);
63         auto depth = 0;
64         if (!vEndTimes) {
65             vEndTimes = std::make_shared<std::vector<uint64_t>>();
66             vEndTimes->push_back(endTime);
67             ipidAndTypesToVEndTime.Insert(ipids_[row], types_[row], vEndTimes);
68             depths_[row] = depth;
69             continue;
70         }
71         for (; depth < vEndTimes->size(); depth++) {
72             if (timeStamps_[row] > vEndTimes->at(depth)) {
73                 depths_[row] = depth;
74                 vEndTimes->at(depth) = endTime;
75                 break;
76             }
77         }
78         if (depth == vEndTimes->size()) {
79             depths_[row] = depth;
80             vEndTimes->push_back(endTime);
81         }
82     }
83 }
84 
SetEndTime(uint64_t row,uint64_t end)85 void FrameSlice::SetEndTime(uint64_t row, uint64_t end)
86 {
87     endTss_[row] = end;
88 }
SetType(uint64_t row,uint8_t type)89 void FrameSlice::SetType(uint64_t row, uint8_t type)
90 {
91     types_[row] = type;
92 }
SetDst(uint64_t row,uint64_t dst)93 void FrameSlice::SetDst(uint64_t row, uint64_t dst)
94 {
95     dsts_[row] = dst;
96 }
97 
SetSrcs(uint64_t row,const std::vector<uint64_t> & fromSlices)98 void FrameSlice::SetSrcs(uint64_t row, const std::vector<uint64_t>& fromSlices)
99 {
100     std::string s = "";
101     for (auto&& i : fromSlices) {
102         s += std::to_string(i) + ",";
103     }
104     s.pop_back();
105     srcs_[row] = s;
106 }
SetFlags(uint64_t row,const uint32_t flags)107 void FrameSlice::SetFlags(uint64_t row, const uint32_t flags)
108 {
109     flags_[row] = flags;
110 }
Ipids() const111 const std::deque<uint32_t> FrameSlice::Ipids() const
112 {
113     return ipids_;
114 }
VsyncIds() const115 const std::deque<uint32_t> FrameSlice::VsyncIds() const
116 {
117     return vsyncIds_;
118 }
CallStackIds() const119 const std::deque<uint64_t> FrameSlice::CallStackIds() const
120 {
121     return callStackIds_;
122 }
EndTss() const123 const std::deque<uint64_t> FrameSlice::EndTss() const
124 {
125     return endTss_;
126 }
Dsts() const127 const std::deque<uint64_t> FrameSlice::Dsts() const
128 {
129     return dsts_;
130 }
Durs() const131 const std::deque<uint64_t> FrameSlice::Durs() const
132 {
133     return durs_;
134 }
Types() const135 const std::deque<uint8_t> FrameSlice::Types() const
136 {
137     return types_;
138 }
Flags() const139 const std::deque<uint8_t> FrameSlice::Flags() const
140 {
141     return flags_;
142 }
143 
Depths() const144 const std::deque<uint8_t> FrameSlice::Depths() const
145 {
146     return depths_;
147 }
FrameNos() const148 const std::deque<uint32_t> FrameSlice::FrameNos() const
149 {
150     return frameNos_;
151 }
Srcs() const152 const std::deque<std::string>& FrameSlice::Srcs() const
153 {
154     return srcs_;
155 }
UpdateCallStackSliceId(uint64_t row,uint64_t callStackSliceId)156 void FrameSlice::UpdateCallStackSliceId(uint64_t row, uint64_t callStackSliceId)
157 {
158     callStackIds_[row] = callStackSliceId;
159 }
SetEndTimeAndFlag(uint64_t row,uint64_t ts,uint64_t expectDur,uint64_t expectEnd)160 void FrameSlice::SetEndTimeAndFlag(uint64_t row, uint64_t ts, uint64_t expectDur, uint64_t expectEnd)
161 {
162     Unused(expectDur);
163     durs_[row] = ts - timeStamps_[row];
164     if (flags_[row] != abnormalStartEndTimeState_) {
165         flags_[row] = expectEnd >= ts ? 0 : 1;
166     }
167 }
Erase(uint64_t row)168 void FrameSlice::Erase(uint64_t row)
169 {
170     flags_[row] = invalidRow_;
171 }
172 
AppendNew(uint32_t frameRow,uint64_t dur)173 size_t GPUSlice::AppendNew(uint32_t frameRow, uint64_t dur)
174 {
175     frameRows_.emplace_back(frameRow);
176     durs_.emplace_back(dur);
177     return Size() - 1;
178 }
FrameRows() const179 const std::deque<uint32_t>& GPUSlice::FrameRows() const
180 {
181     return frameRows_;
182 }
Durs() const183 const std::deque<uint64_t>& GPUSlice::Durs() const
184 {
185     return durs_;
186 }
Size() const187 size_t GPUSlice::Size() const
188 {
189     return durs_.size();
190 }
191 
AppendNew(FrameSlice * frameSlice,uint64_t src,uint64_t dst)192 size_t FrameMaps::AppendNew(FrameSlice* frameSlice, uint64_t src, uint64_t dst)
193 {
194     timeStamps_.emplace_back(0);
195     ids_.emplace_back(ids_.size());
196     srcs_.emplace_back(src);
197     dsts_.emplace_back(dst);
198     if (frameSlice->Types().at(dst) == FrameSlice::EXPECT_SLICE) {
199         uint64_t expRsStartTime = frameSlice->TimeStampData().at(dst);
200         uint64_t expUiEndTime = frameSlice->TimeStampData().at(src) + frameSlice->Durs().at(src);
201         if (std::abs(static_cast<long long>(expRsStartTime - expUiEndTime)) >= ONE_MILLION_NANOSECONDS) {
202             auto acturalRow = dst - 1;
203             frameSlice->SetFlags(acturalRow, FrameSlice::GetAbnormalStartEndTimeState());
204         }
205     }
206 
207     return Size() - 1;
208 }
SrcIndexs() const209 const std::deque<uint64_t>& FrameMaps::SrcIndexs() const
210 {
211     return srcs_;
212 }
DstIndexs() const213 const std::deque<uint64_t>& FrameMaps::DstIndexs() const
214 {
215     return dsts_;
216 }
217 
218 } // namespace TraceStdtype
219 } // namespace SysTuning
220