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 BASE_STDTYPE_H 17 #define BASE_STDTYPE_H 18 19 #include <deque> 20 #include "ts_common.h" 21 22 namespace SysTuning { 23 namespace TraceStdtype { 24 constexpr uint32_t ONE_MILLION_NANOSECONDS = 1000000; 25 constexpr uint32_t BILLION_NANOSECONDS = 1000000000; 26 constexpr uint8_t DYNAMICFRAME_MATCH_LAST = 6; 27 class CacheBase { 28 public: 29 size_t Size() const; 30 const std::deque<uint64_t> &IdsData() const; 31 const std::deque<uint64_t> &TimeStampData() const; 32 const std::deque<InternalTid> &InternalTidsData() const; Clear()33 virtual void Clear() 34 { 35 internalTids_.clear(); 36 timeStamps_.clear(); 37 ids_.clear(); 38 id_ = 0; 39 } 40 41 public: 42 std::deque<InternalTid> internalTids_ = {}; 43 std::deque<uint64_t> timeStamps_ = {}; 44 std::deque<uint64_t> ids_ = {}; 45 uint64_t id_ = 0; 46 }; 47 48 class CpuCacheBase { 49 public: 50 const std::deque<uint64_t> &DursData() const; 51 const std::deque<uint32_t> &CpusData() const; Clear()52 virtual void Clear() 53 { 54 durs_.clear(); 55 cpus_.clear(); 56 } 57 void SetDur(uint64_t index, uint64_t dur); 58 59 public: 60 std::deque<uint64_t> durs_; 61 std::deque<uint32_t> cpus_; 62 }; 63 64 class BatchCacheBase { 65 public: UpdateReadySize(size_t size)66 virtual void UpdateReadySize(size_t size) 67 { 68 readySize_ = size; 69 } 70 virtual void ClearExportedData() = 0; 71 template <typename T, typename... changedata> EraseElements(T & deq,changedata &...args)72 void EraseElements(T &deq, changedata &... args) 73 { 74 deq.erase(deq.begin(), deq.begin() + readySize_); 75 EraseElements(args...); 76 diskTableSize_ += readySize_; 77 readySize_ = 0; 78 } 79 template <typename T1> EraseElements(T1 & deq)80 void EraseElements(T1 &deq) 81 { 82 deq.erase(deq.begin(), deq.begin() + readySize_); 83 } 84 85 public: 86 size_t readySize_ = 0; 87 size_t diskTableSize_ = 0; 88 }; 89 } // namespace TraceStdtype 90 } // namespace SysTuning 91 92 #endif // BASE_STDTYPE_H 93