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 */ 15 16import { 17 PerfFile, 18 PerfThread, 19 PerfCallChain, 20 PerfCallChainMerageData, 21 PerfSample, 22 PerfStack, 23 PerfCall, 24 PerfCmdLine, 25} from '../../../src/trace/bean/PerfProfile'; 26 27jest.mock('../../../src/trace/component/trace/base/TraceRow', () => { 28 return {}; 29}); 30 31describe('PerfProfile Test', () => { 32 let perfFile = new PerfFile(); 33 let perfThread = new PerfThread(); 34 let perfCallChain = new PerfCallChain(); 35 let perfCallChainMerageData = new PerfCallChainMerageData(); 36 let perfSample = new PerfSample(); 37 let perfStack = new PerfStack(); 38 let perfCall = new PerfCall(); 39 let perfCmdLine = new PerfCmdLine(); 40 41 it('PerfFile Test', function () { 42 perfFile = { 43 fileId: 0, 44 symbol: 'symbol', 45 path: 'path', 46 fileName: 'fileName', 47 }; 48 49 expect(perfFile).not.toBeUndefined(); 50 expect(perfFile).toMatchInlineSnapshot( 51{ 52 fileId: expect.any(Number), 53 symbol: expect.any(String), 54 path: expect.any(String), 55 fileName: expect.any(String) }, ` 56{ 57 "fileId": Any<Number>, 58 "fileName": Any<String>, 59 "path": Any<String>, 60 "symbol": Any<String>, 61} 62`); 63 }); 64 65 it('PerfThread Test', function () { 66 perfThread = { 67 tid: 0, 68 pid: 0, 69 threadName: 'threadName', 70 processName: 'processName', 71 }; 72 73 expect(perfThread).not.toBeUndefined(); 74 expect(perfThread).toMatchInlineSnapshot( 75{ 76 tid: expect.any(Number), 77 pid: expect.any(Number), 78 threadName: expect.any(String), 79 processName: expect.any(String) }, ` 80{ 81 "pid": Any<Number>, 82 "processName": Any<String>, 83 "threadName": Any<String>, 84 "tid": Any<Number>, 85} 86`); 87 }); 88 89 it('perfCallChain Test', function () { 90 perfCallChain = { 91 tid: 0, 92 pid: 0, 93 name: 'name', 94 fileName: 'fileName', 95 threadState: 'threadState', 96 startNS: 0, 97 dur: 0, 98 sampleId: 0, 99 callChainId: 0, 100 vaddrInFile: 0, 101 fileId: 0, 102 symbolId: 0, 103 parentId: 'parentId', 104 id: 'id', 105 topDownMerageId: 'topDownMerageId', 106 topDownMerageParentId: 'topDownMerageParentId', 107 bottomUpMerageId: 'bottomUpMerageId', 108 bottomUpMerageParentId: 'bottomUpMerageParentId', 109 depth: 0, 110 }; 111 112 expect(perfCallChain).not.toBeUndefined(); 113 expect(perfCallChain).toMatchInlineSnapshot( 114{ 115 tid: expect.any(Number), 116 pid: expect.any(Number), 117 name: expect.any(String), 118 fileName: expect.any(String), 119 threadState: expect.any(String), 120 startNS: expect.any(Number), 121 dur: expect.any(Number), 122 sampleId: expect.any(Number), 123 callChainId: expect.any(Number), 124 vaddrInFile: expect.any(Number), 125 fileId: expect.any(Number), 126 symbolId: expect.any(Number), 127 parentId: expect.any(String), 128 id: expect.any(String), 129 topDownMerageId: expect.any(String), 130 topDownMerageParentId: expect.any(String), 131 bottomUpMerageId: expect.any(String), 132 bottomUpMerageParentId: expect.any(String), 133 depth: expect.any(Number) }, ` 134{ 135 "bottomUpMerageId": Any<String>, 136 "bottomUpMerageParentId": Any<String>, 137 "callChainId": Any<Number>, 138 "depth": Any<Number>, 139 "dur": Any<Number>, 140 "fileId": Any<Number>, 141 "fileName": Any<String>, 142 "id": Any<String>, 143 "name": Any<String>, 144 "parentId": Any<String>, 145 "pid": Any<Number>, 146 "sampleId": Any<Number>, 147 "startNS": Any<Number>, 148 "symbolId": Any<Number>, 149 "threadState": Any<String>, 150 "tid": Any<Number>, 151 "topDownMerageId": Any<String>, 152 "topDownMerageParentId": Any<String>, 153 "vaddrInFile": Any<Number>, 154} 155`); 156 }); 157 158 it('perfCallChain Test', function () { 159 perfCallChainMerageData = { 160 id: 'id', 161 parentId: 'parentId', 162 symbolName: 'symbolName', 163 symbol: 'symbol', 164 libName: 'libName', 165 self: 'self', 166 weight: 'weight', 167 selfDur: 0, 168 dur: 0, 169 tid: 0, 170 pid: 0, 171 type: 0, 172 isSelected: false, 173 }; 174 175 expect(perfCallChainMerageData).not.toBeUndefined(); 176 expect(perfCallChainMerageData).toMatchInlineSnapshot( 177{ 178 id: expect.any(String), 179 parentId: expect.any(String), 180 symbolName: expect.any(String), 181 symbol: expect.any(String), 182 libName: expect.any(String), 183 self: expect.any(String), 184 weight: expect.any(String), 185 selfDur: expect.any(Number), 186 dur: expect.any(Number), 187 tid: expect.any(Number), 188 pid: expect.any(Number), 189 type: expect.any(Number), 190 isSelected: expect.any(Boolean) }, ` 191{ 192 "dur": Any<Number>, 193 "id": Any<String>, 194 "isSelected": Any<Boolean>, 195 "libName": Any<String>, 196 "parentId": Any<String>, 197 "pid": Any<Number>, 198 "self": Any<String>, 199 "selfDur": Any<Number>, 200 "symbol": Any<String>, 201 "symbolName": Any<String>, 202 "tid": Any<Number>, 203 "type": Any<Number>, 204 "weight": Any<String>, 205} 206`); 207 }); 208 209 it('perfSample Test', function () { 210 perfSample = { 211 sampleId: 0, 212 time: 0, 213 timeString: 'timeString', 214 core: 0, 215 coreName: 'coreName', 216 state: 'state', 217 pid: 0, 218 processName: 'processName', 219 tid: 0, 220 threadName: 'threadName', 221 depth: 0, 222 addr: 'addr', 223 fileId: 0, 224 symbolId: 0, 225 }; 226 expect(perfSample).not.toBeUndefined(); 227 expect(perfSample).toMatchInlineSnapshot( 228{ 229 sampleId: expect.any(Number), 230 time: expect.any(Number), 231 timeString: expect.any(String), 232 core: expect.any(Number), 233 coreName: expect.any(String), 234 state: expect.any(String), 235 pid: expect.any(Number), 236 processName: expect.any(String), 237 tid: expect.any(Number), 238 threadName: expect.any(String), 239 depth: expect.any(Number), 240 addr: expect.any(String), 241 fileId: expect.any(Number), 242 symbolId: expect.any(Number) }, ` 243{ 244 "addr": Any<String>, 245 "core": Any<Number>, 246 "coreName": Any<String>, 247 "depth": Any<Number>, 248 "fileId": Any<Number>, 249 "pid": Any<Number>, 250 "processName": Any<String>, 251 "sampleId": Any<Number>, 252 "state": Any<String>, 253 "symbolId": Any<Number>, 254 "threadName": Any<String>, 255 "tid": Any<Number>, 256 "time": Any<Number>, 257 "timeString": Any<String>, 258} 259`); 260 }); 261 262 it('perfStack Test', function () { 263 perfStack = { 264 symbol: '', 265 path: '', 266 fileId: 0, 267 type: 0, 268 }; 269 expect(perfStack).not.toBeUndefined(); 270 expect(perfStack).toMatchInlineSnapshot( 271{ 272 symbol: expect.any(String), 273 path: expect.any(String), 274 fileId: expect.any(Number), 275 type: expect.any(Number) }, ` 276{ 277 "fileId": Any<Number>, 278 "path": Any<String>, 279 "symbol": Any<String>, 280 "type": Any<Number>, 281} 282`); 283 }); 284 285 it('perfCall Test', function () { 286 perfCall = { 287 sampleId: 0, 288 depth: 0, 289 name: 'name', 290 }; 291 expect(perfCall).not.toBeUndefined(); 292 expect(perfCall).toMatchInlineSnapshot( 293{ 294 sampleId: expect.any(Number), 295 depth: expect.any(Number), 296 name: expect.any(String) }, ` 297{ 298 "depth": Any<Number>, 299 "name": Any<String>, 300 "sampleId": Any<Number>, 301} 302`); 303 }); 304 305 it('PerfFile Test01', function () { 306 let perfFile = new PerfFile(); 307 perfFile.setFileName = jest.fn(() => true) 308 expect(perfFile.setFileName()).toBe(true); 309 }); 310 311 it('PerfFile Test02', function () { 312 let perfFile = new PerfFile(); 313 let perfF = { 314 fileId: 0, 315 symbol: 'symbol', 316 path: 'path', 317 fileName: 'fileName', 318 }; 319 expect(PerfFile.setFileName(perfF)).toBe(undefined); 320 }); 321 322 it('PerfCmdLine Test', function () { 323 perfCmdLine = { 324 report_value: 'report_value', 325 }; 326 expect(perfCmdLine).not.toBeUndefined(); 327 expect(perfCmdLine).toMatchInlineSnapshot( 328{ 329 report_value: expect.any(String) }, ` 330{ 331 "report_value": Any<String>, 332} 333`); 334 }); 335}); 336