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