1 /*
2 * Copyright (C) 2024 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 #include "ffrt_catcher.h"
16
17 #include "file_util.h"
18 #include "log_catcher_utils.h"
19
20 namespace OHOS {
21 namespace HiviewDFX {
FfrtCatcher()22 FfrtCatcher::FfrtCatcher() : EventLogCatcher()
23 {
24 name_ = "FfrtCatcher";
25 }
26
Initialize(const std::string& strParam1, int intParam1, int intParam2)27 bool FfrtCatcher::Initialize(const std::string& strParam1, int intParam1, int intParam2)
28 {
29 // this catcher do not need parameters, just return true
30 description_ = "FfrtCatcher --\n";
31 pid_ = intParam1;
32 return true;
33 };
34
Catch(int fd, int jsonFd)35 int FfrtCatcher::Catch(int fd, int jsonFd)
36 {
37 int originSize = GetFdSize(fd);
38 FileUtil::SaveStringToFd(fd, "ffrt fump pid=" + std::to_string(pid_) + ":\n");
39 LogCatcherUtils::DumpStackFfrt(fd, std::to_string(pid_));
40
41 logSize_ = GetFdSize(fd) - originSize;
42 if (logSize_ <= 0) {
43 FileUtil::SaveStringToFd(fd, "ffrt dump content is empty!");
44 }
45
46 return logSize_;
47 };
48 } // namespace HiviewDFX
49 } // namespace OHOS