• 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 
BeforeReload()39 void PerfDataFilter::BeforeReload()
40 {
41     traceDataCache_->GetPerfCallChainData()->Clear();
42     traceDataCache_->GetPerfFilesData()->Clear();
43     fileIdToRowInFileTable_.Clear();
44     fileIds_.clear();
45     fileIdToRow_.clear();
46 }
Finish()47 void PerfDataFilter::Finish()
48 {
49     auto fileIds = traceDataCache_->GetPerfCallChainData()->FileIds();
50     auto ips = traceDataCache_->GetPerfCallChainData()->Ips();
51     auto symbolsIds = traceDataCache_->GetPerfCallChainData()->SymbolIds();
52     auto vaddrs = traceDataCache_->GetPerfCallChainData()->VaddrInFiles();
53     auto size = traceDataCache_->GetPerfCallChainData()->Size();
54     auto filePath = traceDataCache_->GetPerfFilesData()->FilePaths();
55     auto sambols = traceDataCache_->GetPerfFilesData()->Symbols();
56     uint64_t flag = 1;
57     flag = ~(flag << FLAG_SHIFT_LEFT);
58     for (auto i = 0; i < size; i++) {
59         if (fileIds[i] == INVALID_UINT64) {
60             auto nameIndex = traceDataCache_->GetDataIndex("@0x" + base::number(ips[i], base::INTEGER_RADIX_TYPE_HEX));
61             traceDataCache_->GetPerfCallChainData()->SetName(i, nameIndex);
62             continue;
63         }
64         if (vaddrs[i] == 0 || symbolsIds[i] == -1) {
65             auto pathIndex = filePath[fileIdToRow_.at(fileIds[i])];
66             auto fullPath = traceDataCache_->GetDataFromDict(pathIndex);
67             auto iPos = fullPath.find_last_of('/');
68             fullPath = fullPath.substr(iPos + 1, -1);
69             auto nameIndex = traceDataCache_->GetDataIndex(fullPath + "@0x" +
70                                                            base::number(ips[i] & flag, base::INTEGER_RADIX_TYPE_HEX));
71             traceDataCache_->GetPerfCallChainData()->SetName(i, nameIndex);
72             continue;
73         }
74         // if there has the file Id to which the function belongs,and the symboleid is not -1 and vaddrinfile is not -1.
75         // Set the function name as the virtual address of this function
76         auto value = fileIdToRowInFileTable_.Find(fileIds[i], symbolsIds[i]);
77         if (value == INVALID_UINT64) {
78             auto nameIndex = traceDataCache_->GetDataIndex(
79                 "+0x" + base::number(traceDataCache_->GetPerfCallChainData()->VaddrInFiles()[i] & flag));
80             traceDataCache_->GetPerfCallChainData()->SetName(i, nameIndex);
81             continue;
82         }
83         // The function name is not empty
84         traceDataCache_->GetPerfCallChainData()->SetName(i, sambols[value]);
85     }
86     fileIdToRowInFileTable_.Clear();
87     fileIds_.clear();
88     fileIdToRow_.clear();
89 }
90 } // namespace TraceStreamer
91 } // namespace SysTuning
92