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 uint32_t childCallid = INVALID_UINT32; 33 }; 34 class CallStack : public CacheBase, public CpuCacheBase, public BatchCacheBase { 35 public: 36 size_t AppendInternalAsyncSlice(const CallStackInternalRow &callStackInternalRow, 37 int64_t cookid, 38 const std::optional<uint64_t> &parentId); 39 size_t AppendInternalSlice(const CallStackInternalRow &callStackInternalRow, 40 const std::optional<uint64_t> &parentId); 41 void SetDistributeInfo(size_t index, 42 const std::string &chainId, 43 const std::string &spanId, 44 const std::string &parentSpanId, 45 const std::string &flag); 46 void AppendDistributeInfo(); 47 void AppendTraceMetadata(); 48 void SetDuration(size_t index, uint64_t timeStamp); 49 void SetTraceMetadata(size_t index, 50 const std::string &traceLevel, 51 const DataIndex &tag, 52 const DataIndex &customArg, 53 const DataIndex &customCategory = INVALID_UINT64); 54 void SetDurationWithFlag(size_t index, uint64_t timeStamp); 55 void SetFlag(size_t index, uint8_t flag); 56 void SetDurationEx(size_t index, uint32_t dur); 57 void SetIrqDurAndArg(size_t index, uint64_t timeStamp, uint32_t argSetId); 58 void SetTimeStamp(size_t index, uint64_t timeStamp); 59 void SetDepth(size_t index, uint8_t depth); 60 void SetArgSetId(size_t index, uint32_t argSetId); 61 void SetColorIndex(size_t index, uint32_t colorIndex); Clear()62 void Clear() override 63 { 64 CacheBase::Clear(); 65 CpuCacheBase::Clear(); 66 cats_.clear(); 67 cookies_.clear(); 68 callIds_.clear(); 69 colorIndexs_.clear(); 70 names_.clear(); 71 depths_.clear(); 72 chainIds_.clear(); 73 spanIds_.clear(); 74 parentSpanIds_.clear(); 75 flags_.clear(); 76 argSet_.clear(); 77 traceLevels_.clear(); 78 traceTags_.clear(); 79 customCategorys_.clear(); 80 customArgs_.clear(); 81 childCallid_.clear(); 82 } ClearExportedData()83 void ClearExportedData() override 84 { 85 EraseElements(timeStamps_, ids_, durs_, cats_, cookies_, colorIndexs_, callIds_, names_, depths_, chainIds_, 86 spanIds_, parentSpanIds_, flags_, argSet_, traceLevels_, traceTags_, customCategorys_, 87 customArgs_, childCallid_); 88 } 89 const std::deque<std::optional<uint64_t>> &ParentIdData() const; 90 const std::deque<DataIndex> &CatsData() const; 91 const std::deque<DataIndex> &NamesData() const; 92 const std::deque<uint8_t> &Depths() const; 93 const std::deque<int64_t> &Cookies() const; 94 const std::deque<uint32_t> &CallIds() const; 95 const std::deque<uint32_t> &ColorIndexs() const; 96 const std::deque<std::string> &ChainIds() const; 97 const std::deque<std::string> &SpanIds() const; 98 const std::deque<std::string> &ParentSpanIds() const; 99 const std::deque<std::string> &Flags() const; 100 const std::deque<uint32_t> &ArgSetIdsData() const; 101 const std::deque<std::string> &TraceLevelsData() const; 102 const std::deque<DataIndex> &TraceTagsData() const; 103 const std::deque<DataIndex> &CustomCategorysData() const; 104 const std::deque<DataIndex> &CustomArgsData() const; 105 const std::deque<std::optional<uint64_t>> &ChildCallidData() const; 106 107 private: 108 void AppendCommonInfo(uint64_t startT, uint64_t durationNs, InternalTid internalTid); 109 void AppendCallStack(DataIndex cat, 110 DataIndex name, 111 uint8_t depth, 112 std::optional<uint64_t> childCallid, 113 std::optional<uint64_t> parentId); 114 115 private: 116 std::deque<std::optional<uint64_t>> parentIds_; 117 std::deque<DataIndex> cats_ = {}; 118 std::deque<int64_t> cookies_ = {}; 119 std::deque<uint32_t> callIds_ = {}; 120 std::deque<DataIndex> names_ = {}; 121 std::deque<uint8_t> depths_ = {}; 122 std::deque<uint32_t> colorIndexs_ = {}; 123 std::deque<std::string> chainIds_ = {}; 124 std::deque<std::string> spanIds_ = {}; 125 std::deque<std::string> parentSpanIds_ = {}; 126 std::deque<std::string> flags_ = {}; 127 std::deque<uint32_t> argSet_ = {}; 128 std::deque<std::string> traceLevels_ = {}; 129 std::deque<DataIndex> traceTags_ = {}; 130 std::deque<DataIndex> customCategorys_ = {}; 131 std::deque<DataIndex> customArgs_ = {}; 132 std::deque<std::optional<uint64_t>> childCallid_; 133 }; 134 } // namespace TraceStdtype 135 } // namespace SysTuning 136 #endif // CALLSTACK_STDTYPE_H 137