• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 FAULT_LOGGER_PIPE_H
17 #define FAULT_LOGGER_PIPE_H
18 
19 #include <cstdint>
20 #include <list>
21 
22 #include "dfx_socket_request.h"
23 #include "smart_fd.h"
24 
25 namespace OHOS {
26 namespace HiviewDFX {
27 class FaultLoggerPipe {
28 public:
29     FaultLoggerPipe();
30     ~FaultLoggerPipe() = default;
31     FaultLoggerPipe(const FaultLoggerPipe&) = delete;
32     FaultLoggerPipe& operator=(const FaultLoggerPipe&) = delete;
33     FaultLoggerPipe(FaultLoggerPipe&& rhs) noexcept = default;
34     FaultLoggerPipe& operator=(FaultLoggerPipe&& rhs) noexcept = default;
35     int GetReadFd() const;
36     int GetWriteFd();
37 private:
38     bool write_{false};
39     SmartFd readFd_;
40     SmartFd writeFd_;
41 };
42 
43 enum class PipeFdUsage {
44     BUFFER_FD = 0,
45     RESULT_FD = 1,
46 };
47 
48 class FaultLoggerPipePair {
49 public:
50     int32_t GetPipeFd(PipeFdUsage usage, FaultLoggerPipeType pipeType);
51     FaultLoggerPipePair(int32_t pid, uint64_t requestTime);
52     FaultLoggerPipePair(FaultLoggerPipePair&&) noexcept = default;
53     FaultLoggerPipePair& operator=(FaultLoggerPipePair&&) noexcept = default;
54 
55     static FaultLoggerPipePair& CreateSdkDumpPipePair(int pid, uint64_t requestTime);
56     static bool CheckSdkDumpRecord(int pid, uint64_t checkTime);
57     static FaultLoggerPipePair* GetSdkDumpPipePair(int pid);
58     static void DelSdkDumpPipePair(int pid);
59 private:
60     FaultLoggerPipePair(const FaultLoggerPipePair&) = delete;
61     FaultLoggerPipePair& operator=(const FaultLoggerPipePair&) = delete;
62     bool IsValid(uint64_t checkTime) const;
63     int32_t pid_;
64     uint64_t requestTime_;
65     FaultLoggerPipe faultLoggerPipeBuf_;
66     FaultLoggerPipe faultLoggerPipeRes_;
67     static std::list<FaultLoggerPipePair> sdkDumpPipes_;
68 };
69 
70 class LitePerfPipePair {
71 public:
72     int32_t GetPipeFd(PipeFdUsage usage, FaultLoggerPipeType pipeType);
73     explicit LitePerfPipePair(int32_t uid);
74     LitePerfPipePair(LitePerfPipePair&&) noexcept = default;
75     LitePerfPipePair& operator=(LitePerfPipePair&&) noexcept = default;
76 
77     static LitePerfPipePair& CreatePipePair(int uid);
78     static bool CheckDumpRecord(int uid);
79     static bool CheckDumpMax();
80     static LitePerfPipePair* GetPipePair(int uid);
81     static void DelPipePair(int uid);
82 private:
83     LitePerfPipePair(const LitePerfPipePair&) = delete;
84     LitePerfPipePair& operator=(const LitePerfPipePair&) = delete;
85     int32_t uid_;
86     FaultLoggerPipe faultLoggerPipeBuf_;
87     FaultLoggerPipe faultLoggerPipeRes_;
88     static std::list<LitePerfPipePair> pipes_;
89 };
90 } // namespace HiviewDFX
91 } // namespace OHOS
92 #endif // FAULT_LOGGER_PIPE_H
93