1/*
2 * Copyright (C) 2023 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#ifndef OHOS_USER_ACCESS_TRACER
17#define OHOS_USER_ACCESS_TRACER
18
19#include <string.h>
20#include "hitrace_meter.h"
21
22class UserAccessTracer final {
23public:
24    UserAccessTracer() = default;
25
26    virtual ~UserAccessTracer()
27    {
28        for (int32_t i = 0; i < count_; i++) {
29            FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
30        }
31        count_ = 0;
32    }
33
34    void Start(const std::string &label)
35    {
36        StartTrace(HITRACE_TAG_FILEMANAGEMENT, label);
37        count_++;
38    }
39
40    void Finish()
41    {
42        FinishTrace(HITRACE_TAG_FILEMANAGEMENT);
43        count_--;
44    }
45private:
46    int32_t count_ = 0;
47};
48
49#endif // OHOS_USER_ACCESS_TRACER
50