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