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 CALLSTACK_STDTYPE_H 17 #define CALLSTACK_STDTYPE_H 18 #include <cstdint> 19 #include <deque> 20 #include <optional> 21 #include "base_stdtype.h" 22 23 namespace SysTuning { 24 namespace TraceStdtype { 25 struct CallStackInternalRow { 26 uint64_t startT = INVALID_UINT64; 27 uint64_t durationNs = INVALID_UINT64; 28 InternalTid internalTid = INVALID_UINT32; 29 DataIndex cat = INVALID_UINT64; 30 DataIndex name = INVALID_UINT64; 31 uint8_t depth = INVALID_UINT8; 32 }; 33 class CallStack : public CacheBase, public CpuCacheBase, public BatchCacheBase { 34 public: 35 size_t AppendInternalAsyncSlice(const CallStackInternalRow &callStackInternalRow, 36 int64_t cookid, 37 const std::optional<uint64_t> &parentId); 38 size_t AppendInternalSlice(const CallStackInternalRow &callStackInternalRow, 39 const std::optional<uint64_t> &parentId); 40 void SetDistributeInfo(size_t index, 41 const std::string &chainId, 42 const std::string &spanId, 43 const std::string &parentSpanId, 44 const std::string &flag); 45 void AppendDistributeInfo(); 46 void SetDuration(size_t index, uint64_t timeStamp); 47 void SetDurationWithFlag(size_t index, uint64_t timeStamp); 48 void SetFlag(size_t index, uint8_t flag); 49 void SetDurationEx(size_t index, uint32_t dur); 50 void SetIrqDurAndArg(size_t index, uint64_t timeStamp, uint32_t argSetId); 51 void SetTimeStamp(size_t index, uint64_t timeStamp); 52 void SetDepth(size_t index, uint8_t depth); 53 void SetArgSetId(size_t index, uint32_t argSetId); 54 void SetColorIndex(size_t index, uint32_t colorIndex); Clear()55 void Clear() override 56 { 57 CacheBase::Clear(); 58 CpuCacheBase::Clear(); 59 cats_.clear(); 60 cookies_.clear(); 61 callIds_.clear(); 62 colorIndexs_.clear(); 63 names_.clear(); 64 depths_.clear(); 65 chainIds_.clear(); 66 spanIds_.clear(); 67 parentSpanIds_.clear(); 68 flags_.clear(); 69 argSet_.clear(); 70 } ClearExportedData()71 void ClearExportedData() override 72 { 73 EraseElements(timeStamps_, ids_, durs_, cats_, cookies_, colorIndexs_, callIds_, names_, depths_, chainIds_, 74 spanIds_, parentSpanIds_, flags_, argSet_); 75 } 76 const std::deque<std::optional<uint64_t>> &ParentIdData() const; 77 const std::deque<DataIndex> &CatsData() const; 78 const std::deque<DataIndex> &NamesData() const; 79 const std::deque<uint8_t> &Depths() const; 80 const std::deque<int64_t> &Cookies() const; 81 const std::deque<uint32_t> &CallIds() const; 82 const std::deque<uint32_t> &ColorIndexs() const; 83 const std::deque<std::string> &ChainIds() const; 84 const std::deque<std::string> &SpanIds() const; 85 const std::deque<std::string> &ParentSpanIds() const; 86 const std::deque<std::string> &Flags() const; 87 const std::deque<uint32_t> &ArgSetIdsData() const; 88 89 private: 90 void AppendCommonInfo(uint64_t startT, uint64_t durationNs, InternalTid internalTid); 91 void AppendCallStack(DataIndex cat, DataIndex name, uint8_t depth, std::optional<uint64_t> parentId); 92 93 private: 94 std::deque<std::optional<uint64_t>> parentIds_; 95 std::deque<DataIndex> cats_ = {}; 96 std::deque<int64_t> cookies_ = {}; 97 std::deque<uint32_t> callIds_ = {}; 98 std::deque<DataIndex> names_ = {}; 99 std::deque<uint8_t> depths_ = {}; 100 std::deque<uint32_t> colorIndexs_ = {}; 101 std::deque<std::string> chainIds_ = {}; 102 std::deque<std::string> spanIds_ = {}; 103 std::deque<std::string> parentSpanIds_ = {}; 104 std::deque<std::string> flags_ = {}; 105 std::deque<uint32_t> argSet_ = {}; 106 }; 107 } // namespace TraceStdtype 108 } // namespace SysTuning 109 #endif // CALLSTACK_STDTYPE_H 110