* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ES2PANDA_UTIL_PERF_METRICS_H
#define ES2PANDA_UTIL_PERF_METRICS_H
#include "libarkbase/macros.h"
namespace ark::es2panda::util {
#define ES2PANDA_PERF_CONCAT2_(a, b) a##b
#define ES2PANDA_PERF_CONCAT2(a, b) ES2PANDA_PERF_CONCAT2_(a, b)
#define ES2PANDA_PERF_SCOPE(name) \
thread_local auto ES2PANDA_PERF_CONCAT2(e2pPerfRecord, __LINE__) = \
ark::es2panda::util::RegisterPerfMetricRecord(name); \
ark::es2panda::util::PerfMetricScope ES2PANDA_PERF_CONCAT2(e2pPerfScope, __LINE__)( \
ES2PANDA_PERF_CONCAT2(e2pPerfRecord, __LINE__))
#define ES2PANDA_PERF_FN_SCOPE() ES2PANDA_PERF_SCOPE(__PRETTY_FUNCTION__)
#define ES2PANDA_PERF_EVENT_SCOPE(name) \
ark::es2panda::util::PerfMetricScope e2pPerfScope(ark::es2panda::util::RegisterPerfMetricRecord(name))
void DumpPerfMetrics();
class PerfMetricRecord;
PerfMetricRecord *RegisterPerfMetricRecord(std::string_view name);
class PerfMetricScope {
public:
explicit PerfMetricScope(PerfMetricRecord *record);
~PerfMetricScope();
NO_COPY_SEMANTIC(PerfMetricScope);
NO_MOVE_SEMANTIC(PerfMetricScope);
private:
PerfMetricRecord *record_;
};
}
#endif