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