xref: /base/update/updater/services/log/dump.cpp (revision fb299fa2)
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 "log/dump.h"
17#include <chrono>
18#include <memory>
19#include <unordered_map>
20#include <vector>
21#include "log/log.h"
22#include "securec.h"
23
24namespace Updater {
25thread_local std::stack<std::string> g_stageStack;
26
27extern "C" __attribute__((constructor)) void RegisterDump(void)
28{
29    Dump::GetInstance().RegisterDump("DumpHelperLog", std::make_unique<DumpHelperLog>());
30}
31
32DumpStageHelper::DumpStageHelper(const std::string &stage)
33{
34    g_stageStack.push(stage);
35}
36
37DumpStageHelper::~DumpStageHelper()
38{
39    if (!g_stageStack.empty()) {
40        g_stageStack.pop();
41    }
42}
43
44std::stack<std::string> &DumpStageHelper::GetDumpStack()
45{
46    return g_stageStack;
47}
48Dump &Dump::GetInstance()
49{
50    static Dump dump;
51    return dump;
52}
53
54Dump::~Dump()
55{
56}
57} // Updater
58