• 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 #include "dump_catcher.h"
17 
18 #include "dfx_define.h"
19 #include "dfx_dump_catcher.h"
20 #include "dfx_log.h"
21 
22 namespace OHOS {
23 namespace HiviewDFX {
GetInstance()24 DumpCatcher &DumpCatcher::GetInstance()
25 {
26     static DumpCatcher ins;
27     return ins;
28 }
29 
Dump(int32_t pid,int32_t tid,int timeout) const30 void DumpCatcher::Dump(int32_t pid, int32_t tid, int timeout) const
31 {
32     DfxDumpCatcher dfxDump;
33     std::string msg = "";
34     auto dumpResult = dfxDump.DumpCatchWithTimeout(pid, msg, timeout, tid);
35     if (dumpResult.first == -1) {
36         printf("Result:dump failed.\n");
37     } else if (dumpResult.first == 0) {
38         printf("Result:dump normal stack success.\n");
39     } else if (dumpResult.first == 1) {
40         printf("Result:dump kernel stack success.\n");
41     }
42     printf("%s", dumpResult.second.c_str());
43     printf("%s\n", msg.c_str());
44 }
45 } // namespace HiviewDFX
46 } // namespace OHOS
47