列表trace打点功能

Signed-off-by: zhuhaokun <zhuhaokun1@huawei.com>
This commit is contained in:
zhuhaokun 2023-09-13 17:34:43 +08:00
parent 129196318a
commit 50cede1686
5 changed files with 43 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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<void> {
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);
}
}

View File

@ -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<string> = new Array<string>();
@ -34,10 +39,12 @@ class JsonObjType {
*/
export async function makeDataLocal(listData: ChatListData): Promise<void> {
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<void> {
*/
export async function makeDataList(listData: Array<ChatModel>): Promise<void> {
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);
}
/**

View File

@ -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<void> {
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<void>{
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);
}
}

View File

@ -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<void> {
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<void> {
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);
}
}