Hector Dearman | 0d30033 | 2017-11-22 11:05:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef FTRACE_READER_FTRACE_PROCFS_H_ |
| 18 | #define FTRACE_READER_FTRACE_PROCFS_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | #include "base/scoped_file.h" |
| 23 | |
| 24 | namespace perfetto { |
| 25 | |
| 26 | class FtraceProcfs { |
| 27 | public: |
| 28 | FtraceProcfs(const std::string& root); |
| 29 | virtual ~FtraceProcfs(); |
| 30 | |
| 31 | // Enable the event under with the given |group| and |name|. |
| 32 | bool EnableEvent(const std::string& group, const std::string& name); |
| 33 | |
| 34 | // Disable the event under with the given |group| and |name|. |
| 35 | bool DisableEvent(const std::string& group, const std::string& name); |
| 36 | |
Hector Dearman | 8d8ccd3 | 2017-11-27 16:06:34 +0000 | [diff] [blame] | 37 | // Read the format for event with the given |group| and |name|. |
| 38 | std::string ReadEventFormat(const std::string& group, |
| 39 | const std::string& name) const; |
| 40 | |
| 41 | // Read the available_events file. |
| 42 | std::string ReadAvailableEvents() const; |
| 43 | |
Hector Dearman | 0d30033 | 2017-11-22 11:05:34 +0000 | [diff] [blame] | 44 | // Returns the number of CPUs. |
| 45 | // This will match the number of tracing/per_cpu/cpuXX directories. |
| 46 | size_t virtual NumberOfCpus() const; |
| 47 | |
| 48 | // Clears the trace buffers for all CPUs. Blocks until this is done. |
| 49 | void ClearTrace(); |
| 50 | |
| 51 | // Writes the string |str| as an event into the trace buffer. |
| 52 | bool WriteTraceMarker(const std::string& str); |
| 53 | |
| 54 | // Enable tracing. |
| 55 | bool EnableTracing(); |
| 56 | |
| 57 | // Disables tracing, does not clear the buffer. |
| 58 | bool DisableTracing(); |
| 59 | |
| 60 | // Returns true iff tracing is enabled. |
| 61 | // Necessarily racy: another program could enable/disable tracing at any |
| 62 | // point. |
| 63 | bool IsTracingEnabled(); |
| 64 | |
| 65 | virtual base::ScopedFile OpenPipeForCpu(size_t cpu); |
| 66 | virtual bool WriteToFile(const std::string& path, const std::string& str); |
| 67 | |
| 68 | private: |
| 69 | const std::string root_; |
| 70 | }; |
| 71 | |
| 72 | } // namespace perfetto |
| 73 | |
| 74 | #endif // FTRACE_READER_FTRACE_PROCFS_H_ |