• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 "log.h"
21 #include "ts_common.h"
22 
23 namespace SysTuning {
24 namespace TraceStdtype {
25 constexpr uint32_t ONE_MILLION_NANOSECONDS = 1000000;
26 constexpr uint32_t BILLION_NANOSECONDS = 1000000000;
27 constexpr uint8_t DYNAMICFRAME_MATCH_LAST = 5;
28 class CacheBase {
29 public:
30     size_t Size() const;
31     const std::deque<uint64_t>& IdsData() const;
32     const std::deque<uint64_t>& TimeStampData() const;
33     const std::deque<InternalTid>& InternalTidsData() const;
Clear()34     virtual void Clear()
35     {
36         internalTids_.clear();
37         timeStamps_.clear();
38         ids_.clear();
39         id_ = 0;
40     }
41 
42 public:
43     std::deque<InternalTid> internalTids_ = {};
44     std::deque<uint64_t> timeStamps_ = {};
45     std::deque<uint64_t> ids_ = {};
46     uint64_t id_ = 0;
47 };
48 
49 class CpuCacheBase {
50 public:
51     const std::deque<uint64_t>& DursData() const;
52     const std::deque<uint32_t>& CpusData() const;
Clear()53     virtual void Clear()
54     {
55         durs_.clear();
56         cpus_.clear();
57     }
58     void SetDur(uint64_t index, uint64_t dur);
59 
60 public:
61     std::deque<uint64_t> durs_;
62     std::deque<uint32_t> cpus_;
63 };
64 
65 class BatchCacheBase {
66 public:
UpdateReadySize(size_t size)67     virtual void UpdateReadySize(size_t size)
68     {
69         readySize_ = size;
70     }
71     virtual void ClearExportedData() = 0;
72     template <typename T, typename... changedata>
EraseElements(T & deq,changedata &...args)73     void EraseElements(T& deq, changedata&... args)
74     {
75         deq.erase(deq.begin(), deq.begin() + readySize_);
76         EraseElements(args...);
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 };
88 } // namespace TraceStdtype
89 } // namespace SysTuning
90 
91 #endif // BASE_STDTYPE_H
92