diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/app.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e6d77a787cec31e2a468c2de811d7e6c3c1b6010 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.example.hitracechain_arkts_sample_a", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c345ca427849bf40806cea223c7c849a232e485c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "HitraceChain_ArkTS_Sample_A" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/README_zh.md b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..5cce5a9ef3d727ddddc10c2f6fe6051856cfded5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/README_zh.md @@ -0,0 +1,97 @@ +# HiTraceChain ArkTS接口使用样例 + +### 介绍 + +本示例主要展示了使用HiTraceChain提供分布式跟踪接口。 + +HiTraceChain是基于云计算分布式跟踪调用链思想,在端侧业务流程(涉及跨线程、跨进程、跨设备)中的一种轻量级实现。hiTraceChain在业务控制面流程中,生成和传递唯一跟踪标识,在业务流程中输出的各类信息中(包括应用事件、系统时间、日志等)记录该跟踪标识。在调试、问题定位过程中,开发者可以通过该唯一跟踪标识将本次业务流程端到端的各类信息快速关联起来。 + +本样例介绍在async/await和promise/then异步任务中使用HiTraceChain。 + +该工程中的展示的代码详细描述可查如下链接: + +- [使用HiTraceChain打点(ArkTS)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hitracechain-guidelines-arkts.md) + +### 效果预览 + +| 主页 | +| :----------------------------------------------------------------------------------: | +| `z` | + +#### 使用说明 + +1. 在DevEco Studio Terminal 中执行如下命令: + +``` +$ hitrace -t 10 app | grep onClick +``` + +2. 点击设备上的“clickTime=0”按钮(需在10秒内完成,否则步骤3捕获不到trace数据),触发业务逻辑。 使用关键字“testTag”过滤日志,查看该业务代码打印的hilog日志。 + +``` +06-04 17:46:45.156 55451-55451 C02D33/com.exa...tion/HiTraceC com.examp...lication I [a92ab116052648e 0 0]HiTraceBegin name:testTag: hiTraceChain begin flags:0x01. +06-04 17:46:45.157 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I [a92ab116052648e 0 0]promise task +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I [a92ab116052648e 0 0]test1_1 +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I [a92ab116052648e 0 0]test2 +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I hiTraceChain end in main thread +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I [a92ab116052648e 3457eff 0]test1_2 +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I [a92ab116052648e 3457eff 0]test3 +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication E [a92ab116052648e 1bb5a1b 35d9c46]Random number is too small +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I hiTraceChain end in promise/then +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I [a92ab116052648e 2ddfb70 3457eff]test1_3 +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I [a92ab116052648e 225a1d9 2ddfb70]then task +06-04 17:46:45.158 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I hiTraceChain end in async/await +06-04 17:46:45.163 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I [a92ab116052648e 3a75cb2 520a92]Succeeded in writing an app event +06-04 17:46:45.163 55451-55451 A00000/com.exa...ation/testTag com.examp...lication I hiTraceChain end in hiAppEvent +``` + +3. 在DevEco Studio Terminal窗口查看trace数据,HiTraceChain跟踪开启期间,HiTraceMeter打点得到的trace日志会自动携带HiTraceId信息。 + +``` + e.myapplication-55451 ( 55451) [010] .... 27164.174417: tracing_mark_write: B|55451|H:[a92ab116052648e,0,0]#onClick|M62|clickTime=1 +``` + +### 工程目录 + +``` +└── entry + └── src + └── main + └── ets + ├── entryability + │ └── EntryAbility.ets + ├── entrybackupability + │ └── EntryBackupAbility.ets + └── pages + └── Index.ets //主页 +``` + +### 具体实现 + +1. ArkTS项目可以在"@kit.PerformanceAnalysisKit"中导入对应模块即可在各种场景下调用对应函数,如在index.ets中直接调用,或者在EntryAbility.ets函数中在应用的各个生命周期内添加功能函数以实现应用自动在“启动”或“结束”时进行性能分析。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机; +2. 本示例已适配API20版本SDK,版本号:6.0.0.47; +3. 本示例需要使用DevEco Studio(6.0.0.858)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/ > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f9f311acef30dae790bd712ea67cad948ca1d509 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/build-profile.json5 @@ -0,0 +1,52 @@ +/* + * 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "6.0.0(20)", + "compileSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1d2fc52afb11467a138506d8509a3ca2c123707e --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/obfuscation-rules.txt b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/entryability/EntryAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a95f638674014a6d6088fb8a25f00854a309e53 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * 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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fca37ecc34e1079aaf6557f1272cd694aa0068c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/pages/Index.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..60e39884a50ba52aa6a582136859acb4843b2339 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,132 @@ +/* + * 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. + */ + +// [Start hitracechain_arkts_sample_code_a] +import { BusinessError } from '@kit.BasicServicesKit'; +import { hiAppEvent, hilog, hiTraceChain, hiTraceMeter } from '@kit.PerformanceAnalysisKit'; + +async function test3() { + hilog.info(0x0000, 'testTag', 'test3'); +} + +async function test2() { + hilog.info(0x0000, 'testTag', 'test2'); +} + +async function test1() { + hilog.info(0x0000, 'testTag', 'test1_1'); + await test2(); + hilog.info(0x0000, 'testTag', 'test1_2'); + await test3(); + hilog.info(0x0000, 'testTag', 'test1_3'); +} + +@Entry +@Component +struct Index { + @State message: string = 'clickTime=0'; + @State clickTime: number = 0; + + build() { + Row() { + Column() { + Button(this.message) + .fontSize(20) + .margin(5) + .width(350) + .height(60) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.clickTime++; + this.message = 'clickTime=' + this.clickTime; + // 业务开始前,开启分布式跟踪 + // INCLUDE_ASYNC表示会在系统支持的异步机制里自动传递HiTraceId + let traceId = hiTraceChain.begin('testTag: hiTraceChain begin', hiTraceChain.HiTraceFlag.INCLUDE_ASYNC); + // 开始HiTraceMeter同步打点,该接口API version 19开始支持 + hiTraceMeter.startSyncTrace(hiTraceMeter.HiTraceOutputLevel.COMMERCIAL, 'onClick', this.message); + + // 在按钮点击函数中进行事件打点,以记录按钮点击事件 + let eventParams: Record = { 'click_time': 100 }; + let eventInfo: hiAppEvent.AppEventInfo = { + // 事件领域定义 + domain: 'button', + // 事件名称定义 + name: 'click', + // 事件类型定义 + eventType: hiAppEvent.EventType.BEHAVIOR, + // 事件参数定义 + params: eventParams + }; + hiAppEvent.write(eventInfo).then(() => { + hilog.info(0x0000, 'testTag', 'Succeeded in writing an app event'); + // 按钮点击事件处理结束,关闭异步处理分支的分布式跟踪 + hiTraceChain.end(traceId); + hilog.info(0x0000, 'testTag', 'hiTraceChain end in hiAppEvent'); + }).catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', `HiAppEvent err.code: ${err.code}, err.message: ${err.message}`); + // 异常处理结束,关闭异步处理分支的分布式跟踪 + hiTraceChain.end(traceId); + hilog.info(0x0000, 'testTag', 'hiTraceChain end in hiAppEvent'); + }); + + // 创建Promise对象执行随机数生成任务,若随机数大于0.5,则正常返回结果,反之则返回异常信息 + const promise: Promise = new Promise((resolve: Function, reject: Function) => { + hilog.info(0x0000, 'testTag', 'promise task'); + const randomNumber: number = Math.random(); + if (randomNumber > 0.5) { + resolve(randomNumber); + } else { + reject(new Error('Random number is too small')); + } + }); + + // then方法的回调函数处理Promise对象的执行结果 + promise.then((result: number) => { + // 成功时执行 + hilog.info(0x0000, 'testTag', 'Random number is %{public}d', result); + // 回调函数处理结束,关闭异步处理分支的分布式跟踪 + hiTraceChain.end(traceId); + hilog.info(0x0000, 'testTag', 'hiTraceChain end in promise/then'); + }).catch((error: BusinessError) => { + // 失败时执行 + hilog.error(0x0000, 'testTag', error.message); + // 异常处理结束,关闭异步处理分支的分布式跟踪 + hiTraceChain.end(traceId); + hilog.info(0x0000, 'testTag', 'hiTraceChain end in promise/then'); + }); + + // 执行async/await异步任务 + let res = test1(); + // then方法的回调函数处理异步任务的执行结果 + res.then(() => { + hilog.info(0x0000, 'testTag', 'then task'); + // 功能同hiTraceChain.end,关闭异步处理分支的分布式跟踪 + hiTraceChain.clearId(); + hilog.info(0x0000, 'testTag', 'hiTraceChain end in async/await'); + }); + + // 结束HiTraceMeter同步打点,该接口API version 19开始支持 + hiTraceMeter.finishSyncTrace(hiTraceMeter.HiTraceOutputLevel.COMMERCIAL); + // 业务结束后,关闭分布式跟踪 + hiTraceChain.end(traceId); + hilog.info(0x0000, 'testTag', 'hiTraceChain end in main thread'); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End hitracechain_arkts_sample_code_a] \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/module.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d700a40c54cefb5c84bb352cf7a89b37acd0f342 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/float.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/startIcon.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/media/startIcon.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/profile/backup_config.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/profile/main_pages.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/dark/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/mock/mock-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/hvigor/hvigor-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0c92fdad58a7851692e144df9a4b1f4953ec26c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..34a126da756d306c9412997bcd7d57a34b6da0a2 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/ohosTest.md b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..519de1061cdf567c9a47035833c781802f105b5a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/ohosTest.md @@ -0,0 +1,8 @@ +# 性能分析工具测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ---------------------- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | +| 主页按钮点击 | 位于主页 | 按readme的使用说明操作 | 输出预期日志 | 否 | Pass | diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/screenshots/Snipaste_2025-10-17_15-32-47.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/screenshots/Snipaste_2025-10-17_15-32-47.png new file mode 100644 index 0000000000000000000000000000000000000000..e3b876436723f935c661f19112d9da240ba48f92 Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_A/screenshots/Snipaste_2025-10-17_15-32-47.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/app.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d9e4a4d5610ac58d3550859037fed2adf385b54b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.example.hitracechain_arkts_sample_b", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1e2207deffd02203c383104d0b61b50d6bcf9fd8 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "HitraceChain_ArkTS_Sample_B" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/README_zh.md b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..2f506eb5a34b46d902da851646235ee79c636512 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/README_zh.md @@ -0,0 +1,79 @@ +# HiTraceChain ArkTS接口使用样例 + +### 介绍 + +本示例主要展示了使用HiTraceChain提供分布式跟踪接口。 + +HiTraceChain是基于云计算分布式跟踪调用链思想,在端侧业务流程(涉及跨线程、跨进程、跨设备)中的一种轻量级实现。hiTraceChain在业务控制面流程中,生成和传递唯一跟踪标识,在业务流程中输出的各类信息中(包括应用事件、系统时间、日志等)记录该跟踪标识。在调试、问题定位过程中,开发者可以通过该唯一跟踪标识将本次业务流程端到端的各类信息快速关联起来。 + +本样例介绍在异步宏任务setInterval和setTimeout中使用HiTraceChain。 + +该工程中的展示的代码详细描述可查如下链接: + +- [使用HiTraceChain打点(ArkTS)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hitracechain-guidelines-arkts.md) + +### 效果预览 + +| 主页 | +| :----------------------------------------------------------------------------------: | +| `z` | + +#### 使用说明 + +1. 点击设备上的“clickTime=0”按钮触发业务逻辑。 使用关键字“testTag”过滤日志,查看该业务代码打印的hilog日志。 + +``` +06-05 15:46:04.544 49568-49568 A00000/com.exa...ation/testTag com.examp...lication I HiTraceId is invalid, begin hiTraceChain +06-05 15:46:04.544 49568-49568 C02D33/com.exa...tion/HiTraceC com.examp...lication I [a92ab34b3c84ea7 0 0]HiTraceBegin name:testTag: hiTraceChain begin flags:0x00. +06-05 15:46:04.544 49568-49568 A00000/com.exa...ation/testTag com.examp...lication I [a92ab34b3c84ea7 0 0]HiTraceFlag INCLUDE_ASYNC is enabled +06-05 15:46:04.544 49568-49568 A00000/com.exa...ation/testTag com.examp...lication I hiTraceChain end in main thread +06-05 15:46:05.547 49568-49568 A00000/com.exa...ation/testTag com.examp...lication I [a92ab34b3c84ea7 0 0]Interval 1s: randomNumber is 0.863610 +06-05 15:46:06.548 49568-49568 A00000/com.exa...ation/testTag com.examp...lication I [a92ab34b3c84ea7 0 0]Interval 1s: randomNumber is 0.365460 +06-05 15:46:07.047 49568-49568 A00000/com.exa...ation/testTag com.examp...lication I [a92ab34b3c84ea7 3cafdfd 0]setTimeout 2.5s +06-05 15:46:07.048 49568-49568 A00000/com.exa...ation/testTag com.examp...lication I [a92ab34b3c84ea7 dc842f 3cafdfd]Random number is 0.524236 +``` + +### 工程目录 + +``` +└── entry + └── src + └── main + └── ets + ├── entryability + │ └── EntryAbility.ets + ├── entrybackupability + │ └── EntryBackupAbility.ets + └── pages + └── Index.ets //主页 +``` + +### 具体实现 + +1. ArkTS项目可以在"@kit.PerformanceAnalysisKit"中导入对应模块即可在各种场景下调用对应函数,如在index.ets中直接调用,或者在EntryAbility.ets函数中在应用的各个生命周期内添加功能函数以实现应用自动在“启动”或“结束”时进行性能分析。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机; +2. 本示例已适配API20版本SDK,版本号:6.0.0.47; +3. 本示例需要使用DevEco Studio(6.0.0.858)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/ > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f9f311acef30dae790bd712ea67cad948ca1d509 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/build-profile.json5 @@ -0,0 +1,52 @@ +/* + * 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "6.0.0(20)", + "compileSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1d2fc52afb11467a138506d8509a3ca2c123707e --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/obfuscation-rules.txt b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/entryability/EntryAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a95f638674014a6d6088fb8a25f00854a309e53 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * 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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fca37ecc34e1079aaf6557f1272cd694aa0068c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/pages/Index.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ad2395a734de3378859ce5e335322bfa852d545 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,109 @@ +/* + * 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. + */ + +// [Start hitracechain_arkts_sample_code_b] +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog, hiTraceChain } from '@kit.PerformanceAnalysisKit'; + +@Entry +@Component +struct Index { + @State message: string = 'clickTime=0'; + @State clickTime: number = 0; + + build() { + Row() { + Column() { + Button(this.message) + .fontSize(20) + .margin(5) + .width(350) + .height(60) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.clickTime++; + this.message = 'clickTime=' + this.clickTime; + // 获取当前线程的HiTraceId + let traceId = hiTraceChain.getId(); + // 如果traceId无效,为当前线程开启分布式跟踪 + if (!hiTraceChain.isValid(traceId)) { + hilog.info(0x0000, 'testTag', 'HiTraceId is invalid, begin hiTraceChain'); + traceId = hiTraceChain.begin('testTag: hiTraceChain begin'); + // 使能traceId的INCLUDE_ASYNC,INCLUDE_ASYNC表示会在系统支持的异步机制里自动传递HiTraceId + hiTraceChain.enableFlag(traceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC); + // 将使能INCLUDE_ASYNC的HiTraceId设置到当前线程 + hiTraceChain.setId(traceId); + // 查询INCLUDE_ASYNC是否设置成功 + if (hiTraceChain.isFlagEnabled(hiTraceChain.getId(), hiTraceChain.HiTraceFlag.INCLUDE_ASYNC)) { + hilog.info(0x0000, 'testTag', 'HiTraceFlag INCLUDE_ASYNC is enabled'); + } + } + + const promise: Promise = new Promise((resolve: Function, reject: Function) => { + // 创建异步重复定时任务,每1s执行一次 + let intervalID = setInterval(() => { + // 为当前异步重复定时任务设置HiTraceId + hiTraceChain.setId(traceId); + const randomNumber: number = Math.random(); + hilog.info(0x0000, 'testTag', 'Interval 1s: randomNumber is %{public}d', randomNumber); + // 关闭当前异步重复定时任务的分布式跟踪 + hiTraceChain.end(traceId); + }, 1000) + + // 创建异步定时任务,2.5s后执行,结束异步重复定时任务 + setTimeout(() => { + // 为异步定时任务设置HiTraceId + hiTraceChain.setId(traceId); + // 为异步定时任务生成分支标识spanId + let traceIdTimeout = hiTraceChain.createSpan(); + // 为异步定时任务设置带spanId的HiTraceId + hiTraceChain.setId(traceIdTimeout); + hilog.info(0x0000, 'testTag', 'setTimeout 2.5s'); + // 结束异步重复定时任务 + clearInterval(intervalID); + const randomNumber: number = Math.random(); + if (randomNumber > 0.5) { + resolve(randomNumber); + } else { + reject(new Error('Random number is too small')); + } + // 关闭异步定时任务的分布式跟踪 + hiTraceChain.end(traceId); + }, 2500) + }) + + promise.then((result: number) => { + // 成功时执行 + hilog.info(0x0000, 'testTag', 'Random number is %{public}d', result); + // 回调函数处理结束,关闭异步处理分支的分布式跟踪 + hiTraceChain.end(traceId); + }).catch((error: BusinessError) => { + // 失败时执行 + hilog.error(0x0000, 'testTag', error.message); + // 异常处理结束,关闭异步处理分支的分布式跟踪 + hiTraceChain.end(traceId); + }); + + // 业务结束后,关闭分布式跟踪 + hiTraceChain.end(traceId); + hilog.info(0x0000, 'testTag', 'hiTraceChain end in main thread'); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End hitracechain_arkts_sample_code_b] \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/module.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d700a40c54cefb5c84bb352cf7a89b37acd0f342 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/float.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/startIcon.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/media/startIcon.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/profile/backup_config.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/profile/main_pages.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/dark/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/mock/mock-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/hvigor/hvigor-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0c92fdad58a7851692e144df9a4b1f4953ec26c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..34a126da756d306c9412997bcd7d57a34b6da0a2 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/ohosTest.md b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..519de1061cdf567c9a47035833c781802f105b5a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/ohosTest.md @@ -0,0 +1,8 @@ +# 性能分析工具测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ---------------------- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | +| 主页按钮点击 | 位于主页 | 按readme的使用说明操作 | 输出预期日志 | 否 | Pass | diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/screenshots/Snipaste_2025-10-17_15-32-47.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/screenshots/Snipaste_2025-10-17_15-32-47.png new file mode 100644 index 0000000000000000000000000000000000000000..e3b876436723f935c661f19112d9da240ba48f92 Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_ArkTS_Sample_B/screenshots/Snipaste_2025-10-17_15-32-47.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/app.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d0945138c17c2375662eda881dc45d43782d5120 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.example.hitracechain_ndk", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..95e578284748fa6f8d28ed50dfbfdd4e7b4ddea5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "HitraceChain_NDK" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/README_zh.md b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..0956a7c28fd2bda194cfc73ca22e3e509f2ac052 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/README_zh.md @@ -0,0 +1,86 @@ +# HiTraceChain NDK接口使用样例 + +### 介绍 + +本示例主要展示了使用HiTraceChain提供分布式跟踪接口。 + +HiTraceChain是基于云计算分布式跟踪调用链思想,在端侧业务流程(涉及跨线程、跨进程、跨设备)中的一种轻量级实现。hiTraceChain在业务控制面流程中,生成和传递唯一跟踪标识,在业务流程中输出的各类信息中(包括应用事件、系统时间、日志等)记录该跟踪标识。在调试、问题定位过程中,开发者可以通过该唯一跟踪标识将本次业务流程端到端的各类信息快速关联起来。 + +该工程中的展示的代码详细描述可查如下链接: + +- [使用HiTraceChain打点(C/C++)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hitracechain-guidelines-ndk.md) + +### 效果预览 + +| 主页 | +| :----------------------------------------------------------------------------------: | +| `z` | + +#### 使用说明 + +1. 点击设备上的“clickTime=0”按钮触发业务逻辑。 使用关键字“testTag”过滤日志,查看该业务代码打印的hilog日志。 + +``` +06-05 21:26:01.006 9944-9944 C02D33/com.exa...tion/HiTraceC com.examp...lication I [a92ab19ae90197d 0 0]HiTraceBegin name:testTag: hiTraceChain begin flags:0x00. +06-05 21:26:01.006 9944-9944 A00000/com.exa...ation/testTag com.examp...lication I [a92ab19ae90197d 0 0]HiTraceId is valid +06-05 21:26:01.006 9944-9944 A00000/com.exa...ation/testTag com.examp...lication I [a92ab19ae90197d 0 0]HITRACE_FLAG_INCLUDE_ASYNC is enabled +06-05 21:26:01.007 9944-9944 A00000/com.exa...ation/testTag com.examp...lication I Add, HiTraceChain end +06-05 21:26:01.007 9944-9944 A00000/com.exa...ation/testTag com.examp...lication I Test NAPI 2 + 3 = 5 +06-05 21:26:01.007 9944-13961 A00000/com.exa...ation/testTag com.examp...lication I [a92ab19ae90197d 2544fdb 0]Print1 +06-05 21:26:01.007 9944-13961 A00000/com.exa...ation/testTag com.examp...lication I Print1, HiTraceChain end +06-05 21:26:01.008 9944-13962 A00000/com.exa...ation/testTag com.examp...lication I [a92ab19ae90197d 236699a 2544fdb]Print2 +06-05 21:26:01.008 9944-13962 A00000/com.exa...ation/testTag com.examp...lication I Print2, HiTraceChain end +``` + +### 工程目录 + +``` +└── entry + └── src + └── main + ├── cpp + │ ├── CMakeLists.txt + │ ├── napi_init.cpp + │ └── types + │ └── libentry + │ ├── Index.d.ts + │ └── oh-package.json5 + └── ets + ├── entryability + │ └── EntryAbility.ets + ├── entrybackupability + │ └── EntryBackupAbility.ets + └── pages + └── Index.ets +``` + +### 具体实现 + +1. ArkTS项目可以在"@kit.PerformanceAnalysisKit"中导入对应模块即可在各种场景下调用对应函数,如在index.ets中直接调用,或者在EntryAbility.ets函数中在应用的各个生命周期内添加功能函数以实现应用自动在“启动”或“结束”时进行性能分析。 +2. C++项目可以在CMakeLists.txt里的target_link_libraries中添加对应功能的包,在napi_init.cpp中添加注册自定义C++功能函数(还需在index.d.ts中声明)后,即可在各种场景下通过"libentry.so"库自定义一个对象来调用注册声明的测试函数即可。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机; +2. 本示例已适配API20版本SDK,版本号:6.0.0.47; +3. 本示例需要使用DevEco Studio(6.0.0.858)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/ > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f9f311acef30dae790bd712ea67cad948ca1d509 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/build-profile.json5 @@ -0,0 +1,52 @@ +/* + * 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "6.0.0(20)", + "compileSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f3d112306bd8c6ec733f59e86a9dd7450a60a8a8 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/build-profile.json5 @@ -0,0 +1,59 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + }, + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/obfuscation-rules.txt b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5d993e5251fd56950970aa593aefef1b8d71e976 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/CMakeLists.txt b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e8d578188cb3df822a8250c0b39a845f1ff61313 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# [Start hitracechain_ndk_cmake_code] +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(HiTraceChainTest03) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libhitrace_ndk.z.so libhilog_ndk.z.so) +# [End hitracechain_ndk_cmake_code] \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/napi_init.cpp b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4f966d0c4c97c625c8ae50ecfcbf72923c359b9 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,124 @@ +/* + * 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. + */ + +// [Start hitracechain_ndk_native_code] +#include + +#include "hilog/log.h" +#include "hitrace/trace.h" +#include "napi/native_api.h" + +#undef LOG_TAG +#define LOG_TAG "testTag" + +void Print2(HiTraceId id) +{ + // 为当前线程设置HiTraceId + OH_HiTrace_SetId(&id); + // 生成分支标识spanId + id = OH_HiTrace_CreateSpan(); + // 为当前线程设置带spanId的HiTraceId + OH_HiTrace_SetId(&id); + OH_LOG_INFO(LogType::LOG_APP, "Print2"); + // 结束当前线程分布式跟踪,功能同OH_HiTrace_EndChain() + OH_HiTrace_ClearId(); + OH_LOG_INFO(LogType::LOG_APP, "Print2, HiTraceChain end"); +} + +void Print1(HiTraceId id) +{ + // 为当前线程设置HiTraceId + OH_HiTrace_SetId(&id); + // 生成分支标识spanId + id = OH_HiTrace_CreateSpan(); + // 为当前线程设置带spanId的HiTraceId + OH_HiTrace_SetId(&id); + OH_LOG_INFO(LogType::LOG_APP, "Print1"); + std::thread(Print2, OH_HiTrace_GetId()).detach(); + // 结束当前线程分布式跟踪 + OH_HiTrace_EndChain(); + OH_LOG_INFO(LogType::LOG_APP, "Print1, HiTraceChain end"); +} + +static napi_value Add(napi_env env, napi_callback_info info) +{ + // 任务开始,开启分布式跟踪 + HiTraceId hiTraceId = OH_HiTrace_BeginChain("testTag: hiTraceChain begin", HiTrace_Flag::HITRACE_FLAG_DEFAULT); + // 判断生成的hiTraceId是否有效,有效则输出一行hilog日志 + if (OH_HiTrace_IsIdValid(&hiTraceId)) { + OH_LOG_INFO(LogType::LOG_APP, "HiTraceId is valid"); + } + // 使能HITRACE_FLAG_INCLUDE_ASYNC标志位,表示会在系统支持的异步机制里自动传递HiTraceId + OH_HiTrace_EnableFlag(&hiTraceId, HiTrace_Flag::HITRACE_FLAG_INCLUDE_ASYNC); + // 判断hitraceId的HITRACE_FLAG_INCLUDE_ASYNC标志位是否已经使能,使能则把hiTraceId设置到当前线程TLS中 + if (OH_HiTrace_IsFlagEnabled(&hiTraceId, HiTrace_Flag::HITRACE_FLAG_INCLUDE_ASYNC)) { + OH_HiTrace_SetId(&hiTraceId); + OH_LOG_INFO(LogType::LOG_APP, "HITRACE_FLAG_INCLUDE_ASYNC is enabled"); + } + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + // 创建线程执行打印任务,传递当前线程的HiTraceId + std::thread(Print1, OH_HiTrace_GetId()).detach(); + // 任务结束,结束分布式跟踪 + OH_HiTrace_EndChain(); + OH_LOG_INFO(LogType::LOG_APP, "Add, HiTraceChain end"); + + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} +// [End hitracechain_ndk_native_code] \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/types/libentry/Index.d.ts b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..5c14affc63e0dc8a96335ff0c4f6256d392724e2 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,16 @@ +/* + * 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. + */ + +export const add: (a: number, b: number) => number; \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/types/libentry/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..846e4c7e13ead48abe6019bd40f3a13bf8f9c083 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/entryability/EntryAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a95f638674014a6d6088fb8a25f00854a309e53 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * 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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fca37ecc34e1079aaf6557f1272cd694aa0068c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/pages/Index.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d8f89001b29f63e1a37657dd661e2e7b397d4c0 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,48 @@ +/* + * 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. + */ + +// [Start hitracechain_ndk_page_code] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import testNapi from 'libentry.so'; + +const DOMAIN = 0x0000; + +@Entry +@Component +struct Index { + @State message: string = 'clickTime=0'; + @State clickTime: number = 0; + + build() { + Row() { + Column() { + Button(this.message) + .fontSize(20) + .margin(5) + .width(350) + .height(60) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.clickTime++; + this.message = 'clickTime=' + this.clickTime; + hilog.info(DOMAIN, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3)); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End hitracechain_ndk_page_code] \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/module.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d700a40c54cefb5c84bb352cf7a89b37acd0f342 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/float.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/startIcon.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/media/startIcon.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/profile/backup_config.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/profile/main_pages.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/dark/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/mock/Libentry.mock.ets b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/mock/Libentry.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..eebf1ed910f6a8f2a9e7e565aa71b179b7b8b537 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + +const NativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default NativeMock; \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/mock/mock-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2c7d2ba82b796a2850ced0a277d261d7d7355416 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/entry/src/mock/mock-config.json5 @@ -0,0 +1,20 @@ +/* + * 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. + */ + +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/hvigor/hvigor-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0c92fdad58a7851692e144df9a4b1f4953ec26c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..34a126da756d306c9412997bcd7d57a34b6da0a2 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/ohosTest.md b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..519de1061cdf567c9a47035833c781802f105b5a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/ohosTest.md @@ -0,0 +1,8 @@ +# 性能分析工具测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ---------------------- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | +| 主页按钮点击 | 位于主页 | 按readme的使用说明操作 | 输出预期日志 | 否 | Pass | diff --git a/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/screenshots/Snipaste_2025-10-17_15-32-47.png b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/screenshots/Snipaste_2025-10-17_15-32-47.png new file mode 100644 index 0000000000000000000000000000000000000000..e3b876436723f935c661f19112d9da240ba48f92 Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceChain_NDK/screenshots/Snipaste_2025-10-17_15-32-47.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/app.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..19b31bd47ff4d45d25d0736de16d5fcb379135f5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.example.hitracemeter_arkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..15db0933119c555aabc9d0fe3313c74dd31138cd --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "HitraceMeter_ArkTS" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/README_zh.md b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..57db0111502e71f659baa82fc985175023a5593c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/README_zh.md @@ -0,0 +1,89 @@ +# HiTraceMeter ArkTS接口使用样例 + +### 介绍 + +本示例主要展示了使用HiTraceMeter提供系统性能打点接口。开发者通过在关键代码位置调用HiTraceMeter接口提供的API接口,能够有效跟踪进程轨迹、查看系统性能。 + +该工程中的展示的代码详细描述可查如下链接: + +- [使用HiTraceMeter跟踪性能(ArkTS)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hitracemeter-guidelines-arkts.md) + +### 效果预览 + +| 主页 | +| :----------------------------------------------------------------------------------: | +| `z` | + +#### 使用说明 + +1.在主界面点击Hello World文本;DevEco Studio Terminal 中执行如下命令: + +``` +PS D:\xxx\xxx> hdc shell +$ hitrace --trace_begin app +``` + +2.执行抓取trace命令后,先在设备中点击几次HiTraceMeter ArkTS按钮,继续在Terminal窗口执行命令: + +``` +$ hitrace --trace_dump | grep myTest +``` + +3.成功输出如下数据即为成功: + +``` +e.myapplication-39945 ( 39945) [010] .... 347921.342267: tracing_mark_write: S|39945|H:myTestAsyncTrace|1001|M62|categoryTest|key=value +e.myapplication-39945 ( 39945) [010] .... 347921.342280: tracing_mark_write: C|39945|H:myTestCountTrace|1|M62 +e.myapplication-39945 ( 39945) [010] .... 347921.342327: tracing_mark_write: S|39945|H:myTestAsyncTrace|1002|M62|categoryTest|key=value +e.myapplication-39945 ( 39945) [010] .... 347921.342333: tracing_mark_write: C|39945|H:myTestCountTrace|2|M62 +e.myapplication-39945 ( 39945) [010] .... 347921.342358: tracing_mark_write: F|39945|H:myTestAsyncTrace|1001|M62 +e.myapplication-39945 ( 39945) [010] .... 347921.342365: tracing_mark_write: F|39945|H:myTestAsyncTrace|1002|M62 +e.myapplication-39945 ( 39945) [010] .... 347921.342387: tracing_mark_write: B|39945|H:myTestSyncTrace|M62|key=value +e.myapplication-39945 ( 39945) [010] .... 347921.342586: tracing_mark_write: S|39945|H:myTestAsyncTrace|1003|M62|categoryTest|key0=value0,key1=value1,key2=value2,key3=value3,key4=value4,key5=value5,key6=value6,key7=value7,key8=value8,key9=value9 +e.myapplication-39945 ( 39945) [010] .... 347921.342615: tracing_mark_write: F|39945|H:myTestAsyncTrace|1003|M62 +``` + +### 工程目录 + +``` +└── entry + └── src + └── main + └── ets + ├── entryability + │ └── EntryAbility.ets + ├── entrybackupability + │ └── EntryBackupAbility.ets + └── pages + └── Index.ets //主页 +``` + +### 具体实现 + +1. ArkTS项目可以在"@kit.PerformanceAnalysisKit"中导入对应模块即可在各种场景下调用对应函数,如在index.ets中直接调用,或者在EntryAbility.ets函数中在应用的各个生命周期内添加功能函数以实现应用自动在“启动”或“结束”时进行性能分析。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机; +2. 本示例已适配API20版本SDK,版本号:6.0.0.47; +3. 本示例需要使用DevEco Studio(6.0.0.858)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/ > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f9f311acef30dae790bd712ea67cad948ca1d509 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/build-profile.json5 @@ -0,0 +1,52 @@ +/* + * 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "6.0.0(20)", + "compileSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1d2fc52afb11467a138506d8509a3ca2c123707e --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/obfuscation-rules.txt b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a95f638674014a6d6088fb8a25f00854a309e53 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * 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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fca37ecc34e1079aaf6557f1272cd694aa0068c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/pages/Index.ets b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4931ea7c5010640bc84765480c2d17ef3d50e599 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,83 @@ +/* + * 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. + */ + +// [Start hitracemeter_arkts_code] +import { hiTraceMeter, hilog } from '@kit.PerformanceAnalysisKit'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.message = (this.message == 'Hello HiTrace') ? 'Hello World' : 'Hello HiTrace'; + const COMMERCIAL = hiTraceMeter.HiTraceOutputLevel.COMMERCIAL; + + let traceCount = 0; + // 第一个异步跟踪任务开始 + hiTraceMeter.startAsyncTrace(COMMERCIAL, 'myTestAsyncTrace', 1001, 'categoryTest', 'key=value'); + // 开始计数任务 + traceCount++; + hiTraceMeter.traceByValue(COMMERCIAL, 'myTestCountTrace', traceCount); + // 业务流程 + hilog.info(0x0000, 'testTrace', 'myTraceTest running, taskId: 1001'); + + // 第二个异步跟踪任务开始,同时第一个跟踪的同名任务还没结束,出现了并行执行,对应接口的taskId需要不同 + hiTraceMeter.startAsyncTrace(COMMERCIAL, 'myTestAsyncTrace', 1002, 'categoryTest', 'key=value'); + // 开始计数任务 + traceCount++; + hiTraceMeter.traceByValue(COMMERCIAL, 'myTestCountTrace', traceCount); + // 业务流程 + hilog.info(0x0000, 'testTrace', 'myTraceTest running, taskId: 1002'); + + // 结束taskId为1001的异步跟踪任务 + hiTraceMeter.finishAsyncTrace(COMMERCIAL, 'myTestAsyncTrace', 1001); + // 结束taskId为1002的异步跟踪任务 + hiTraceMeter.finishAsyncTrace(COMMERCIAL, 'myTestAsyncTrace', 1002); + + // 开始同步跟踪任务 + hiTraceMeter.startSyncTrace(COMMERCIAL, 'myTestSyncTrace', 'key=value'); + // 业务流程 + hilog.info(0x0000, 'testTrace', 'myTraceTest running, synchronizing trace'); + // 结束同步跟踪任务 + hiTraceMeter.finishSyncTrace(COMMERCIAL); + + // 若通过HiTraceMeter性能打点接口传递的参数的生成过程比较复杂,此时可以通过isTraceEnabled判断当前是否开启应用trace捕获, + // 在未开启应用trace捕获时,避免该部分性能损耗 + if (hiTraceMeter.isTraceEnabled()) { + let customArgs = 'key0=value0'; + for (let index = 1; index < 10; index++) { + customArgs += `,key${index}=value${index}` + } + hiTraceMeter.startAsyncTrace(COMMERCIAL, 'myTestAsyncTrace', 1003, 'categoryTest', customArgs); + hilog.info(0x0000, 'testTrace', 'myTraceTest running, taskId: 1003'); + hiTraceMeter.finishAsyncTrace(COMMERCIAL, 'myTestAsyncTrace', 1003); + } else { + hilog.info(0x0000, 'testTrace', 'myTraceTest running, trace is not enabled'); + } + }) + } + .width('100%') + } + .height('100%') + } +} +// [End hitracemeter_arkts_code] \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/module.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d700a40c54cefb5c84bb352cf7a89b37acd0f342 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/float.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/startIcon.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/media/startIcon.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/profile/backup_config.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/profile/main_pages.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/dark/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/mock/mock-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/hvigor/hvigor-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0c92fdad58a7851692e144df9a4b1f4953ec26c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..34a126da756d306c9412997bcd7d57a34b6da0a2 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/ohosTest.md b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..519de1061cdf567c9a47035833c781802f105b5a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/ohosTest.md @@ -0,0 +1,8 @@ +# 性能分析工具测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ---------------------- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | +| 主页按钮点击 | 位于主页 | 按readme的使用说明操作 | 输出预期日志 | 否 | Pass | diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/screenshots/Snipaste_2025-10-17_14-47-32.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/screenshots/Snipaste_2025-10-17_14-47-32.png new file mode 100644 index 0000000000000000000000000000000000000000..e1eadfca86e5990aa1c4787d69c3a805a22a9da3 Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_ArkTS/screenshots/Snipaste_2025-10-17_14-47-32.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/app.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dd0fdf641f3d282c8309c2e06134647973c8b58f --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.example.hitracemeter_ndk", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2b9420b8bcf0521a4e4def618ee3bb74014688b5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "HitraceMeter_NDK" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/README_zh.md b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..1a81eab972ee9c660d12b44d27a694c3e5f29c90 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/README_zh.md @@ -0,0 +1,103 @@ +# HiTraceMeter NDK接口使用样例 + +### 介绍 + +本示例主要展示了使用HiTraceMeter提供系统性能打点接口。开发者通过在关键代码位置调用HiTraceMeter接口提供的API接口,能够有效跟踪进程轨迹、查看系统性能。 + +该工程中的展示的代码详细描述可查如下链接: + +- [使用HiTraceMeter跟踪性能(C/C++)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hitracemeter-guidelines-ndk.md) + +### 效果预览 + +| 主页 | +| :----------------------------------------------------------------------------------: | +| `z` | + +#### 使用说明 + +1.在主界面点击Hello World文本;DevEco Studio Terminal 中执行如下命令: + +``` +PS D:\xxx\xxx> hdc shell +$ hitrace --trace_begin app +``` + +2.执行抓取trace命令后,先在设备中点击几次HiTraceMeter ArkTS按钮,继续在Terminal窗口执行命令: + +``` +$ hitrace --trace_dump | grep myTest +``` + +3.成功输出如下数据即为成功: + +``` +<...>-49837 (-------) [002] .... 349137.708093: tracing_mark_write: S|49837|H:myTestAsyncTrace|1001|M62|categoryTest|key=value +<...>-49837 (-------) [002] .... 349137.708103: tracing_mark_write: C|49837|H:myTestCountTrace|1|M62 +<...>-49837 (-------) [002] .... 349137.708201: tracing_mark_write: S|49837|H:myTestAsyncTrace|1002|M62|categoryTest|key=value +<...>-49837 (-------) [002] .... 349137.708209: tracing_mark_write: C|49837|H:myTestCountTrace|2|M62 +<...>-49837 (-------) [002] .... 349137.708239: tracing_mark_write: F|49837|H:myTestAsyncTrace|1001|M62 +<...>-49837 (-------) [002] .... 349137.708246: tracing_mark_write: F|49837|H:myTestAsyncTrace|1002|M62 +<...>-49837 (-------) [002] .... 349137.708252: tracing_mark_write: B|49837|H:myTestSyncTrace|M62|key=value +<...>-49837 (-------) [002] .... 349137.708301: tracing_mark_write: S|49837|H:myTestAsyncTrace|1003|M62|categoryTest|key0=value0,key1=value1,key2=value2,key3=value3,key4=value4,key5=value5,key6=value6,key7=value7,key8=value8,key9=value9 +<...>-49837 (-------) [002] .... 349137.708323: tracing_mark_write: F|49837|H:myTestAsyncTrace|1003|M62 +``` + +4. 停止采集trace + +``` +$ hitrace --trace_finish +``` + +### 工程目录 + +``` +└── entry + └── src + └── main + ├── cpp + │ ├── CMakeLists.txt + │ ├── napi_init.cpp + │ └── types + │ └── libentry + │ ├── Index.d.ts + │ └── oh-package.json5 + └── ets + ├── entryability + │ └── EntryAbility.ets + ├── entrybackupability + │ └── EntryBackupAbility.ets + └── pages + └── Index.ets +``` + +### 具体实现 + +1. ArkTS项目可以在"@kit.PerformanceAnalysisKit"中导入对应模块即可在各种场景下调用对应函数,如在index.ets中直接调用,或者在EntryAbility.ets函数中在应用的各个生命周期内添加功能函数以实现应用自动在“启动”或“结束”时进行性能分析。 +2. C++项目可以在CMakeLists.txt里的target_link_libraries中添加对应功能的包,在napi_init.cpp中添加注册自定义C++功能函数(还需在index.d.ts中声明)后,即可在各种场景下通过"libentry.so"库自定义一个对象来调用注册声明的测试函数即可。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机; +2. 本示例已适配API20版本SDK,版本号:6.0.0.47; +3. 本示例需要使用DevEco Studio(6.0.0.858)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/ > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f9f311acef30dae790bd712ea67cad948ca1d509 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/build-profile.json5 @@ -0,0 +1,52 @@ +/* + * 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "6.0.0(20)", + "compileSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/.gitignore b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/build-profile.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f3d112306bd8c6ec733f59e86a9dd7450a60a8a8 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/build-profile.json5 @@ -0,0 +1,59 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + }, + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/obfuscation-rules.txt b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5d993e5251fd56950970aa593aefef1b8d71e976 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/CMakeLists.txt b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b4a9f97420d22d618e19f4d0e50b1a5e42d97d7d --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# [Start hitracemeter_ndk_cmake_code] +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(HiTraceChainTest03) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libhitrace_ndk.z.so libhilog_ndk.z.so) +# [End hitracemeter_ndk_cmake_code] \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/napi_init.cpp b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0629edeb9c7a42b66b42436a8137a4497af8e184 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,127 @@ +/* + * 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. + */ + +// [Start hitracemeter_ndk_native_code] +#include +#include + +#include "hilog/log.h" +#include "hitrace/trace.h" +#include "napi/native_api.h" + +#undef LOG_TAG +#define LOG_TAG "traceTest" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + // 第一个异步跟踪任务开始 + HiTrace_Output_Level level = HITRACE_LEVEL_COMMERCIAL; + constexpr int64_t taskIdOne = 1001; + OH_HiTrace_StartAsyncTraceEx(level, "myTestAsyncTrace", taskIdOne, "categoryTest", "key=value"); + // 开始计数任务 + int64_t traceCount = 0; + traceCount++; + OH_HiTrace_CountTraceEx(level, "myTestCountTrace", traceCount); + // 业务流程 + OH_LOG_INFO(LogType::LOG_APP, "myTraceTest running, taskId: 1001"); + // 第二个异步跟踪任务开始,同时第一个跟踪的同名任务还没结束,出现了并行执行,对应接口的taskId需要不同 + constexpr int64_t taskIdTwo = 1002; + OH_HiTrace_StartAsyncTraceEx(level, "myTestAsyncTrace", taskIdTwo, "categoryTest", "key=value"); + // 开始计数任务 + traceCount++; + OH_HiTrace_CountTraceEx(level, "myTestCountTrace", traceCount); + // 业务流程 + OH_LOG_INFO(LogType::LOG_APP, "myTraceTest running, taskId: 1002"); + + // 结束taskId为1001的异步跟踪任务 + OH_HiTrace_FinishAsyncTraceEx(level, "myTestAsyncTrace", taskIdOne); + // 结束taskId为1002的异步跟踪任务 + OH_HiTrace_FinishAsyncTraceEx(level, "myTestAsyncTrace", taskIdTwo); + + // 开始同步跟踪任务 + OH_HiTrace_StartTraceEx(level, "myTestSyncTrace", "key=value"); + // 业务流程 + OH_LOG_INFO(LogType::LOG_APP, "myTraceTest running, synchronizing trace"); + // 结束同步跟踪任务 + OH_HiTrace_FinishTraceEx(level); + + // 若通过HiTraceMeter性能打点接口传递的参数的生成过程比较复杂,此时可以通过isTraceEnabled判断当前是否开启应用trace捕获, + // 在未开启应用trace捕获时,避免该部分性能损耗 + constexpr int64_t taskIdThree = 1003; + constexpr int loopTime = 10; + if (OH_HiTrace_IsTraceEnabled()) { + char customArgs[128] = "key0=value0"; + for (int index = 1; index < loopTime; index++) { + char buffer[16]; + snprintf(buffer, sizeof(buffer), ",key%d=value%d", index, index); + strncat(customArgs, buffer, sizeof(customArgs) - strlen(customArgs) - 1); + } + OH_HiTrace_StartAsyncTraceEx(level, "myTestAsyncTrace", taskIdThree, "categoryTest", customArgs); + OH_LOG_INFO(LogType::LOG_APP, "myTraceTest running, taskId: 1003"); + OH_HiTrace_FinishAsyncTraceEx(level, "myTestAsyncTrace", taskIdThree); + } else { + OH_LOG_INFO(LogType::LOG_APP, "myTraceTest running, trace is not enabled"); + } + + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} +// [End hitracemeter_ndk_native_code] \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/types/libentry/Index.d.ts b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..5c14affc63e0dc8a96335ff0c4f6256d392724e2 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,16 @@ +/* + * 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. + */ + +export const add: (a: number, b: number) => number; \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/types/libentry/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..846e4c7e13ead48abe6019bd40f3a13bf8f9c083 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/entryability/EntryAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a95f638674014a6d6088fb8a25f00854a309e53 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,63 @@ +/* + * 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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fca37ecc34e1079aaf6557f1272cd694aa0068c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/pages/Index.ets b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..60dcb7ae52242195af7b5083378e9525b8766785 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,41 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import testNapi from 'libentry.so'; + +const DOMAIN = 0x0000; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.message = 'Welcome'; + hilog.info(DOMAIN, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3)); + }) + } + .width('100%') + } + .height('100%') + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/module.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d700a40c54cefb5c84bb352cf7a89b37acd0f342 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/float.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/string.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/background.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/background.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/foreground.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/foreground.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/layered_image.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/startIcon.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/media/startIcon.png differ diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/profile/backup_config.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/profile/main_pages.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/dark/element/color.json b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/mock/Libentry.mock.ets b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/mock/Libentry.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..eebf1ed910f6a8f2a9e7e565aa71b179b7b8b537 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + +const NativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default NativeMock; \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/mock/mock-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2c7d2ba82b796a2850ced0a277d261d7d7355416 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/entry/src/mock/mock-config.json5 @@ -0,0 +1,20 @@ +/* + * 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. + */ + +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/hvigor/hvigor-config.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0c92fdad58a7851692e144df9a4b1f4953ec26c --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/hvigorfile.ts b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/oh-package.json5 b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..34a126da756d306c9412997bcd7d57a34b6da0a2 --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/ohosTest.md b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..519de1061cdf567c9a47035833c781802f105b5a --- /dev/null +++ b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/ohosTest.md @@ -0,0 +1,8 @@ +# 性能分析工具测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ---------------------- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 否 | Pass | +| 主页按钮点击 | 位于主页 | 按readme的使用说明操作 | 输出预期日志 | 否 | Pass | diff --git a/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/screenshots/Snipaste_2025-10-17_14-47-32.png b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/screenshots/Snipaste_2025-10-17_14-47-32.png new file mode 100644 index 0000000000000000000000000000000000000000..e1eadfca86e5990aa1c4787d69c3a805a22a9da3 Binary files /dev/null and b/PerformanceAnalysisKit/HiTrace/HitraceMeter_NDK/screenshots/Snipaste_2025-10-17_14-47-32.png differ