From 41f969199051922a9477394c585345f197a33828 Mon Sep 17 00:00:00 2001 From: wenlong12 Date: Thu, 28 Jul 2022 11:01:52 +0800 Subject: [PATCH] add napi mock for hitrace Signed-off-by:wenlong12 Signed-off-by: wenlong12 --- .../main/extend/systemplugin/napi/index.js | 3 ++ .../systemplugin/napi/ohos_hiTraceMeter.js | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 runtime/main/extend/systemplugin/napi/ohos_hiTraceMeter.js diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 0c08df7e..aecc8f7a 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -64,6 +64,7 @@ import { mockHiAppEvent } from './ohos_hiAppEvent' import { mockHilog } from './ohos_hilog' import { mockHiSysEvent } from './ohos_hiSysEvent' import { mockHiTraceChain } from './ohos_hiTraceChain' +import { mockHiTraceMeter } from './ohos_hiTraceMeter' import { mockFaultLogger } from './ohos_faultLogger' import { mockTv } from './tv' import { mockDtv } from './dtv' @@ -392,6 +393,8 @@ export function mockRequireNapiFun() { return mockHiSysEvent(); case "hiTraceChain": return mockHiTraceChain(); + case "hiTraceMeter": + return mockHiTraceMeter(); case "faultLogger": return mockFaultLogger(); case "tv": diff --git a/runtime/main/extend/systemplugin/napi/ohos_hiTraceMeter.js b/runtime/main/extend/systemplugin/napi/ohos_hiTraceMeter.js new file mode 100644 index 00000000..715acafa --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/ohos_hiTraceMeter.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 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. + */ + +export function mockHiTraceMeter() { + const hitrace = { + startTrace: function (...args) { + console.warn("HiTraceMeter.startTrace interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + finishTrace: function (...args) { + console.warn("HiTraceMeter.finishTrace interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + traceByValue: function (...args) { + console.warn("HiTraceMeter.traceByValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + }, + } + return hitrace; +}