• 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 #include "callstack_stdtype.h"
16 
17 namespace SysTuning {
18 namespace TraceStdtype {
AppendInternalAsyncSlice(const CallStackInternalRow & callStackInternalRow,int64_t cookid,const std::optional<uint64_t> & parentId)19 size_t CallStack::AppendInternalAsyncSlice(const CallStackInternalRow &callStackInternalRow,
20                                            int64_t cookid,
21                                            const std::optional<uint64_t> &parentId)
22 {
23     AppendCommonInfo(callStackInternalRow.startT, callStackInternalRow.durationNs, callStackInternalRow.internalTid);
24     AppendCallStack(callStackInternalRow.cat, callStackInternalRow.name, callStackInternalRow.depth, parentId);
25     AppendDistributeInfo();
26     cookies_.emplace_back(cookid);
27     ids_.emplace_back(id_++);
28     return Size() - 1;
29 }
AppendInternalSlice(const CallStackInternalRow & callStackInternalRow,const std::optional<uint64_t> & parentId)30 size_t CallStack::AppendInternalSlice(const CallStackInternalRow &callStackInternalRow,
31                                       const std::optional<uint64_t> &parentId)
32 {
33     AppendCommonInfo(callStackInternalRow.startT, callStackInternalRow.durationNs, callStackInternalRow.internalTid);
34     AppendCallStack(callStackInternalRow.cat, callStackInternalRow.name, callStackInternalRow.depth, parentId);
35     ids_.emplace_back(id_++);
36     cookies_.emplace_back(INVALID_INT64);
37     AppendDistributeInfo();
38     return Size() - 1;
39 }
40 
AppendCommonInfo(uint64_t startT,uint64_t durationNs,InternalTid internalTid)41 void CallStack::AppendCommonInfo(uint64_t startT, uint64_t durationNs, InternalTid internalTid)
42 {
43     timeStamps_.emplace_back(startT);
44     durs_.emplace_back(durationNs);
45     callIds_.emplace_back(internalTid);
46     colorIndexs_.emplace_back(0);
47 }
AppendCallStack(DataIndex cat,DataIndex name,uint8_t depth,std::optional<uint64_t> parentId)48 void CallStack::AppendCallStack(DataIndex cat, DataIndex name, uint8_t depth, std::optional<uint64_t> parentId)
49 {
50     parentIds_.emplace_back(parentId);
51     cats_.emplace_back(cat);
52     names_.emplace_back(name);
53     depths_.emplace_back(depth);
54 }
SetDistributeInfo(size_t index,const std::string & chainId,const std::string & spanId,const std::string & parentSpanId,const std::string & flag)55 void CallStack::SetDistributeInfo(size_t index,
56                                   const std::string &chainId,
57                                   const std::string &spanId,
58                                   const std::string &parentSpanId,
59                                   const std::string &flag)
60 {
61     chainIds_[index] = chainId;
62     spanIds_[index] = spanId;
63     parentSpanIds_[index] = parentSpanId;
64     flags_[index] = flag;
65     argSet_[index] = INVALID_UINT32;
66 }
AppendDistributeInfo()67 void CallStack::AppendDistributeInfo()
68 {
69     chainIds_.emplace_back("");
70     spanIds_.emplace_back("");
71     parentSpanIds_.emplace_back("");
72     flags_.emplace_back("");
73     argSet_.emplace_back(INVALID_UINT32);
74 }
SetDuration(size_t index,uint64_t timeStamp)75 void CallStack::SetDuration(size_t index, uint64_t timeStamp)
76 {
77     durs_[index] = timeStamp - timeStamps_[index];
78 }
SetDurationWithFlag(size_t index,uint64_t timeStamp)79 void CallStack::SetDurationWithFlag(size_t index, uint64_t timeStamp)
80 {
81     durs_[index] = timeStamp - timeStamps_[index];
82     flags_[index] = "1";
83 }
84 
SetFlag(size_t index,uint8_t flag)85 void CallStack::SetFlag(size_t index, uint8_t flag)
86 {
87     flags_[index] = std::to_string(flag);
88 }
SetDurationEx(size_t index,uint32_t dur)89 void CallStack::SetDurationEx(size_t index, uint32_t dur)
90 {
91     durs_[index] = dur;
92 }
93 
SetIrqDurAndArg(size_t index,uint64_t timeStamp,uint32_t argSetId)94 void CallStack::SetIrqDurAndArg(size_t index, uint64_t timeStamp, uint32_t argSetId)
95 {
96     SetDuration(index, timeStamp);
97     argSet_[index] = argSetId;
98 }
SetTimeStamp(size_t index,uint64_t timeStamp)99 void CallStack::SetTimeStamp(size_t index, uint64_t timeStamp)
100 {
101     timeStamps_[index] = timeStamp;
102 }
103 
SetDepth(size_t index,uint8_t depth)104 void CallStack::SetDepth(size_t index, uint8_t depth)
105 {
106     depths_[index] = depth;
107 }
SetArgSetId(size_t index,uint32_t argSetId)108 void CallStack::SetArgSetId(size_t index, uint32_t argSetId)
109 {
110     argSet_[index] = argSetId;
111 }
SetColorIndex(size_t index,uint32_t colorIndex)112 void CallStack::SetColorIndex(size_t index, uint32_t colorIndex)
113 {
114     colorIndexs_[index] = colorIndex;
115 }
ParentIdData() const116 const std::deque<std::optional<uint64_t>> &CallStack::ParentIdData() const
117 {
118     return parentIds_;
119 }
CatsData() const120 const std::deque<DataIndex> &CallStack::CatsData() const
121 {
122     return cats_;
123 }
NamesData() const124 const std::deque<DataIndex> &CallStack::NamesData() const
125 {
126     return names_;
127 }
Depths() const128 const std::deque<uint8_t> &CallStack::Depths() const
129 {
130     return depths_;
131 }
Cookies() const132 const std::deque<int64_t> &CallStack::Cookies() const
133 {
134     return cookies_;
135 }
CallIds() const136 const std::deque<uint32_t> &CallStack::CallIds() const
137 {
138     return callIds_;
139 }
ColorIndexs() const140 const std::deque<uint32_t> &CallStack::ColorIndexs() const
141 {
142     return colorIndexs_;
143 }
ChainIds() const144 const std::deque<std::string> &CallStack::ChainIds() const
145 {
146     return chainIds_;
147 }
SpanIds() const148 const std::deque<std::string> &CallStack::SpanIds() const
149 {
150     return spanIds_;
151 }
ParentSpanIds() const152 const std::deque<std::string> &CallStack::ParentSpanIds() const
153 {
154     return parentSpanIds_;
155 }
Flags() const156 const std::deque<std::string> &CallStack::Flags() const
157 {
158     return flags_;
159 }
ArgSetIdsData() const160 const std::deque<uint32_t> &CallStack::ArgSetIdsData() const
161 {
162     return argSet_;
163 }
164 } // namespace TraceStdtype
165 } // namespace SysTuning
166