diff --git a/code/Performance/PerformanceLibrary/build-profile.json5 b/code/Performance/PerformanceLibrary/build-profile.json5 index 1e6a591fc..c601ce300 100644 --- a/code/Performance/PerformanceLibrary/build-profile.json5 +++ b/code/Performance/PerformanceLibrary/build-profile.json5 @@ -20,9 +20,9 @@ { "name": "default", "signingConfig": "default", - "compileSdkVersion": 10, - "compatibleSdkVersion": 10, - "targetSdkVersion": 10 + "compileSdkVersion": 11, + "compatibleSdkVersion": 11, + "targetSdkVersion": 11 } ], "buildModeSet": [ @@ -110,6 +110,10 @@ { "name": "nativeThreadsCallJS", "srcPath": "./feature/nativeThreadsCallJS" + }, + { + "name": "ThreadCommunication", + "srcPath": "./feature/ThreadCommunication" } ] } \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/.gitignore b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/.gitignore new file mode 100644 index 000000000..e2713a277 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/Index.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/Index.ets new file mode 100644 index 000000000..f699eea6e --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/Index.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 { IndependentTask } from './src/main/ets/pages/IndependentTask'; +export { MultiTask } from './src/main/ets/pages/MultiTask'; +export { TaskSendDataUsage } from './src/main/ets/pages/TaskSendDataUsage'; +export { WorkerUsage } from './src/main/ets/pages/WorkerUsage'; +export { WorkerCallGlobalUsage } from './src/main/ets/pages/WorkerCallGlobalUsage'; +export { ThreadCommunicationHomePage } from './src/main/ets/pages/ThreadCommunicationHomePage'; diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/build-profile.json5 b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/build-profile.json5 new file mode 100644 index 000000000..186963290 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/build-profile.json5 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 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": { + + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + } + }, + ], + "targets": [ + { + "name": "default" + } + ] +} diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/consumer-rules.txt b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/consumer-rules.txt new file mode 100644 index 000000000..e69de29bb diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/hvigorfile.ts b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/hvigorfile.ts new file mode 100644 index 000000000..6354b7339 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 { harTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/obfuscation-rules.txt b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/obfuscation-rules.txt new file mode 100644 index 000000000..985b2aeb7 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/obfuscation-rules.txt @@ -0,0 +1,18 @@ +# 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://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md + +# 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 \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/oh-package.json5 b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/oh-package.json5 new file mode 100644 index 000000000..02b8ec2fb --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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. + */ + +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "threadcommunication", + "description": "Please describe the basic information.", + "main": "ThreadCommunicationHomePage.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IconItemSource.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IconItemSource.ets new file mode 100644 index 000000000..630fc1f57 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IconItemSource.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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 class IconItemSource { + image: string | Resource = ''; + text: string | Resource = ''; + + constructor(image: string | Resource = '', text: string | Resource = '') { + this.image = image; + this.text = text; + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IconView.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IconView.ets new file mode 100644 index 000000000..27e1631ce --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IconView.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 TEXT_OPACITY: number = 0.8; + +@Component +export struct IconItem { + image: string | Resource = ''; + text: string | Resource = ''; + + build() { + Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignContent: FlexAlign.Center }) { + Image(this.image) + .height(40) + .width(40) + .objectFit(ImageFit.Contain) + .margin({ + left: 15 + }) + + Text(this.text) + .fontSize(20) + .fontColor(Color.Black) + .width(100) + .height(50) + .opacity(TEXT_OPACITY) + .textAlign(TextAlign.Center) + } + .width($r('app.string.percent_100')) + .height(50) + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IndependentTask.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IndependentTask.ets new file mode 100644 index 000000000..7faa31c5f --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/IndependentTask.ets @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024 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 router from '@ohos.router'; +import taskpool from '@ohos.taskpool'; +import { IconItem } from './IconView'; +import { IconItemSource } from './IconItemSource'; + +@Concurrent +function loadPicture(count: number): IconItemSource[] { + let iconItemSourceList: IconItemSource[] = []; + // 遍历添加count*6个IconItem的数据 + for (let index = 0; index < count; index++) { + const numStart: number = index * 6; + // 此处循环使用6张图片资源 + iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`)); + } + return iconItemSourceList; +} + +@Component +export struct IndependentTask { + @State iconItemSourceList: IconItemSource[] = []; + + build() { + Column() { + // 顶部导航栏 + Row() { + Image($r("app.media.back")) + .height(24) + .width(24) + .onClick(() => { + router.back(); + }) + + Text($r('app.string.scenario_1')) + .fontSize(24) + .lineHeight(30) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ + left: 16 + }) + } + .width($r('app.string.percent_100')) + .height(50) + .justifyContent(FlexAlign.Start) + .padding({ + left: 24 + }) + + Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true }) + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30); + taskpool.execute(lodePictureTask).then((res: Object) => { + this.iconItemSourceList = res as IconItemSource[]; + }) + }) + if (this.iconItemSourceList.length > 0) { + List({ space: 20 }) { + ForEach(this.iconItemSourceList, (item: IconItemSource) => { + ListItem() { + IconItem({ image: item.image, text: item.text }); + } + }, (item: IconItemSource, index) => index.toString()) + } + .divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线 + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .layoutWeight(1) + } + } + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .alignItems(HorizontalAlign.Center) + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/MultiTask.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/MultiTask.ets new file mode 100644 index 000000000..2cae01b54 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/MultiTask.ets @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2024 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 router from '@ohos.router'; +import taskpool from '@ohos.taskpool'; +import { IconItem } from './IconView'; +import { IconItemSource } from './IconItemSource'; + +@Concurrent +function loadPicture(count: number): IconItemSource[] { + let iconItemSourceList: IconItemSource[] = []; + // 遍历添加count*6个IconItem的数据 + for (let index = 0; index < count; index++) { + const numStart: number = index * 6; + // 此处循环使用6张图片资源 + iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`)); + } + return iconItemSourceList; +} + +@Component +export struct MultiTask { + @State iconItemSourceList: IconItemSource[] = []; + + build() { + Column() { + // 顶部导航栏 + Row() { + Image($r("app.media.back")) + .height(24) + .width(24) + .onClick(() => { + router.back(); + }) + + Text($r('app.string.scenario_2')) + .fontSize(24) + .lineHeight(30) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ + left: 16 + }) + } + .width($r('app.string.percent_100')) + .height(50) + .justifyContent(FlexAlign.Start) + .padding({ + left: 24 + }) + + Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true }) + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + let taskGroup: taskpool.TaskGroup = new taskpool.TaskGroup(); + taskGroup.addTask(new taskpool.Task(loadPicture, 30)); + taskGroup.addTask(new taskpool.Task(loadPicture, 20)); + taskGroup.addTask(new taskpool.Task(loadPicture, 10)); + taskpool.execute(taskGroup).then((ret: Object[]) => { + for (let i = 0; i < ret.length; i++) { + let iconItems: IconItemSource[] = (ret[i] as IconItemSource[]); + for (let j = 0; j < iconItems.length; j++) { + this.iconItemSourceList.push(iconItems[j] as IconItemSource); + } + } + }) + }) + if (this.iconItemSourceList.length > 0) { + List({ space: 20 }) { + ForEach(this.iconItemSourceList, (item: IconItemSource) => { + ListItem() { + IconItem({ image: item.image, text: item.text }); + } + }, (item: IconItemSource, index) => index.toString()) + } + .divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线 + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .layoutWeight(1) + } + } + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .alignItems(HorizontalAlign.Center) + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/TaskSendDataUsage.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/TaskSendDataUsage.ets new file mode 100644 index 000000000..964848505 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/TaskSendDataUsage.ets @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2024 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 router from '@ohos.router'; +import taskpool from '@ohos.taskpool'; +import { IconItem } from './IconView'; +import { IconItemSource } from './IconItemSource'; +import Logger from '../util/Logger'; + +const LOAD_SUCCESS: string = getContext().resourceManager.getStringSync($r('app.string.process_success')); + +@Concurrent +function loadPicture(count: number): IconItemSource[] { + let iconItemSourceList: IconItemSource[] = []; + // 遍历添加count*6个IconItem的数据 + for (let index = 0; index < count; index++) { + const numStart: number = index * 6; + // 此处循环使用6张图片资源 + iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`)); + iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`)); + } + taskpool.Task.sendData(iconItemSourceList.length); + return iconItemSourceList; +} + +function notice(data: number): void { + Logger.info(LOAD_SUCCESS + data); +} + +@Component +export struct TaskSendDataUsage { + @State iconItemSourceList: IconItemSource[] = []; + + build() { + Column() { + // 顶部导航栏 + Row() { + Image($r("app.media.back")) + .height(24) + .width(24) + .onClick(() => { + router.back(); + }) + + Text($r('app.string.scenario_3')) + .fontSize(24) + .lineHeight(30) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ + left: 16 + }) + } + .width($r('app.string.percent_100')) + .height(50) + .justifyContent(FlexAlign.Start) + .padding({ + left: 24 + }) + + Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true }) + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30); + lodePictureTask.onReceiveData(notice); + taskpool.execute(lodePictureTask).then((res: Object) => { + this.iconItemSourceList = res as IconItemSource[]; + }) + }) + if (this.iconItemSourceList.length > 0) { + List({ space: 20 }) { + ForEach(this.iconItemSourceList, (item: IconItemSource) => { + ListItem() { + IconItem({ image: item.image, text: item.text }); + } + }, (item: IconItemSource, index) => index.toString()) + } + .divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线 + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .layoutWeight(1) + } + } + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .alignItems(HorizontalAlign.Center) + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/ThreadCommunicationHomePage.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/ThreadCommunicationHomePage.ets new file mode 100644 index 000000000..e0d86af8b --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/ThreadCommunicationHomePage.ets @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2024 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 router from '@ohos.router'; + +@Component +export struct ThreadCommunicationHomePage { + build() { + Column() { + Row() { + Row() { + Text($r('app.string.thread_communication')) + .fontSize(20) + .lineHeight(30) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + .width($r('app.string.percent_100')) + .height(30) + } + .height(56) + .backgroundColor(Color.White) + } + .margin({ + left: 24 + }) + + Button($r('app.string.scenario_1'), { type: ButtonType.Normal, stateEffect: true }) + .id('Scenario_1') + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + router.pushUrl({ + url: 'pages/ThreadCommunication/IndependentTaskPage' + }) + }) + + Button($r('app.string.scenario_2'), { type: ButtonType.Normal, stateEffect: true }) + .id('Scenario_2') + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + router.pushUrl({ + url: 'pages/ThreadCommunication/MultiTaskPage' + }) + }) + + Button($r('app.string.scenario_3'), { type: ButtonType.Normal, stateEffect: true }) + .id('Scenario_3') + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + router.pushUrl({ + url: 'pages/ThreadCommunication/TaskSendDataUsagePage' + }) + }) + + Button($r('app.string.scenario_4'), { type: ButtonType.Normal, stateEffect: true }) + .id('Scenario_4') + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + router.pushUrl({ + url: 'pages/ThreadCommunication/WorkerUsagePage' + }) + }) + + Button($r('app.string.scenario_5'), { type: ButtonType.Normal, stateEffect: true }) + .id('Scenario_5') + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + router.pushUrl({ + url: 'pages/ThreadCommunication/WorkerCallGlobalUsagePage' + }) + }) + } + .height(200) + .width($r('app.string.percent_100')) + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/WorkerCallGlobalUsage.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/WorkerCallGlobalUsage.ets new file mode 100644 index 000000000..5d14f8e5a --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/WorkerCallGlobalUsage.ets @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024 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 router from '@ohos.router'; +import worker from '@ohos.worker'; +import { IconItem } from './IconView'; +import { IconItemSource } from './IconItemSource'; + + +class PicData { + public iconItemSourceList: IconItemSource[] = []; + + public setUp(): string { + for (let index = 0; index < 20; index++) { + const numStart: number = index * 6; + // 此处循环使用6张图片资源 + this.iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`)); + } + return "setUpIconItemSourceList success!"; + } +} + +@Component +export struct WorkerCallGlobalUsage { + @State iconItemSourceList: IconItemSource[] = []; + private workerInstance: worker.ThreadWorker | undefined = undefined; + private message: string = "run setUp in picData"; + + aboutToAppear() { + this.initWorker(); + } + + build() { + Column() { + // 顶部导航栏 + Row() { + Image($r("app.media.back")) + .height(24) + .width(24) + .onClick(() => { + router.back(); + }) + + Text($r('app.string.scenario_5')) + .fontSize(24) + .lineHeight(30) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ + left: 16 + }) + } + .width($r('app.string.percent_100')) + .height(50) + .justifyContent(FlexAlign.Start) + .padding({ + left: 24 + }) + + Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true }) + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + if (this.workerInstance !== undefined) { + this.workerInstance.postMessage(this.message); + } + }) + + if (this.iconItemSourceList.length > 0) { + List({ space: 20 }) { + ForEach(this.iconItemSourceList, (item: IconItemSource) => { + ListItem() { + IconItem({ image: item.image, text: item.text }); + } + }, (item: IconItemSource, index) => index.toString()) + } + .divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线 + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .layoutWeight(1) + } + } + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .alignItems(HorizontalAlign.Center) + } + + initWorker() { + if (this.workerInstance !== undefined) { + let picData: PicData = new PicData(); + // 在ThreadWorker实例上注册registerObj + this.workerInstance.registerGlobalCallObject("picData", picData); + } + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/WorkerUsage.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/WorkerUsage.ets new file mode 100644 index 000000000..80221b174 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/pages/WorkerUsage.ets @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2024 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 router from '@ohos.router'; +import worker, { MessageEvents } from '@ohos.worker'; +import { IconItem } from './IconView'; +import { IconItemSource } from './IconItemSource'; + +@Component +export struct WorkerUsage { + @State iconItemSourceList: IconItemSource[] = []; + private workerInstance: worker.ThreadWorker | undefined = undefined; + + aboutToAppear() { + for (let index = 0; index < 20; index++) { + const numStart: number = index * 6; + // 此处循环使用6张图片资源 + this.iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`)); + } + if (this.workerInstance !== undefined) { + this.workerInstance.onmessage = (e: MessageEvents): void => { + if (e.data instanceof Array) { + this.iconItemSourceList = e.data; + } + } + } + + } + + build() { + Column() { + // 顶部导航栏 + Row() { + Image($r("app.media.back")) + .height(24) + .width(24) + .onClick(() => { + router.back(); + }) + + Text($r('app.string.scenario_4')) + .fontSize(24) + .lineHeight(30) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ + left: 16 + }) + } + .width($r('app.string.percent_100')) + .height(50) + .justifyContent(FlexAlign.Start) + .padding({ + left: 24 + }) + + Button($r('app.string.change_image_number'), { type: ButtonType.Normal, stateEffect: true }) + .fontSize(14) + .borderRadius(8) + .backgroundColor(Color.Blue) + .width(250) + .height(60) + .margin({ + top: 30 + }) + .onClick(() => { + if (this.workerInstance !== undefined) { + this.workerInstance.postMessage(this.iconItemSourceList); + } + }) + if (this.iconItemSourceList.length > 0) { + List({ space: 20 }) { + ForEach(this.iconItemSourceList, (item: IconItemSource) => { + ListItem() { + IconItem({ image: item.image, text: item.text }); + } + }, (item: IconItemSource, index) => index.toString()) + } + .divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线 + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .layoutWeight(1) + } + } + .width($r('app.string.percent_100')) + .height($r('app.string.percent_100')) + .alignItems(HorizontalAlign.Center) + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/util/Logger.ets b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/util/Logger.ets new file mode 100644 index 000000000..9f11be2b9 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/ets/util/Logger.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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 '@ohos.hilog'; + +const DOMAIN: number = 0xF811; + +class Logger { + private prefix: string=""; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + } + + debug(...args: string[]): void { + hilog.debug(DOMAIN, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(DOMAIN, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(DOMAIN, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(DOMAIN, this.prefix, this.format, args); + } +} + +export default new Logger('ThreadCommunication'); \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/module.json5 b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/module.json5 new file mode 100644 index 000000000..06e19f10a --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/module.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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": "ThreadCommunication", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/element/color.json b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/element/color.json new file mode 100644 index 000000000..3c712962d --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/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/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/element/string.json b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/element/string.json new file mode 100644 index 000000000..1ee898303 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/element/string.json @@ -0,0 +1,56 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "thread_communication", + "value": "主线程和子线程的通信" + }, + { + "name": "scenario_1", + "value": "场景一:独立的耗时任务" + }, + { + "name": "scenario_2", + "value": "场景二:多个任务执行结果统一返回" + }, + { + "name": "scenario_3", + "value": "场景三:TaskPool和主线程的即时通信" + }, + { + "name": "scenario_4", + "value": "场景四:Worker和主线程的即时通信" + }, + { + "name": "scenario_5", + "value": "场景五:子线程同步调用主线程的接口" + }, + { + "name": "load_image", + "value": "加载图片" + }, + { + "name": "percent_100", + "value": "100%" + }, + { + "name": "change_image_number", + "value": "将图片变成4个" + }, + { + "name": "process_success", + "value": "子线程任务已执行完,共加载图片:" + } + ] +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/album.svg b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/album.svg new file mode 100644 index 000000000..7b14dc626 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/album.svg @@ -0,0 +1,30 @@ + + + ic_album + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/applet.svg b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/applet.svg new file mode 100644 index 000000000..ebe013f91 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/applet.svg @@ -0,0 +1,16 @@ + + + ic_applet + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/back.svg b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/back.svg new file mode 100644 index 000000000..57acebd12 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/back.svg @@ -0,0 +1,23 @@ + + + public/ic_back + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/cards.svg b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/cards.svg new file mode 100644 index 000000000..aeb80463a --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/cards.svg @@ -0,0 +1,28 @@ + + + ic_cards + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/nearby.svg b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/nearby.svg new file mode 100644 index 000000000..56852c4b5 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/nearby.svg @@ -0,0 +1,31 @@ + + + ic_near + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/scan.svg b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/scan.svg new file mode 100644 index 000000000..dae3d51e2 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/scan.svg @@ -0,0 +1,29 @@ + + + ic_scan + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/shop.svg b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/shop.svg new file mode 100644 index 000000000..672daaa49 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/base/media/shop.svg @@ -0,0 +1,31 @@ + + + ic_shop + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/en_US/element/string.json b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/en_US/element/string.json new file mode 100644 index 000000000..1ee898303 --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/en_US/element/string.json @@ -0,0 +1,56 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "thread_communication", + "value": "主线程和子线程的通信" + }, + { + "name": "scenario_1", + "value": "场景一:独立的耗时任务" + }, + { + "name": "scenario_2", + "value": "场景二:多个任务执行结果统一返回" + }, + { + "name": "scenario_3", + "value": "场景三:TaskPool和主线程的即时通信" + }, + { + "name": "scenario_4", + "value": "场景四:Worker和主线程的即时通信" + }, + { + "name": "scenario_5", + "value": "场景五:子线程同步调用主线程的接口" + }, + { + "name": "load_image", + "value": "加载图片" + }, + { + "name": "percent_100", + "value": "100%" + }, + { + "name": "change_image_number", + "value": "将图片变成4个" + }, + { + "name": "process_success", + "value": "子线程任务已执行完,共加载图片:" + } + ] +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/zh_CN/element/string.json b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/zh_CN/element/string.json new file mode 100644 index 000000000..c22b3df4b --- /dev/null +++ b/code/Performance/PerformanceLibrary/feature/ThreadCommunication/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,56 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "thread_communication", + "value": "主线程和子线程的通信" + }, + { + "name": "scenario_1", + "value": "场景一:独立的耗时任务" + }, + { + "name": "scenario_2", + "value": "场景二:多个任务执行结果统一返回" + }, + { + "name": "scenario_3", + "value": "场景三:TaskPool和主线程的即时通信" + }, + { + "name": "scenario_4", + "value": "场景四:Worker和主线程的即时通信" + }, + { + "name": "scenario_5", + "value": "场景五:子线程同步调用主线程的接口" + }, + { + "name": "load_image", + "value": "加载图片" + }, + { + "name": "percent_100", + "value": "100%" + }, + { + "name": "change_image_number", + "value": "将图片变成4个" + }, + { + "name": "process_success", + "value": "子线程任务已执行完,共加载图片:" + } + ] +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/oh-package.json5 b/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/oh-package.json5 index d9e126bfc..438da4f72 100644 --- a/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/oh-package.json5 +++ b/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/oh-package.json5 @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2023 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. + */ + { "license": "Apache-2.0", "devDependencies": {}, diff --git a/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/src/main/ets/utils/TreadUtil.ets b/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/src/main/ets/utils/TreadUtil.ets index a3ab45181..6ed5814c9 100644 --- a/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/src/main/ets/utils/TreadUtil.ets +++ b/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/src/main/ets/utils/TreadUtil.ets @@ -37,11 +37,11 @@ export async function pixelMapProcessByTaskPool(pixelMap: image.PixelMap, lastAd taskPoolGroup.addTask(createImageTask(arrayBufferSlice, lastAdjustData, currentAdjustData, isParamsByTransfer)); } let start: number = new Date().getTime(); - taskpool.execute(taskPoolGroup).then((data: ArrayBuffer[]) => { + taskpool.execute(taskPoolGroup).then((data: Object[]) => { if (callback !== undefined) { - let end : number = new Date().getTime(); - AppStorage.set('timeCost', util.format('%s s', ((end - start) / 60).toFixed(2).toString())); - callback(concatenateArrayBuffers(data)); + let end: number = new Date().getTime(); + AppStorage.set('timeCost', util.format('%s s', ((end - start) / 1000).toFixed(2).toString())); + callback(concatenateArrayBuffers(data as ArrayBuffer[])); } }).catch((e: BusinessError) => { Logger.error(e.message); diff --git a/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/src/main/ets/view/AdjustImageView.ets b/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/src/main/ets/view/AdjustImageView.ets index 7c5420ab5..fb8b11111 100644 --- a/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/src/main/ets/view/AdjustImageView.ets +++ b/code/Performance/PerformanceLibrary/feature/ThreadDataTransfer/src/main/ets/view/AdjustImageView.ets @@ -74,7 +74,7 @@ struct SliderCustom { step: CommonConstants.SLIDER_STEP, min: this.min, max: this.max - }) + }).id('thread_transfer_data_slider') .trackColor(Color.White) .width($r('app.string.layout_80_percent')) .showSteps(true) diff --git a/code/Performance/PerformanceLibrary/feature/WaterFlow/src/main/ets/pages/WaterFlowDataSource.ets b/code/Performance/PerformanceLibrary/feature/WaterFlow/src/main/ets/pages/WaterFlowDataSource.ets index ddd63b521..aea987603 100644 --- a/code/Performance/PerformanceLibrary/feature/WaterFlow/src/main/ets/pages/WaterFlowDataSource.ets +++ b/code/Performance/PerformanceLibrary/feature/WaterFlow/src/main/ets/pages/WaterFlowDataSource.ets @@ -39,28 +39,28 @@ export class WaterFlowDataSource implements IDataSource { // 通知控制器数据增加 notifyDataAdd(index: number): void { this.listeners.forEach(listener => { - listener.onDataAdded(index) + listener.onDataAdd(index) }) } // 通知控制器数据变化 notifyDataChange(index: number): void { this.listeners.forEach(listener => { - listener.onDataChanged(index) + listener.onDataChange(index) }) } // 通知控制器数据删除 notifyDataDelete(index: number): void { this.listeners.forEach(listener => { - listener.onDataDeleted(index) + listener.onDataDelete(index) }) } // 通知控制器数据位置变化 notifyDataMove(from: number, to: number): void { this.listeners.forEach(listener => { - listener.onDataMoved(from, to) + listener.onDataMove(from, to) }) } diff --git a/code/Performance/PerformanceLibrary/feature/nativeThreadsCallJS/build-profile.json5 b/code/Performance/PerformanceLibrary/feature/nativeThreadsCallJS/build-profile.json5 index 2cc61a533..d5b6ebcdd 100644 --- a/code/Performance/PerformanceLibrary/feature/nativeThreadsCallJS/build-profile.json5 +++ b/code/Performance/PerformanceLibrary/feature/nativeThreadsCallJS/build-profile.json5 @@ -19,7 +19,8 @@ "externalNativeOptions": { "path": "./src/main/cpp/CMakeLists.txt", "arguments": "", - "cppFlags": "" + "cppFlags": "", + "abiFilters": ["armeabi-v7a"] }, }, "buildOptionSet": [ diff --git a/code/Performance/PerformanceLibrary/oh-package-lock.json5 b/code/Performance/PerformanceLibrary/oh-package-lock.json5 index 36d04f1d2..17c8ea40d 100644 --- a/code/Performance/PerformanceLibrary/oh-package-lock.json5 +++ b/code/Performance/PerformanceLibrary/oh-package-lock.json5 @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + { "lockfileVersion": 1, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/build-profile.json5 b/code/Performance/PerformanceLibrary/product/phone/entry/build-profile.json5 index bc2a7a25c..1a5affb09 100644 --- a/code/Performance/PerformanceLibrary/product/phone/entry/build-profile.json5 +++ b/code/Performance/PerformanceLibrary/product/phone/entry/build-profile.json5 @@ -15,6 +15,11 @@ { "apiType": "stageMode", "buildOption": { + "sourceOption": { + "workers": [ + "./src/main/ets/pages/ThreadCommunication/workers/Worker.ts" + ] + } }, "targets": [ { diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/oh-package.json5 b/code/Performance/PerformanceLibrary/product/phone/entry/oh-package.json5 index 646801b60..3de1873cf 100644 --- a/code/Performance/PerformanceLibrary/product/phone/entry/oh-package.json5 +++ b/code/Performance/PerformanceLibrary/product/phone/entry/oh-package.json5 @@ -23,9 +23,10 @@ "dependencies": { "@ohos/backgroundTask": "file:../../../feature/backgroundTask", "@ohos/grid": "file:../../../feature/grid", - "@ohos/webPerformance": "file:../../../feature/webPerformance", - "@ohos/nativethreadscalljs": "file:../../../feature/nativeThreadsCallJS", "@ohos/staticImport": "file:../../../feature/staticImport", + "@ohos/ThreadCommunication": "file:../../../feature/ThreadCommunication", + "@ohos/nativethreadscalljs": "file:../../../feature/nativeThreadsCallJS", + "@ohos/webPerformance": "file:../../../feature/webPerformance", "@ohos/ifOrVisibility": "file:../../../feature/ifOrVisibility", "@ohos/smartPerfEditor": "file:../../../feature/smartPerfEditor", "@ohos/hiDumper": "file:../../../feature/hiDumper", diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/model/MockData.ets b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/model/MockData.ets index b82e2cf26..9a30ad758 100644 --- a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/model/MockData.ets +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/model/MockData.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -73,6 +73,10 @@ export let performanceTypeArray: Array = [ uri: 'pages/nativeThreadsCallJS/NativeThreadsCallJS' }, { + name: 'ThreadCommunication', + uri: 'pages/ThreadCommunication/ThreadCommunicationHomePage' + }, + } name: 'WebPerformance', uri: 'pages/webPerformance/WebHomePage' } diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/IndependentTaskPage.ets b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/IndependentTaskPage.ets new file mode 100644 index 000000000..a352b7327 --- /dev/null +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/IndependentTaskPage.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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 { IndependentTask } from '@ohos/ThreadCommunication'; + +@Entry +@Component +struct IndependentTaskPage { + build() { + Column() { + IndependentTask() + } + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/MultiTaskPage.ets b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/MultiTaskPage.ets new file mode 100644 index 000000000..5ba975833 --- /dev/null +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/MultiTaskPage.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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 { MultiTask } from '@ohos/ThreadCommunication'; + +@Entry +@Component +struct MultiTaskPage { + build() { + Column() { + MultiTask() + } + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/TaskSendDataUsagePage.ets b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/TaskSendDataUsagePage.ets new file mode 100644 index 000000000..e1f16315e --- /dev/null +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/TaskSendDataUsagePage.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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 { TaskSendDataUsage } from '@ohos/ThreadCommunication'; + +@Entry +@Component +struct TaskSendDataUsagePage { + build() { + Column() { + TaskSendDataUsage() + } + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/ThreadCommunicationHomePage.ets b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/ThreadCommunicationHomePage.ets new file mode 100644 index 000000000..9fc5f8ec5 --- /dev/null +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/ThreadCommunicationHomePage.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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 { ThreadCommunicationHomePage } from '@ohos/ThreadCommunication'; + +@Entry +@Component +struct ThreadCommunicationPage { + build() { + Column() { + ThreadCommunicationHomePage() + } + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/WorkerCallGlobalUsagePage.ets b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/WorkerCallGlobalUsagePage.ets new file mode 100644 index 000000000..968cf391e --- /dev/null +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/WorkerCallGlobalUsagePage.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 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 { WorkerCallGlobalUsage } from '@ohos/ThreadCommunication'; +import worker from '@ohos.worker'; + +const workerInstance = new worker.ThreadWorker("entry/ets/pages/ThreadCommunication/workers/Worker.ts"); + +@Entry +@Component +struct WorkerCallGlobalUsagePage { + build() { + Column() { + WorkerCallGlobalUsage({workerInstance:workerInstance}); + } + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/WorkerUsagePage.ets b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/WorkerUsagePage.ets new file mode 100644 index 000000000..cff442f30 --- /dev/null +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/WorkerUsagePage.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 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 { WorkerUsage } from '@ohos/ThreadCommunication'; +import worker from '@ohos.worker'; + +const workerInstance = new worker.ThreadWorker("entry/ets/pages/ThreadCommunication/workers/Worker.ts"); + +@Entry +@Component +struct WorkerUsagePage { + build() { + Column() { + WorkerUsage({ workerInstance: workerInstance }); + } + } +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/workers/Worker.ts b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/workers/Worker.ts new file mode 100644 index 000000000..0c9ff6fd0 --- /dev/null +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/ets/pages/ThreadCommunication/workers/Worker.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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 worker, { MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker'; + +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; +workerPort.onmessage = (e: MessageEvents): void => { + if (typeof e.data === "string") { + try { + // 调用方法无入参 + let res: string = workerPort.callGlobalCallObjectMethod("picData", "setUp", 0) as string; + console.error("worker: ", res); + } catch (error) { + // 异常处理 + console.error("worker: error code is " + error.code + " error message is " + error.message); + } + } else if (e.data instanceof Array) { + workerPort.postMessage(e.data.slice(0, 4)); + } + +} \ No newline at end of file diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/resources/base/profile/main_pages.json b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/resources/base/profile/main_pages.json index f3e95c535..4e7061cc7 100644 --- a/code/Performance/PerformanceLibrary/product/phone/entry/src/main/resources/base/profile/main_pages.json +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/main/resources/base/profile/main_pages.json @@ -42,6 +42,12 @@ "pages/DFXStateManagement/DFXStateManagementPage", "pages/DFXStateManagement/DFXStateBeforeOptimizationPage", "pages/DFXStateManagement/DFXStateAfterOptimizationPage", + "pages/ThreadCommunication/ThreadCommunicationHomePage", + "pages/ThreadCommunication/IndependentTaskPage", + "pages/ThreadCommunication/MultiTaskPage", + "pages/ThreadCommunication/TaskSendDataUsagePage", + "pages/ThreadCommunication/WorkerUsagePage", + "pages/ThreadCommunication/WorkerCallGlobalUsagePage", "pages/webPerformance/WebHomePage", "pages/webPerformance/WebBrowserPage", "pages/webPerformance/WebInitializedPage", diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/ohosTest/ets/test/Ability.test.ets b/code/Performance/PerformanceLibrary/product/phone/entry/src/ohosTest/ets/test/Ability.test.ets index 80dbc2cc2..2e1807a89 100644 --- a/code/Performance/PerformanceLibrary/product/phone/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/ohosTest/ets/test/Ability.test.ets @@ -603,10 +603,12 @@ export default function abilityTest() { await btnAccept.click(); await driver.delayMs(3000); // 获取定位权限 - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.permission_while_use')))); let locAcceptBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.permission_while_use')))); - await locAcceptBtn.click(); - await driver.delayMs(1000); + await driver.delayMs(500); + if (locAcceptBtn !== null) { + await locAcceptBtn.click(); + await driver.delayMs(1000); + } // 点击开启定位服务 let startLocationBtn: Component = await driver.findComponent(ON.text('开启定位服务')); await driver.delayMs(500); @@ -766,6 +768,169 @@ export default function abilityTest() { done(); }) + /** + * 主线程和子线程通信 + */ + it(BUNDLE + "ThreadCommunication_001", 1, async (done: Function) => { + Logger.info(TAG, `${BUNDLE}ThreadCommunication_001 begin`); + let driver: Driver = Driver.create(); + await driver.delayMs(500); + await driver.swipe(10, 800, 10, 0, 600); + await driver.delayMs(500); + let threadHome: Component = await driver.findComponent(ON.text('ThreadCommunication')); + await driver.delayMs(500); + await threadHome.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.thread_communication')))); + await driver.delayMs(200); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_1')))); + await driver.delayMs(200); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_2')))); + await driver.delayMs(200); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_3')))); + await driver.delayMs(200); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_4')))); + await driver.delayMs(200); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_5')))); + await driver.delayMs(200); + Logger.info(TAG, `${BUNDLE}ThreadCommunication_001 end`); + done(); + }) + + /** + * 独立的耗时任务测试用例 + */ + it(BUNDLE + "ThreadCommunication_002", 1, async (done: Function) => { + Logger.info(TAG, `${BUNDLE}ThreadCommunication_002 begin`); + let driver: Driver = Driver.create(); + await driver.delayMs(500); + let scenario: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_1')))); + await driver.delayMs(500); + await scenario.click(); + await driver.delayMs(1000); + let loadImage: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.load_image')))); + await driver.delayMs(500); + await loadImage.click(); + await driver.delayMs(1000); + await driver.pressBack(); + Logger.info(TAG, `${BUNDLE}ThreadCommunication_002 end`); + done(); + }) + + /** + * 多个任务执行结果统一返回测试用例 + */ + it(BUNDLE + "ThreadCommunication_003", 1, async (done: Function) => { + Logger.info(TAG, `${BUNDLE}ThreadCommunication_003 begin`); + let driver: Driver = Driver.create(); + await driver.delayMs(500); + let scenario: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_2')))); + await driver.delayMs(500); + await scenario.click(); + await driver.delayMs(1000); + let loadImage: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.load_image')))); + await driver.delayMs(500); + await loadImage.click(); + await driver.delayMs(1000); + await driver.pressBack(); + Logger.info(TAG, `${BUNDLE}ThreadCommunication_003 end`); + done(); + }) + + /** + * TaskPool和主线程的即时通信测试用例 + */ + it(BUNDLE + "ThreadCommunication_004", 1, async (done: Function) => { + Logger.info(TAG, `${BUNDLE}ThreadCommunication_004 begin`); + let driver: Driver = Driver.create(); + await driver.delayMs(500); + let scenario: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_3')))); + await driver.delayMs(500); + await scenario.click(); + await driver.delayMs(1000); + let loadImage: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.load_image')))); + await driver.delayMs(500); + await loadImage.click(); + await driver.delayMs(1000); + await driver.pressBack(); + Logger.info(TAG, `${BUNDLE}ThreadCommunication_004 end`); + done(); + }) + + /** + * Worker和主线程的即时通信测试用例 + */ + it(BUNDLE + "ThreadCommunication_005", 1, async (done: Function) => { + Logger.info(TAG, `${BUNDLE}ThreadCommunication_005 begin`); + let driver: Driver = Driver.create(); + await driver.delayMs(500); + let scenario: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_4')))); + await driver.delayMs(500); + await scenario.click(); + await driver.delayMs(1000); + let loadImage: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.change_image_number')))); + await driver.delayMs(500); + await loadImage.click(); + await driver.delayMs(1000); + await driver.pressBack(); + Logger.info(TAG, `${BUNDLE}ThreadCommunication_005 end`); + done(); + }) + + /** + * 子线程同步调用主线程的接口测试用例 + */ + it(BUNDLE + "ThreadCommunication_006", 1, async (done: Function) => { + Logger.info(TAG, `${BUNDLE}ThreadCommunication_006 begin`); + let driver: Driver = Driver.create(); + await driver.delayMs(500); + let scenario: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.scenario_5')))); + await driver.delayMs(500); + await scenario.click(); + await driver.delayMs(1000); + let loadImage: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.load_image')))); + await driver.delayMs(500); + await loadImage.click(); + await driver.delayMs(1000); + await driver.pressBack(); + await driver.delayMs(500); + await driver.pressBack(); + Logger.info(TAG, `${BUNDLE}ThreadCommunication_006 end`); + done(); + }) + /** * 点击WebPerformance按钮,进入Web首页面 */ @@ -832,6 +997,48 @@ export default function abilityTest() { }) /** + * 线程间大数据传输测试用例 + */ + it(BUNDLE + "ThreadDataTransfer_001", 1, async (done: Function) => { + Logger.info(TAG, `${BUNDLE}ThreadDataTransfer_001 begin`); + let driver: Driver = Driver.create(); + await driver.delayMs(500); + await driver.swipe(10, 800, 10, 0, 600); + await driver.delayMs(500); + let threadDataTransfer: Component = await driver.findComponent(ON.text('ThreadDataTransfer')); + await driver.delayMs(500); + await threadDataTransfer.click(); + await driver.delayMs(500); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.saturation')))); + await driver.delayMs(200); + await driver.assertComponentExist(ON.text(getContext().resourceManager.getStringSync($r('app.string.task_num')))); + await driver.delayMs(200); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.pass_params')))); + await driver.delayMs(200); + let transferData: Component = await driver.findComponent(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.start_transfer')))); + await driver.delayMs(200); + await driver.assertComponentExist(ON.text(getContext() + .resourceManager + .getStringSync($r('app.string.running_time')))); + await driver.delayMs(200); + await transferData.click(); + await driver.delayMs(500); + let slider: Component = await driver.findComponent(ON.id('thread_transfer_data_slider')); + await driver.delayMs(500); + await slider.click(); + await driver.delayMs(70000); + await driver.pressBack(); + await driver.delayMs(500); + Logger.info(TAG, `${BUNDLE}ThreadDataTransfer_001 end`); + done(); + } + * DFXStateManagement 查看内容 */ it(BUNDLE + "DFXStateManagement", 2, async (done: Function) => { diff --git a/code/Performance/PerformanceLibrary/product/phone/entry/src/ohosTest/resources/base/element/string.json b/code/Performance/PerformanceLibrary/product/phone/entry/src/ohosTest/resources/base/element/string.json index 7d902f5a9..aae8876c2 100644 --- a/code/Performance/PerformanceLibrary/product/phone/entry/src/ohosTest/resources/base/element/string.json +++ b/code/Performance/PerformanceLibrary/product/phone/entry/src/ohosTest/resources/base/element/string.json @@ -12,14 +12,14 @@ "name": "TestAbility_label", "value": "test label" }, - { - "name": "MemoryShared", - "value": "MemoryShared" - }, { "name": "permission_while_use", "value": "仅使用期间允许" }, + { + "name": "MemoryShared", + "value": "MemoryShared" + }, { "name": "atomic_operation", "value": "原子操作对比" @@ -48,6 +48,58 @@ "name": "write_success", "value": "写入文件成功" }, + { + "name": "thread_communication", + "value": "主线程和子线程的通信" + }, + { + "name": "scenario_1", + "value": "场景一:独立的耗时任务" + }, + { + "name": "scenario_2", + "value": "场景二:多个任务执行结果统一返回" + }, + { + "name": "scenario_3", + "value": "场景三:TaskPool和主线程的即时通信" + }, + { + "name": "scenario_4", + "value": "场景四:Worker和主线程的即时通信" + }, + { + "name": "scenario_5", + "value": "场景五:子线程同步调用主线程的接口" + }, + { + "name": "load_image", + "value": "加载图片" + }, + { + "name": "change_image_number", + "value": "将图片变成4个" + }, + { + "name": "saturation", + "value": "饱和度" + }, + { + "name": "task_num", + "value": "任务数" + }, + { + "name": "pass_params", + "value": "传参方式" + }, + { + "name": "start_transfer", + "value": "通过转移方式传参" + }, + { + "name": "running_time", + "value": "运行时间:" + }, { "name": "web_uninitialized", "value": "常规Web首页"