• 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 
16 #ifndef HIPERF_PERF_PIPE
17 #define HIPERF_PERF_PIPE
18 
19 #include <fstream>
20 #include <stdint.h>
21 #include "utilities.h"
22 #include "perf_events.h"
23 
24 namespace OHOS {
25 namespace Developtools {
26 namespace HiPerf {
27 enum class CommandType {
28     RECORD = 0,
29     STAT,
30 };
31 const std::string CONTROL_CMD_PREPARE = "prepare";
32 const std::string CONTROL_CMD_START = "start";
33 const std::string CONTROL_CMD_PAUSE = "pause";
34 const std::string CONTROL_CMD_RESUME = "resume";
35 const std::string CONTROL_CMD_OUTPUT = "output";
36 const std::string CONTROL_CMD_STOP = "stop";
37 class PerfPipe {
38 private:
39     std::string fifoFileC2S_;
40     std::string fifoFileS2C_;
41     std::string controlCmd_;
42     std::string perfCmd_;
43     bool outputEnd_ = false;
44 
45 public:
46     void SetFifoFileName(const CommandType& commandType, std::string& controlCmd,
47         std::string& fifoFileC2S, std::string& fifoFileS2C);
48     void RemoveFifoFile();
49     bool CreateFifoFile();
50     bool SendFifoAndWaitReply(const std::string &cmd, const std::chrono::milliseconds &timeOut);
51     bool WaitFifoReply(const int fd, const std::chrono::milliseconds &timeOut);
52     void WaitFifoReply(const int fd, const std::chrono::milliseconds &timeOut, std::string& reply);
53     void ProcessStopCommand(const bool ret);
54     void ProcessOutputCommand(bool ret);
55     bool ProcessControlCmd();
56     void SetOutPutEnd(const bool outputEnd);
57 };
58 } // namespace HiPerf
59 } // namespace Developtools
60 } // namespace OHOS
61 #endif // HIPERF_PERF_PIPE
62