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 TRACE_STDTYPE_H 17 #define TRACE_STDTYPE_H 18 19 #include <array> 20 #include <deque> 21 #include <limits> 22 #include <map> 23 #include <mutex> 24 #include <optional> 25 #include <sstream> 26 #include <stdexcept> 27 #include <string> 28 #include <unordered_map> 29 #include <vector> 30 #include "ts_common.h" 31 32 namespace SysTuning { 33 namespace TraceStdtype { 34 using namespace SysTuning::TraceStreamer; 35 // the supported metadata 36 enum MetaDataItem { METADATA_ITEM_PARSERTOOL_VERSION, METADATA_ITEM_PARSERTOOL_PUBLISH_DATETIME, METADATA_ITEM_MAX }; 37 class DemoCacheBase { 38 public: Size()39 size_t Size() const 40 { 41 return std::max(demoTimeStamps_.size(), demoIds_.size()); 42 } IdsData()43 const std::deque<uint64_t> &IdsData() const 44 { 45 return demoIds_; 46 } TimeStampData()47 const std::deque<uint64_t> &TimeStampData() const 48 { 49 return demoTimeStamps_; 50 } InternalTidsData()51 const std::deque<InternalTid> &InternalTidsData() const 52 { 53 return demoInternalTids_; 54 } Clear()55 virtual void Clear() 56 { 57 demoInternalTids_.clear(); 58 demoTimeStamps_.clear(); 59 demoIds_.clear(); 60 } 61 62 public: 63 std::deque<InternalTid> demoInternalTids_ = {}; 64 std::deque<uint64_t> demoTimeStamps_ = {}; 65 std::deque<uint64_t> demoIds_ = {}; 66 }; 67 68 class GpuCounterObject : public DemoCacheBase { 69 public: 70 GpuCounterObject() = default; 71 ~GpuCounterObject() = default; 72 void AppendNewData(int32_t counterId, const std::string counterName); 73 const std::deque<int32_t> &CounterId() const; 74 const std::deque<std::string> &CounterName() const; 75 76 private: 77 std::deque<int32_t> counterId_ = {}; 78 std::deque<std::string> counterName_ = {}; 79 }; 80 class GpuCounter : public DemoCacheBase { 81 public: 82 GpuCounter() = default; 83 ~GpuCounter() = default; 84 void AppendNewData(uint64_t ts, int32_t counterId, int32_t value); 85 const std::deque<uint64_t> &TimeStamp() const; 86 const std::deque<int32_t> &CounterId() const; 87 const std::deque<int32_t> &Value() const; 88 89 private: 90 std::deque<uint64_t> ts_ = {}; 91 std::deque<int32_t> counterId_ = {}; 92 std::deque<int32_t> value_ = {}; 93 }; 94 95 class SliceObject : public DemoCacheBase { 96 public: 97 SliceObject() = default; 98 ~SliceObject() = default; 99 void AppendNewData(int32_t sliceId, std::string sliceName); 100 const std::deque<int32_t> &SliceId() const; 101 const std::deque<std::string> &SliceName() const; 102 103 private: 104 std::deque<int32_t> sliceId_ = {}; 105 std::deque<std::string> sliceName_ = {}; 106 }; 107 class SliceData : public DemoCacheBase { 108 public: 109 SliceData() = default; 110 ~SliceData() = default; 111 void AppendNewData(int32_t sliceId, uint64_t startTs, uint64_t endTs, int32_t value); 112 const std::deque<int32_t> &SliceId() const; 113 const std::deque<uint64_t> &TimeStamp() const; 114 const std::deque<uint64_t> &EndTs() const; 115 const std::deque<int32_t> &Value() const; 116 117 private: 118 std::deque<uint64_t> startTs_ = {}; 119 std::deque<int32_t> sliceId_ = {}; 120 std::deque<uint64_t> endTs_ = {}; 121 std::deque<int32_t> value_ = {}; 122 }; 123 class MetaData : public DemoCacheBase { 124 public: 125 MetaData() = default; 126 ~MetaData() = default; 127 void InitMetaData(); 128 void SetParserToolVersion(const std::string &version); 129 void SetParserToolPublishDateTime(const std::string &datetime); 130 const std::string &Value(uint64_t row) const; 131 const std::string &Name(uint64_t row) const; Clear()132 void Clear() override 133 { 134 columnNames_.clear(); 135 values_.clear(); 136 } 137 138 private: 139 const std::string METADATA_ITEM_PARSERTOOL_VERSION_COLNAME = "tool_version"; 140 const std::string METADATA_ITEM_PARSERTOOL_PUBLISH_DATETIME_COLNAME = "tool_publish_time"; 141 std::deque<std::string> columnNames_ = {}; 142 std::deque<std::string> values_ = {}; 143 }; 144 } // namespace TraceStdtype 145 } // namespace SysTuning 146 147 #endif // TRACE_STDTYPE_H 148