• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "perf_data_filter.h"
16 #include "measure_filter.h"
17 #include "process_filter.h"
18 #include "slice_filter.h"
19 #include "string_to_numerical.h"
20 namespace SysTuning {
21 namespace TraceStreamer {
PerfDataFilter(TraceDataCache * dataCache,const TraceStreamerFilters * filter)22 PerfDataFilter::PerfDataFilter(TraceDataCache *dataCache, const TraceStreamerFilters *filter)
23     : FilterBase(dataCache, filter), fileIdToRowInFileTable_(INVALID_UINT64)
24 {
25 }
26 PerfDataFilter::~PerfDataFilter() = default;
27 
AppendPerfFiles(uint64_t fileId,uint32_t serial,DataIndex symbols,DataIndex filePath)28 size_t PerfDataFilter::AppendPerfFiles(uint64_t fileId, uint32_t serial, DataIndex symbols, DataIndex filePath)
29 {
30     fileIds_.emplace(fileId);
31     auto size = traceDataCache_->GetPerfFilesData()->AppendNewPerfFiles(fileId, serial, symbols, filePath);
32     fileIdToRowInFileTable_.Insert(fileId, serial, size);
33     if (!serial || serial == INVALID_UINT32) {
34         fileIdToRow_.insert(std::make_pair(fileId, size));
35     }
36     return size;
37 }
38 
AppendInvalidVaddrIpToFuncName(uint64_t ip,DataIndex nameIndex)39 void PerfDataFilter::AppendInvalidVaddrIpToFuncName(uint64_t ip, DataIndex nameIndex)
40 {
41     auto iter = invalidVaddrIpToFuncName_.find(ip);
42     if (iter == invalidVaddrIpToFuncName_.end()) {
43         invalidVaddrIpToFuncName_.emplace(ip, nameIndex);
44     }
45 }
46 
BeforeReload()47 void PerfDataFilter::BeforeReload()
48 {
49     traceDataCache_->GetPerfCallChainData()->Clear();
50     traceDataCache_->GetPerfFilesData()->Clear();
51     fileIdToRowInFileTable_.Clear();
52     fileIds_.clear();
53     fileIdToRow_.clear();
54     invalidVaddrIpToFuncName_.clear();
55 }
Finish()56 void PerfDataFilter::Finish()
57 {
58     auto fileIds = traceDataCache_->GetPerfCallChainData()->FileIds();
59     auto ips = traceDataCache_->GetPerfCallChainData()->Ips();
60     auto symbolsIds = traceDataCache_->GetPerfCallChainData()->SymbolIds();
61     auto vaddrs = traceDataCache_->GetPerfCallChainData()->VaddrInFiles();
62     auto size = traceDataCache_->GetPerfCallChainData()->Size();
63     auto filePath = traceDataCache_->GetPerfFilesData()->FilePaths();
64     auto sambols = traceDataCache_->GetPerfFilesData()->Symbols();
65     uint64_t flag = 1;
66     flag = ~(flag << FLAG_SHIFT_LEFT);
67     for (auto i = 0; i < size; i++) {
68         if (fileIds[i] == INVALID_UINT64) {
69             auto nameIndex = traceDataCache_->GetDataIndex("@0x" + base::number(ips[i], base::INTEGER_RADIX_TYPE_HEX));
70             traceDataCache_->GetPerfCallChainData()->SetName(i, nameIndex);
71             continue;
72         }
73         if (vaddrs[i] == 0 || symbolsIds[i] == -1) {
74             auto iter = invalidVaddrIpToFuncName_.find(ips[i]);
75             if (iter != invalidVaddrIpToFuncName_.end()) {
76                 traceDataCache_->GetPerfCallChainData()->SetName(i, iter->second);
77             } else {
78                 TS_LOGE("invalidVaddrIpToFuncName_ can't find ip:%p", ips[i]);
79             }
80             continue;
81         }
82         // if there has the file Id to which the function belongs,and the symboleid is not -1 and vaddrinfile is not -1.
83         // Set the function name as the virtual address of this function
84         auto value = fileIdToRowInFileTable_.Find(fileIds[i], symbolsIds[i]);
85         if (value == INVALID_UINT64) {
86             auto nameIndex = traceDataCache_->GetDataIndex(
87                 "+0x" + base::number(traceDataCache_->GetPerfCallChainData()->VaddrInFiles()[i] & flag));
88             traceDataCache_->GetPerfCallChainData()->SetName(i, nameIndex);
89             continue;
90         }
91         // The function name is not empty
92         traceDataCache_->GetPerfCallChainData()->SetName(i, sambols[value]);
93     }
94     fileIdToRowInFileTable_.Clear();
95     fileIds_.clear();
96     fileIdToRow_.clear();
97     invalidVaddrIpToFuncName_.clear();
98 }
99 } // namespace TraceStreamer
100 } // namespace SysTuning
101