1 /*
2 * Copyright (C) 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 #include "engine_dump_manager.h"
17 #include <unistd.h>
18 #include "service_dump_manager.h"
19 #include "gmemdfxdump.h"
20 #include "media_errors.h"
21
22 namespace OHOS {
23 namespace Media {
GetInstance()24 EngineDumpManager &EngineDumpManager::GetInstance()
25 {
26 static EngineDumpManager EngineDumpManager;
27 return EngineDumpManager;
28 }
29
~EngineDumpManager()30 EngineDumpManager::~EngineDumpManager()
31 {
32 ServiceDumpManager::GetInstance().UnregisterDfxDumper();
33 }
34
Init()35 void EngineDumpManager::Init()
36 {
37 auto MemInfoDump = std::bind(&EngineDumpManager::DumpGlibMemInfo, this, std::placeholders::_1);
38 std::u16string keyMem = u"glibmem";
39 ServiceDumpManager::GetInstance().RegisterDfxDumper(keyMem, MemInfoDump);
40
41 auto MemPoolInfoDump = std::bind(&EngineDumpManager::DumpGlibMemPoolInfo, this, std::placeholders::_1);
42 std::u16string keyPool = u"glibpool";
43 ServiceDumpManager::GetInstance().RegisterDfxDumper(keyPool, MemPoolInfoDump);
44
45 std::string dumpString;
46 GetGMemDump(dumpString);
47 }
48
DumpGlibMemInfo(int32_t fd)49 int32_t EngineDumpManager::DumpGlibMemInfo(int32_t fd)
50 {
51 std::string dumpString;
52 GetGMemDump(dumpString);
53 if (fd != -1) {
54 write(fd, dumpString.c_str(), dumpString.size());
55 dumpString.clear();
56 }
57 return MSERR_OK;
58 }
59
DumpGlibMemPoolInfo(int32_t fd)60 int32_t EngineDumpManager::DumpGlibMemPoolInfo(int32_t fd)
61 {
62 std::string dumpString;
63 GetGMemPoolDump(dumpString);
64 if (fd != -1) {
65 write(fd, dumpString.c_str(), dumpString.size());
66 dumpString.clear();
67 }
68 return MSERR_OK;
69 }
70 } // namespace Media
71 } // namespace OHOS