• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2021. 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 #ifndef FTRACE_FS_OPS_H
16 #define FTRACE_FS_OPS_H
17 
18 #include <string>
19 #include <vector>
20 #include <iostream>
21 #include <fstream>
22 #include <sstream>
23 #include "ftrace_namespace.h"
24 
25 #ifndef MOCKABLE
26 #define MOCKABLE virtual
27 #endif
28 
29 FTRACE_NS_BEGIN
30 class FtraceFsOps {
31 public:
32     static FtraceFsOps& GetInstance();
33     static std::string GetFtraceRoot();
34     bool IsHmKernel();
35     int WriteTraceFile(const std::string& path, const std::string& content);
36     int WriteTraceFile(const std::string& path, const std::string& content, int flags);
37     std::string ReadTraceFile(const std::string& path) const;
38     std::string GetKernelVersion() const;
39 
40     MOCKABLE std::string GetKernelSymbols() const;
41     MOCKABLE std::string GetPrintkFormats() const;
42 
43     MOCKABLE std::string GetProcessComm(int pid);
44     MOCKABLE std::string GetThreadComm(int pid, int tid);
45 
46     // for ftrace status nodes
47     bool SetSavedCmdLinesSize(uint32_t size);
48     MOCKABLE std::string GetSavedCmdLines() const;
49     MOCKABLE std::string GetSavedTgids() const;
50     MOCKABLE int GetTgidFromStatus(int pid) const;
51     MOCKABLE std::string GetPerCpuStats(int cpu) const;
52     MOCKABLE std::string GetRawTracePath(int cpu) const;
53     std::string GetHmRawTracePath() const;
54     MOCKABLE std::string GetPageHeaderFormat() const;
55     MOCKABLE std::string GetEventDataFormat(const std::string& type, const std::string& name) const;
56     MOCKABLE std::vector<std::pair<std::string, std::string>> GetPlatformEvents();
57 
58     // for ftrace control nodes
59     MOCKABLE bool ClearTraceBuffer();
60     MOCKABLE bool SetRecordCmdOption(bool enable);
61     MOCKABLE bool SetRecordTgidOption(bool enable);
62     MOCKABLE bool SetBufferSizeKb(int sizeKb);
63     MOCKABLE bool SetTraceClock(const std::string& clock);
64     MOCKABLE std::string GetTraceClock();
65     MOCKABLE bool AppendSetEvent(const std::string& type, const std::string& name);
66     MOCKABLE bool ClearSetEvent();
67     MOCKABLE bool EnableEvent(const std::string& type, const std::string& name);
68     MOCKABLE bool DisableEvent(const std::string& type, const std::string& name);
69     MOCKABLE bool DisableCategories(const std::string& categories);
70     MOCKABLE bool EnableTracing();
71     MOCKABLE bool DisableTracing();
72 
73     // for UT
SetFtraceRoot(std::string path)74     void SetFtraceRoot(std::string path)
75     {
76         ftraceRoot_ = path;
77     }
78 
79 private:
80     FtraceFsOps();
81     MOCKABLE ~FtraceFsOps();
82     DISALLOW_COPY_AND_MOVE(FtraceFsOps);
83 
84 private:
85     std::string ftraceRoot_;
86 };
87 FTRACE_NS_END
88 
89 #endif // FTRACE_FS_OPS_H