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 #include "measure_stdtype.h"
17
18 namespace SysTuning {
19 namespace TraceStdtype {
AppendNewFilterData(std::string type,std::string name,uint64_t sourceArgSetId)20 size_t Filter::AppendNewFilterData(std::string type, std::string name, uint64_t sourceArgSetId)
21 {
22 nameDeque_.emplace_back(name);
23 sourceArgSetId_.emplace_back(sourceArgSetId);
24 ids_.emplace_back(id_++);
25 typeDeque_.emplace_back(type);
26 return Size() - 1;
27 }
28
AppendMeasureData(uint32_t type,uint64_t timeStamp,int64_t value,uint32_t filterId)29 size_t Measure::AppendMeasureData(uint32_t type, uint64_t timeStamp, int64_t value, uint32_t filterId)
30 {
31 valuesDeque_.emplace_back(value);
32 filterIdDeque_.emplace_back(filterId);
33 typeDeque_.emplace_back(type);
34 timeStamps_.emplace_back(timeStamp);
35 durDeque_.emplace_back(INVALID_UINT64);
36 return Size() - 1;
37 }
38
SetDur(uint32_t row,uint64_t timeStamp)39 void Measure::SetDur(uint32_t row, uint64_t timeStamp)
40 {
41 durDeque_[row] = timeStamp - timeStamps_[row];
42 }
43
UpdatePrevSizeAndAdapterRows(size_t size)44 void Measure::UpdatePrevSizeAndAdapterRows(size_t size)
45 {
46 readySize_ = size;
47 // if filterIdToRow_.empty(), the readySize_ is all
48 if (filterIdToRow_.empty()) {
49 return;
50 }
51 // find minRowToBeUpdated
52 auto minRowToBeUpdated = filterIdToRow_.begin()->second;
53 for (const auto &pair : filterIdToRow_) {
54 if (minRowToBeUpdated > pair.second) {
55 minRowToBeUpdated = pair.second;
56 }
57 }
58 readySize_ = minRowToBeUpdated;
59 for (auto &pair : filterIdToRow_) {
60 pair.second -= readySize_;
61 }
62 }
63
AppendNewFilter(uint64_t filterId,DataIndex type,DataIndex nameId)64 size_t SysMeasureFilter::AppendNewFilter(uint64_t filterId, DataIndex type, DataIndex nameId)
65 {
66 ids_.emplace_back(filterId);
67 names_.emplace_back(nameId);
68 types_.emplace_back(type);
69 return ids_.size() - 1;
70 }
NamesData() const71 const std::deque<DataIndex> &SysMeasureFilter::NamesData() const
72 {
73 return names_;
74 }
75
TypesData() const76 const std::deque<DataIndex> &SysMeasureFilter::TypesData() const
77 {
78 return types_;
79 }
80
AppendNewFilter(uint64_t id,DataIndex name,uint32_t internalPid)81 size_t ProcessMeasureFilter::AppendNewFilter(uint64_t id, DataIndex name, uint32_t internalPid)
82 {
83 internalPids_.emplace_back(internalPid);
84 ids_.emplace_back(id);
85 names_.emplace_back(name);
86 return Size() - 1;
87 }
88
AppendNewFilter(uint64_t id,DataIndex type,DataIndex name,uint64_t cpu)89 size_t ClockEventData::AppendNewFilter(uint64_t id, DataIndex type, DataIndex name, uint64_t cpu)
90 {
91 cpus_.emplace_back(cpu);
92 ids_.emplace_back(id);
93 types_.emplace_back(type);
94 names_.emplace_back(name);
95 return Size() - 1;
96 }
AppendNewFilter(uint64_t id,uint64_t rate,DataIndex name,uint64_t cpu)97 size_t ClkEventData::AppendNewFilter(uint64_t id, uint64_t rate, DataIndex name, uint64_t cpu)
98 {
99 ids_.emplace_back(id);
100 rates_.emplace_back(rate);
101 names_.emplace_back(name);
102 cpus_.emplace_back(cpu);
103 return Size() - 1;
104 }
105 } // namespace TraceStdtype
106 } // namespace SysTuning
107