1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 16import { jank, JankRender, JankStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerJank'; 17jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 18 return {}; 19}); 20jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 21 return {}; 22}); 23describe('ProcedureWorkerJank Test', () => { 24 const jankData = { 25 frame: { 26 x: 20, 27 y: 20, 28 width: 100, 29 height: 100, 30 }, 31 id: 35, 32 ts: 42545, 33 dur: 2015, 34 name: '2145', 35 depth: 1, 36 jank_tag: false, 37 cmdline: 'render.test', 38 type: '1', 39 pid: 20, 40 frame_type: 'render_service', 41 src_slice: '525', 42 rs_ts: 2569, 43 rs_vsync: '2569', 44 rs_dur: 1528, 45 rs_pid: 1252, 46 rs_name: 'name', 47 gpu_dur: 2568, 48 }; 49 let render = new JankRender(); 50 51 it('ProcedureWorkerJank01', () => { 52 const canvas = document.createElement('canvas'); 53 canvas.width = 2; 54 canvas.height = 2; 55 const ctx = canvas.getContext('2d'); 56 57 const data = { 58 frame: { 59 x: 120, 60 y: 120, 61 width: 100, 62 height: 100, 63 }, 64 id: 21, 65 ts: 254151, 66 dur: 1201, 67 name: '1583', 68 depth: 6, 69 jank_tag: true, 70 cmdline: 'render.test', 71 type: '0', 72 pid: 21, 73 frame_type: 'render_service', 74 src_slice: '5', 75 rs_ts: 3, 76 rs_vsync: '2561', 77 rs_dur: 965, 78 rs_pid: 320, 79 rs_name: 'name', 80 gpu_dur: 102, 81 }; 82 expect(JankStruct.draw(ctx!, data, 2)).toBeUndefined(); 83 }); 84 85 it('ProcedureWorkerJank02', () => { 86 const canvas = document.createElement('canvas'); 87 canvas.width = 1; 88 canvas.height = 1; 89 const ctx = canvas.getContext('2d'); 90 expect(JankStruct.draw(ctx!, jankData, 2)).toBeUndefined(); 91 }); 92 93 it('ProcedureWorkerJank09', function () { 94 let jankNode = [ 95 { 96 frame: { 97 x: 9, 98 y: 10, 99 width: 21, 100 height: 22, 101 }, 102 startNS: 44, 103 length: 41, 104 height: 422, 105 }, 106 ]; 107 let frame = { 108 x: 220, 109 y: 120, 110 width: 444, 111 height: 4, 112 }; 113 let list = [ 114 { 115 frame: { 116 x: 7, 117 y: 75, 118 width: 2, 119 height: 12, 120 }, 121 startNS: 45, 122 length: 5, 123 height: 32, 124 }, 125 ]; 126 jank(list, jankNode, 1, 1, 1, frame, true); 127 }); 128 129 it('ProcedureWorkerJank10', function () { 130 let node = [ 131 { 132 frame: { 133 x: 90, 134 y: 80, 135 width: 230, 136 height: 300, 137 }, 138 startNS: 800, 139 length: 100, 140 height: 92, 141 }, 142 ]; 143 let frame = { 144 x: 980, 145 y: 980, 146 width: 400, 147 height: 1440, 148 }; 149 let list = [ 150 { 151 frame: { 152 x: 45, 153 y: 50, 154 width: 150, 155 height: 140, 156 }, 157 startNS: 20, 158 length: 72, 159 height: 27, 160 }, 161 ]; 162 jank(list, node, 1, 1, 1, frame, false); 163 }); 164 165 it('ProcedureWorkerJank11', () => { 166 let node = { 167 frame: { 168 x: 65, 169 y: 20, 170 width: 99, 171 height: 330, 172 }, 173 startNS: 200, 174 length: 1, 175 height: 90, 176 startTime: 0, 177 dur: 31, 178 }; 179 expect(JankStruct.setJankFrame(node, 1, 1, 1, 10, { width: 10 })).toBeUndefined(); 180 }); 181 182 it('ProcedureWorkerJank12', () => { 183 let canvas = document.createElement('canvas') as HTMLCanvasElement; 184 let context = canvas.getContext('2d'); 185 TraceRow.range = { 186 startNS: 3206163251057, 187 endNS: 3215676817201, 188 totalNS: 9513566144, 189 }; 190 new JankRender().renderMainThread( 191 { 192 context: context!, 193 useCache: false, 194 type: `expected_frame_timeline_slice`, 195 }, 196 { 197 dataList: [ 198 { 199 id: 17, 200 frame_type: 'frameTimes', 201 ipid: 34, 202 name: 36331, 203 app_dur: 16616555, 204 dur: 33554127, 205 ts: 15037892, 206 type: 61, 207 flag: null, 208 pid: 3467, 209 cmdline: 'com.huawei', 210 rs_ts: 31666322, 211 rs_vsync: 28763, 212 rs_dur: 16617667, 213 rs_ipid: 555, 214 rs_pid: 1253, 215 rs_name: '', 216 depth: 0, 217 frame: { 218 x: 12, 219 y: 10, 220 width: 45, 221 height: 40, 222 }, 223 }, 224 { 225 id: 41, 226 frame_type: 'frame', 227 ipid: 81, 228 name: 36612, 229 app_dur: 16616234, 230 dur: 33233432, 231 ts: 31656235, 232 type: 25, 233 flag: null, 234 pid: 3435, 235 cmdline: 'com.wx', 236 rs_ts: 48273526, 237 rs_vsync: 25524, 238 rs_dur: 16556797, 239 rs_ipid: 325, 240 rs_pid: 1232, 241 rs_name: 'render', 242 depth: 13, 243 frame: { 244 x: 43, 245 y: 220, 246 width: 15, 247 height: 210, 248 }, 249 }, 250 { 251 id: 14, 252 frame_type: 'time', 253 ipid: 34, 254 name: 33693, 255 app_dur: 1661327, 256 dur: 33236526, 257 ts: 48256426, 258 type: 41, 259 flag: null, 260 pid: 3420, 261 cmdline: 'com.huawei', 262 rs_ts: 68320255, 263 rs_vsync: 28435, 264 rs_dur: 16616797, 265 rs_ipid: 35, 266 rs_pid: 1563, 267 rs_name: 'service', 268 depth: 30, 269 frame: { 270 x: 63, 271 y: 50, 272 width: 355, 273 height: 230, 274 }, 275 }, 276 ], 277 dataListCache: [ 278 { 279 id: 17, 280 frame_type: 'frameTime', 281 ipid: 84, 282 name: 36691, 283 app_dur: 16616797, 284 dur: 33567127, 285 ts: 15038992, 286 type: 81, 287 flag: null, 288 pid: 3420, 289 cmdline: 'com.huawei.wx', 290 rs_ts: 31656322, 291 rs_vsync: 28323, 292 rs_dur: 11116797, 293 rs_ipid: 25, 294 rs_pid: 1263, 295 rs_name: 'render_service', 296 depth: 10, 297 frame: { 298 x: 2, 299 y: 0, 300 width: 5, 301 height: 40, 302 }, 303 }, 304 { 305 id: 11, 306 frame_type: 'frameTime', 307 ipid: 84, 308 name: 36692, 309 app_dur: 16616797, 310 dur: 33277901, 311 ts: 31657422, 312 type: 1, 313 flag: null, 314 pid: 3420, 315 cmdline: 'com.huawei.wx', 316 rs_ts: 48273426, 317 rs_vsync: 28324, 318 rs_dur: 16616797, 319 rs_ipid: 275, 320 rs_pid: 1263, 321 rs_name: 'render_service', 322 depth: 17, 323 frame: { 324 x: 47, 325 y: 20, 326 width: 5, 327 height: 20, 328 }, 329 }, 330 { 331 id: 173, 332 frame_type: 'frameTime', 333 ipid: 84, 334 name: 76693, 335 app_dur: 16616797, 336 dur: 33233626, 337 ts: 48273426, 338 type: 1, 339 flag: null, 340 pid: 3420, 341 cmdline: 'com.huawei.wx', 342 rs_ts: 64890255, 343 rs_vsync: 28325, 344 rs_dur: 16616797, 345 rs_ipid: 25, 346 rs_pid: 1783, 347 rs_name: 'render_service', 348 depth: 0, 349 frame: { 350 x: 6, 351 y: 70, 352 width: 5, 353 height: 20, 354 }, 355 }, 356 ], 357 frame: { x: 7, y: 76, width: 610, height: 106 } 358 } 359 ); 360 }); 361}); 362