• 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 HITRACE_DUMP_PIPE_H
17 #define HITRACE_DUMP_PIPE_H
18 
19 #include <unique_fd.h>
20 
21 #include "hitrace_define.h"
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 namespace Hitrace {
26 class HitraceDumpPipe {
27 public:
28     HitraceDumpPipe() = delete;
29     explicit HitraceDumpPipe(bool isParent);
30     ~HitraceDumpPipe() = default;
31 
32     static bool InitTraceDumpPipe();
33     static void ClearTraceDumpPipe();
34 
35     // parent side
36     bool SubmitTraceDumpTask(const TraceDumpTask& task);
37     bool ReadSyncDumpRet(const int timeout, TraceDumpTask& task);
38     bool ReadAsyncDumpRet(const int timeout, TraceDumpTask& task);
39 
40     // child side
41     bool ReadTraceTask(const int timeoutMs, TraceDumpTask& task);
42     bool WriteSyncReturn(const TraceDumpTask& task);
43     bool WriteAsyncReturn(const TraceDumpTask& task);
44 
45 private:
46     bool CheckProcessRole(bool shouldBeParent, const char* operation) const;
47     bool CheckFdValidity(const int fd, const char* operation, const char* pipeName) const;
48     bool WriteToPipe(const int fd, const TraceDumpTask& task, const char* operation);
49     bool ReadFromPipe(const int fd, TraceDumpTask& task, const int timeoutMs, const char* operation);
50 
51     bool isParent_ = false;
52     UniqueFd taskSubmitFd_;
53     UniqueFd syncRetFd_;
54     UniqueFd asyncRetFd_;
55 };
56 } // namespace Hitrace
57 } // namespace HiviewDFX
58 } // namespace OHOS
59 #endif