• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Init()30 void EngineDumpManager::Init()
31 {
32     auto MemInfoDump = std::bind(&EngineDumpManager::DumpGlibMemInfo, this, std::placeholders::_1);
33     std::u16string keyMem = u"glibmem";
34     ServiceDumpManager::GetInstance().RegisterDfxDumper(keyMem, MemInfoDump);
35 
36     auto MemPoolInfoDump = std::bind(&EngineDumpManager::DumpGlibMemPoolInfo, this, std::placeholders::_1);
37     std::u16string keyPool = u"glibpool";
38     ServiceDumpManager::GetInstance().RegisterDfxDumper(keyPool, MemPoolInfoDump);
39 
40     std::string dumpString;
41     GetGMemDump(dumpString);
42 }
43 
DumpGlibMemInfo(int32_t fd)44 int32_t EngineDumpManager::DumpGlibMemInfo(int32_t fd)
45 {
46     std::string dumpString;
47     GetGMemDump(dumpString);
48     if (fd != -1) {
49         write(fd, dumpString.c_str(), dumpString.size());
50         dumpString.clear();
51     }
52     return MSERR_OK;
53 }
54 
DumpGlibMemPoolInfo(int32_t fd)55 int32_t EngineDumpManager::DumpGlibMemPoolInfo(int32_t fd)
56 {
57     std::string dumpString;
58     GetGMemPoolDump(dumpString);
59     if (fd != -1) {
60         write(fd, dumpString.c_str(), dumpString.size());
61         dumpString.clear();
62     }
63     return MSERR_OK;
64 }
65 } // namespace Media
66 } // namespace OHOS