1e9297d28Sopenharmony_ci/*
2e9297d28Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3e9297d28Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e9297d28Sopenharmony_ci * you may not use this file except in compliance with the License.
5e9297d28Sopenharmony_ci * You may obtain a copy of the License at
6e9297d28Sopenharmony_ci *
7e9297d28Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e9297d28Sopenharmony_ci *
9e9297d28Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e9297d28Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e9297d28Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e9297d28Sopenharmony_ci * See the License for the specific language governing permissions and
13e9297d28Sopenharmony_ci * limitations under the License.
14e9297d28Sopenharmony_ci */
15e9297d28Sopenharmony_ci
16e9297d28Sopenharmony_ci#include "scoped_bytrace.h"
17e9297d28Sopenharmony_ci
18e9297d28Sopenharmony_ci#include <hitrace_meter.h>
19e9297d28Sopenharmony_ci#include <hilog/log.h>
20e9297d28Sopenharmony_ci#include "parameters.h"
21e9297d28Sopenharmony_ci
22e9297d28Sopenharmony_ciScopedBytrace::ScopedBytrace(const std::string &proc) : proc_(proc)
23e9297d28Sopenharmony_ci{
24e9297d28Sopenharmony_ci    StartTrace(HITRACE_TAG_GRAPHIC_AGP, proc_);
25e9297d28Sopenharmony_ci    isEnd = false;
26e9297d28Sopenharmony_ci}
27e9297d28Sopenharmony_ci
28e9297d28Sopenharmony_ciScopedBytrace::~ScopedBytrace()
29e9297d28Sopenharmony_ci{
30e9297d28Sopenharmony_ci    if (isEnd == false) {
31e9297d28Sopenharmony_ci        FinishTrace(HITRACE_TAG_GRAPHIC_AGP);
32e9297d28Sopenharmony_ci    }
33e9297d28Sopenharmony_ci}
34e9297d28Sopenharmony_ci
35e9297d28Sopenharmony_civoid ScopedBytrace::End()
36e9297d28Sopenharmony_ci{
37e9297d28Sopenharmony_ci    if (isEnd == false) {
38e9297d28Sopenharmony_ci        FinishTrace(HITRACE_TAG_GRAPHIC_AGP);
39e9297d28Sopenharmony_ci    }
40e9297d28Sopenharmony_ci}
41e9297d28Sopenharmony_ci
42e9297d28Sopenharmony_cibool ScopedDebugTrace::debugTraceEnabled_ =
43e9297d28Sopenharmony_ci        std::atoi((OHOS::system::GetParameter("persist.sys.graphic.openDebugTrace", "0")).c_str()) != 0;
44e9297d28Sopenharmony_ciScopedDebugTrace::ScopedDebugTrace(const std::string &traceStr)
45e9297d28Sopenharmony_ci{
46e9297d28Sopenharmony_ci    if (debugTraceEnabled_) {
47e9297d28Sopenharmony_ci        StartTrace(HITRACE_TAG_GRAPHIC_AGP, traceStr);
48e9297d28Sopenharmony_ci    }
49e9297d28Sopenharmony_ci}
50e9297d28Sopenharmony_ciScopedDebugTrace::~ScopedDebugTrace()
51e9297d28Sopenharmony_ci{
52e9297d28Sopenharmony_ci    if (debugTraceEnabled_) {
53e9297d28Sopenharmony_ci        FinishTrace(HITRACE_TAG_GRAPHIC_AGP);
54e9297d28Sopenharmony_ci    }
55e9297d28Sopenharmony_ci}
56