• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef LPERF_RECORD_H
16 #define LPERF_RECORD_H
17 
18 #include <string>
19 #include <vector>
20 
21 #include "lperf_events.h"
22 #include "stack_printer.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 class LperfRecord {
27 public:
28     int StartProcessSampling(int pid, const std::vector<int>& tids, int freq, int duration);
29     int CollectSampleStack(std::string& datas);
30     void FinishProcessSampling();
31 
32 private:
33     int OnSubCommand();
34     void PrepareLperfEvent();
35     void SymbolicRecord(LperfRecordSample& record);
36 
37     LperfEvents lperfEvents_;
38     std::unique_ptr<StackPrinter> stackPrinter_ = nullptr;
39 
40     unsigned int timeStopSec_ = 0;
41     unsigned int frequency_ = 0;
42     int pid_ = 0;
43     std::vector<int> tids_ = {};
44 };
45 
46 template<typename T>
CheckOutOfRange(const T & value,const T & min,const T & max)47 inline bool CheckOutOfRange(const T& value, const T& min, const T& max)
48 {
49     return value < min || value > max;
50 }
51 } // namespace HiviewDFX
52 } // namespace OHOS
53 #endif // LPERF_RECORD_H