• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 DFX_BUFFER_WRITER_H
17 #define DFX_BUFFER_WRITER_H
18 
19 #include <cinttypes>
20 #include <condition_variable>
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include "dfx_buffer_writer.h"
25 #include "nocopyable.h"
26 #include "smart_fd.h"
27 
28 namespace OHOS {
29 namespace HiviewDFX {
30 
31 typedef int (*BufferWriteFunc) (int32_t fd, const char *buf, const size_t len);
32 
33 class DfxBufferWriter final {
34 public:
35     static DfxBufferWriter &GetInstance();
36     ~DfxBufferWriter() = default;
37     void Finish();
38 
39     void SetWriteBufFd(SmartFd fd);
40     void SetWriteResFd(SmartFd fd);
41     void SetWriteFunc(BufferWriteFunc func);
42     bool WriteDumpRes(int32_t dumpRes);
43 
44     void WriteMsg(const std::string& msg);
45     void WriteFormatMsg(const char *format, ...);
46 
47     void AppendBriefDumpInfo(const std::string& info);
48     void PrintBriefDumpInfo();
49 private:
50     static int DefaultWrite(int32_t fd, const char *buf, const size_t len);
51 
52     DfxBufferWriter() = default;
53     DISALLOW_COPY_AND_MOVE(DfxBufferWriter);
54 
55     BufferWriteFunc writeFunc_ = nullptr;
56     SmartFd bufFd_;
57     SmartFd resFd_;
58     std::string briefDumpInfo_;
59 };
60 } // namespace HiviewDFX
61 } // namespace OHOS
62 
63 #endif  // DFX_PROCESSDUMP_H
64