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 #include "symbols_filter.h"
17 #include <cstdint>
18 #include <limits>
19 #include <optional>
20
21 #include "log.h"
22 #include "measure_filter.h"
23 #include "process_filter.h"
24 #include "ts_common.h"
25
26 namespace SysTuning {
27 namespace TraceStreamer {
SymbolsFilter(TraceDataCache * dataCache,const TraceStreamerFilters * filter)28 SymbolsFilter::SymbolsFilter(TraceDataCache* dataCache, const TraceStreamerFilters* filter)
29 : FilterBase(dataCache, filter)
30 {
31 }
32
33 SymbolsFilter::~SymbolsFilter() = default;
RegisterFunc(uint64_t addr,DataIndex funcNameDictIndex)34 void SymbolsFilter::RegisterFunc(uint64_t addr, DataIndex funcNameDictIndex)
35 {
36 if (symbolsMap_.find(addr) == symbolsMap_.end()) {
37 symbolsMap_.insert(std::make_pair(addr, funcNameDictIndex));
38 traceDataCache_->GetSymbolsData()->InsertSymbol(funcNameDictIndex, addr);
39 } else {
40 symbolsMap_.at(addr) = funcNameDictIndex;
41 }
42 }
43
GetFunc(uint64_t addr) const44 const DataIndex& SymbolsFilter::GetFunc(uint64_t addr) const
45 {
46 if (symbolsMap_.find(addr) == symbolsMap_.end()) {
47 auto lastAddr = symbolsMap_.lower_bound(addr);
48 if (lastAddr == symbolsMap_.end()) {
49 return INVALID_UINT64;
50 }
51 return lastAddr->second;
52 } else {
53 return symbolsMap_.at(addr);
54 }
55 }
Clear()56 void SymbolsFilter::Clear()
57 {
58 symbolsMap_.clear();
59 }
60 } // namespace TraceStreamer
61 } // namespace SysTuning
62