176fd607bSopenharmony_ci/*
276fd607bSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
376fd607bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
476fd607bSopenharmony_ci * you may not use this file except in compliance with the License.
576fd607bSopenharmony_ci * You may obtain a copy of the License at
676fd607bSopenharmony_ci *
776fd607bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
876fd607bSopenharmony_ci *
976fd607bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1076fd607bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1176fd607bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1276fd607bSopenharmony_ci * See the License for the specific language governing permissions and
1376fd607bSopenharmony_ci * limitations under the License.
1476fd607bSopenharmony_ci */
1576fd607bSopenharmony_ci
1676fd607bSopenharmony_ci#ifndef OHOS_MEDIA_LIBRARY_TRACER
1776fd607bSopenharmony_ci#define OHOS_MEDIA_LIBRARY_TRACER
1876fd607bSopenharmony_ci
1976fd607bSopenharmony_ci#include <string.h>
2076fd607bSopenharmony_ci
2176fd607bSopenharmony_ci#include "hitrace_meter.h"
2276fd607bSopenharmony_ci
2376fd607bSopenharmony_ci#define COMPILE_HIDDEN __attribute__ ((visibility ("hidden")))
2476fd607bSopenharmony_ciclass MediaLibraryTracer final {
2576fd607bSopenharmony_cipublic:
2676fd607bSopenharmony_ci    MediaLibraryTracer() = default;
2776fd607bSopenharmony_ci
2876fd607bSopenharmony_ci    virtual ~MediaLibraryTracer()
2976fd607bSopenharmony_ci    {
3076fd607bSopenharmony_ci        for (int32_t i = 0; i < count_; i++) {
3176fd607bSopenharmony_ci            FinishTrace(HITRACE_TAG_ZMEDIA);
3276fd607bSopenharmony_ci        }
3376fd607bSopenharmony_ci
3476fd607bSopenharmony_ci        count_ = 0;
3576fd607bSopenharmony_ci    }
3676fd607bSopenharmony_ci
3776fd607bSopenharmony_ci    void Start(const std::string &label)
3876fd607bSopenharmony_ci    {
3976fd607bSopenharmony_ci        StartTrace(HITRACE_TAG_ZMEDIA, label);
4076fd607bSopenharmony_ci        count_++;
4176fd607bSopenharmony_ci    }
4276fd607bSopenharmony_ci
4376fd607bSopenharmony_ci    void Finish()
4476fd607bSopenharmony_ci    {
4576fd607bSopenharmony_ci        FinishTrace(HITRACE_TAG_ZMEDIA);
4676fd607bSopenharmony_ci        count_--;
4776fd607bSopenharmony_ci    }
4876fd607bSopenharmony_ci
4976fd607bSopenharmony_ciprivate:
5076fd607bSopenharmony_ci    COMPILE_HIDDEN int32_t count_ = 0;
5176fd607bSopenharmony_ci};
5276fd607bSopenharmony_ci
5376fd607bSopenharmony_ci#endif // OHOS_MEDIA_LIBRARY_TRACER
54