* 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.
*/
(self as unknown as Worker).onmessage = (e: MessageEvent): void => {
orgnazitionStcData(e.data);
}
function orgnazitionStcData(
args: {
leftNs: number,
rightNs: number,
recordStartNS: number,
schedTaskData: unknown[]
}
): void {
let group: unknown = {};
args.schedTaskData.forEach((task) => {
let item = {
pid: task.pid,
tid: task.tid,
count: 1,
startTime: task.startTime,
processName: '',
threadName: '',
interval: task.interval,
currMono: task.curr_mono,
expireMono: task.expire_mono
};
if (group[`${task.pid}`]) {
setTaskData(group,item);
} else {
group[`${task.pid}`] = {
pid: task.pid,
count: 1,
processName: '',
children: [
{
pid: task.pid,
tid: task.tid,
count: 1,
processName: '',
threadName: '',
}
]
}
}
});
let resultList = Object.values(group);
self.postMessage(resultList);
}
function setTaskData(group: unknown, item: unknown) {
let process = group[`${item.pid}`];
process.count += 1;
let thread = process.children.find((child) => child.tid === item.tid);
if (thread) {
thread.count += 1;
} else {
process.children.push({
pid: item.pid,
tid: item.tid,
count: 1,
processName: '',
threadName: '',
})
}
}