From 50cede16861f8509bff94740ea615a977b0acb74 Mon Sep 17 00:00:00 2001 From: zhuhaokun Date: Wed, 13 Sep 2023 17:34:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8trace=E6=89=93=E7=82=B9?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuhaokun --- .../chatlist/src/main/ets/pages/ChatDetailPage.ets | 12 +++++++++++- .../chatlist/src/main/ets/pages/ChatListPage.ets | 5 +++++ .../chatlist/src/main/ets/utils/DataFactory.ets | 9 +++++++++ .../entry/src/main/ets/pages/FriendsMomentsPage.ets | 10 +++++++++- .../phone/entry/src/main/ets/pages/FriendsPage.ets | 9 +++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/code/Solutions/IM/Chat/features/chatlist/src/main/ets/pages/ChatDetailPage.ets b/code/Solutions/IM/Chat/features/chatlist/src/main/ets/pages/ChatDetailPage.ets index beb473a02..d5aedd6cd 100644 --- a/code/Solutions/IM/Chat/features/chatlist/src/main/ets/pages/ChatDetailPage.ets +++ b/code/Solutions/IM/Chat/features/chatlist/src/main/ets/pages/ChatDetailPage.ets @@ -20,8 +20,14 @@ import router from '@ohos.router'; import { ImageTextMessage, FileMessage } from '../viewmodel/MsgBase'; import image from '@ohos.multimedia.image'; import Constants from '../utils/Constants'; +import hiTraceMeter from '@ohos.hiTraceMeter'; -@Previewgit +const ABOUT_TO_APPEAR_TRACE: string = 'ChatDetailPage_AboutToAppear_HiTrace'; +const ABOUT_TO_APPEAR_TRACE_ID: number = 1; // aboutToAppear 中使用的 taskId +const MAKE_DATA_LOCAL_TRACE: string = 'ChatDetailPage_MakeDataLocal_HiTrace'; +const MAKE_DATA_LOCAL_TRACE_ID: number = 2; // makeDataLocal 中使用的 taskId + +@Preview @Component // 聊天页面 export struct ChatDetailPage { @@ -151,6 +157,7 @@ export struct ChatDetailPage { // 设定本地聊天内容 async makeDataLocal() { + hiTraceMeter.startTrace(MAKE_DATA_LOCAL_TRACE, MAKE_DATA_LOCAL_TRACE_ID); let chatDetailMsgList = await getMessageListFromJSON(); let todayDate = new Date(); let userMyself = new ChatContact('1', $r('app.string.myself')); @@ -184,10 +191,13 @@ export struct ChatDetailPage { let lastMsg = new TextMessage(this.lastMsg); this.chatDetailData.pushData(new MessageBase('1000', userFriend, userMyself, lastMsg, 1, todayDate.getSeconds())); this.msgLength = this.chatDetailData.totalCount(); + hiTraceMeter.finishTrace(MAKE_DATA_LOCAL_TRACE, MAKE_DATA_LOCAL_TRACE_ID); } async aboutToAppear() { + hiTraceMeter.startTrace(ABOUT_TO_APPEAR_TRACE, ABOUT_TO_APPEAR_TRACE_ID); this.makeDataLocal(); + hiTraceMeter.finishTrace(ABOUT_TO_APPEAR_TRACE, ABOUT_TO_APPEAR_TRACE_ID); } } diff --git a/code/Solutions/IM/Chat/features/chatlist/src/main/ets/pages/ChatListPage.ets b/code/Solutions/IM/Chat/features/chatlist/src/main/ets/pages/ChatListPage.ets index 692ff8eb4..746c6f31d 100644 --- a/code/Solutions/IM/Chat/features/chatlist/src/main/ets/pages/ChatListPage.ets +++ b/code/Solutions/IM/Chat/features/chatlist/src/main/ets/pages/ChatListPage.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import hiTraceMeter from '@ohos.hiTraceMeter'; import { makeDataLocal, makeDataList } from '../utils/DataFactory'; import Constants from '../utils/Constants'; import { ChatModel } from '../viewmodel/MsgBase'; @@ -26,6 +27,8 @@ const TAG: string = 'ChatListDisplayView'; const ID_SEARCH: string = "search"; // 删除item后,下方的item顶上来的动画的播放时间 const DELETE_ANIMATION_DURATION: number = 500; +const ABOUT_TO_APPEAR_TRACE: string = 'ChatListPage_AboutToAppear_HiTrace'; +const ABOUT_TO_APPEAR_TRACE_ID: number = 3; // aboutToAppear 中使用的 taskId class Message { chatItem: ChatModel; @@ -176,7 +179,9 @@ export struct ChatListDisplayView { async aboutToAppear(): Promise { Logger.info(TAG, "ChatListPage aboutToAppear"); + hiTraceMeter.startTrace(ABOUT_TO_APPEAR_TRACE, ABOUT_TO_APPEAR_TRACE_ID); await makeDataLocal(this.chatListLazy); await makeDataList(this.chatListArray); + hiTraceMeter.finishTrace(ABOUT_TO_APPEAR_TRACE, ABOUT_TO_APPEAR_TRACE_ID); } } diff --git a/code/Solutions/IM/Chat/features/chatlist/src/main/ets/utils/DataFactory.ets b/code/Solutions/IM/Chat/features/chatlist/src/main/ets/utils/DataFactory.ets index 4e95c033f..21967975d 100644 --- a/code/Solutions/IM/Chat/features/chatlist/src/main/ets/utils/DataFactory.ets +++ b/code/Solutions/IM/Chat/features/chatlist/src/main/ets/utils/DataFactory.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +import hiTraceMeter from '@ohos.hiTraceMeter'; import util from '@ohos.util'; import Logger from './Logger'; import { ChatModel, ChatContact, FriendMoment } from '../viewmodel/MsgBase'; @@ -21,6 +22,10 @@ import Constants from './Constants'; const TAG: string = 'ChatList_DataFactory'; const MOCK_DATA_FILE_DIR: string = 'mockChatModelData.json'; +const MAKE_DATA_LOCAL_TRACE: string = 'ChatList_MakeDataLocal_HiTrace'; +const MAKE_DATA_LOCAL_TRACE_ID: number = 1; // makeDataLocal 中使用的 taskId +const MAKE_DATA_LIST_TRACE: string = 'ChatList_MakeDataList_HiTrace'; +const MAKE_DATA_LIST_TRACE_ID: number = 2; // makeDataList 中使用的 taskId class JsonObjType { MessageList: Array = new Array(); @@ -34,10 +39,12 @@ class JsonObjType { */ export async function makeDataLocal(listData: ChatListData): Promise { Logger.info(TAG, 'makeDataLocal'); + hiTraceMeter.startTrace(MAKE_DATA_LOCAL_TRACE, MAKE_DATA_LOCAL_TRACE_ID); let chatModelMockData = await getChatModelObjFromJSON(); for (let i = 0; i < Constants.DATA_MOCK_COUNT; i++) { listData.pushData(chatModelMockData[i]); } + hiTraceMeter.finishTrace(MAKE_DATA_LOCAL_TRACE, MAKE_DATA_LOCAL_TRACE_ID); } /** @@ -46,10 +53,12 @@ export async function makeDataLocal(listData: ChatListData): Promise { */ export async function makeDataList(listData: Array): Promise { Logger.info(TAG, 'makeDataList'); + hiTraceMeter.startTrace(MAKE_DATA_LIST_TRACE, MAKE_DATA_LIST_TRACE_ID); let chatModelMockData = await getChatModelObjFromJSON(); for (let i = 0; i < Constants.DATA_MOCK_COUNT; i++) { listData.push(chatModelMockData[i]); } + hiTraceMeter.finishTrace(MAKE_DATA_LIST_TRACE, MAKE_DATA_LIST_TRACE_ID); } /** diff --git a/code/Solutions/IM/Chat/products/phone/entry/src/main/ets/pages/FriendsMomentsPage.ets b/code/Solutions/IM/Chat/products/phone/entry/src/main/ets/pages/FriendsMomentsPage.ets index 1cd3a96e6..b35aa5977 100644 --- a/code/Solutions/IM/Chat/products/phone/entry/src/main/ets/pages/FriendsMomentsPage.ets +++ b/code/Solutions/IM/Chat/products/phone/entry/src/main/ets/pages/FriendsMomentsPage.ets @@ -18,9 +18,13 @@ import { ChatContact, BasicDataSource, FriendMoment } from '@ohos/chatlist'; import { getFriendMomentObjFromJSON } from '@ohos/chatlist/src/main/ets/utils/DataFactory'; import Constants from '@ohos/chatlist/src/main/ets/utils/Constants'; import Logger from '@ohos/chatlist/src/main/ets/utils/Logger'; +import hiTraceMeter from '@ohos.hiTraceMeter'; const TAG: string = 'entry_FriendsMomentsPage'; - +const ABOUT_TO_APPEAR_TRACE: string = 'FriendsPage_AboutToAppear_HiTrace'; +const ABOUT_TO_APPEAR_TRACE_ID: number = 1; // aboutToAppear 中使用的 taskId +const MAKE_LOCAL_DATA_TRACE: string = 'FriendsPage_MakeLocalData_HiTrace'; +const MAKE_LOCAL_DATA_TRACE_ID: number = 2; // makeDataLocal 中使用的 taskId @Entry @Component @@ -98,17 +102,21 @@ struct FriendsMomentsPage { } async aboutToAppear(): Promise { + hiTraceMeter.startTrace(ABOUT_TO_APPEAR_TRACE, ABOUT_TO_APPEAR_TRACE_ID); Logger.info(TAG, 'aboutToAppear'); await this.makeLocalData(); + hiTraceMeter.finishTrace(ABOUT_TO_APPEAR_TRACE, ABOUT_TO_APPEAR_TRACE_ID); } // 本地mock数据生成朋友圈数据,推到momentData里 async makeLocalData(): Promise{ Logger.info(TAG, 'makeLocalData'); + hiTraceMeter.startTrace(MAKE_LOCAL_DATA_TRACE, MAKE_LOCAL_DATA_TRACE_ID); let FriendMoment = await getFriendMomentObjFromJSON(); for (let i = 0; i < Constants.FRIEND_MOMENT_MOCK_DATA_COUNT; i++) { this.momentData.pushData(FriendMoment[i]); } + hiTraceMeter.finishTrace(MAKE_LOCAL_DATA_TRACE, MAKE_LOCAL_DATA_TRACE_ID); } } diff --git a/code/Solutions/IM/Chat/products/phone/entry/src/main/ets/pages/FriendsPage.ets b/code/Solutions/IM/Chat/products/phone/entry/src/main/ets/pages/FriendsPage.ets index f53572d58..ceb712bd2 100644 --- a/code/Solutions/IM/Chat/products/phone/entry/src/main/ets/pages/FriendsPage.ets +++ b/code/Solutions/IM/Chat/products/phone/entry/src/main/ets/pages/FriendsPage.ets @@ -19,10 +19,15 @@ import Constants from '@ohos/chatlist/src/main/ets/utils/Constants'; import PageConstants from '@ohos/chatlist/src/main/ets/utils/PageConstants'; import { getChatModelObjFromJSON } from '@ohos/chatlist/src/main/ets/utils/DataFactory'; import Logger from '@ohos/chatlist/src/main/ets/utils/Logger'; +import hiTraceMeter from '@ohos.hiTraceMeter'; const TAG: string = 'entry_FriendsPage'; const LIST_SPACE: number = 2; const LIST_INITIAL_INDEX: number = 0; +const ABOUT_TO_APPEAR_TRACE: string = 'FriendsPage_AboutToAppear_HiTrace'; +const ABOUT_TO_APPEAR_TRACE_ID: number = 1; // aboutToAppear 中使用的 taskId +const MAKE_DATA_LOCAL_TRACE: string = 'FriendsPage_MakeDataLocal_HiTrace'; +const MAKE_DATA_LOCAL_TRACE_ID:number = 2; // makeDataLocal 中使用的 taskId class FriendsPageItemType { image: string | Resource = '' @@ -104,15 +109,19 @@ export struct FriendsPage { async aboutToAppear(): Promise { Logger.info(TAG, 'aboutToAppear'); + hiTraceMeter.startTrace(ABOUT_TO_APPEAR_TRACE, ABOUT_TO_APPEAR_TRACE_ID); await this.makeDataLocal(); + hiTraceMeter.finishTrace(ABOUT_TO_APPEAR_TRACE, ABOUT_TO_APPEAR_TRACE_ID); } async makeDataLocal(): Promise { Logger.info(TAG, 'makeDataLocal'); + hiTraceMeter.startTrace(MAKE_DATA_LOCAL_TRACE, MAKE_DATA_LOCAL_TRACE_ID); let chatModelMockData = await getChatModelObjFromJSON(); for (let i = 0; i < Constants.DATA_MOCK_COUNT; i++) { this.friendsListData.pushData(chatModelMockData[i].user); } + hiTraceMeter.finishTrace(MAKE_DATA_LOCAL_TRACE, MAKE_DATA_LOCAL_TRACE_ID); } }