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 #include "dump_catcher.h"
17
18 #include <iostream>
19 #include "dfx_define.h"
20 #include "dfx_dump_catcher.h"
21 #include "dfx_log.h"
22
23 namespace OHOS {
24 namespace HiviewDFX {
GetInstance()25 DumpCatcher &DumpCatcher::GetInstance()
26 {
27 static DumpCatcher ins;
28 return ins;
29 }
30
Dump(int32_t type,int32_t pid,int32_t tid) const31 void DumpCatcher::Dump(int32_t type, int32_t pid, int32_t tid) const
32 {
33 DfxDumpCatcher dfxDump;
34 std::string msg = "";
35 bool dumpRet = false;
36 switch (type) {
37 case DUMP_TYPE_NATIVE:
38 dumpRet = dfxDump.DumpCatch(pid, tid, msg);
39 break;
40 case DUMP_TYPE_MIX:
41 dumpRet = dfxDump.DumpCatchMix(pid, tid, msg);
42 break;
43 case DUMP_TYPE_KERNEL:
44 break;
45 default:
46 DFXLOG_WARN("type(%d) invalid, must %d(native), %d(mix), %d(kernel)", \
47 type, DUMP_TYPE_NATIVE, DUMP_TYPE_MIX, DUMP_TYPE_KERNEL);
48 break;
49 }
50
51 if (!dumpRet) {
52 std::cout << "Dump Failed." << std::endl;
53 }
54
55 if (!msg.empty()) {
56 std::cout << msg << std::endl;
57 } else {
58 std::cout << "Dump msg empty." << std::endl;
59 }
60 }
61 } // namespace HiviewDFX
62 } // namespace OHOS
63