MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxPrintProfiler

Function fxPrintProfiler

xs/sources/xsProfile.c:391–507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389}
390
391void fxPrintProfiler(txMachine* the, void* stream)
392{
393 // https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#type-Profile
394 txProfiler* profiler = the->profiler;
395 FILE* file = stream;
396 char buffer[22];
397 char name[36];
398
399 fxRemoveProfilerCycle(the, profiler, 0);
400
401 if (!file) {
402 time_t timer;
403 struct tm* tm_info;
404 timer = time(NULL);
405 tm_info = localtime(&timer);
406 strftime(buffer, 22, "XS-%y-%m-%d-%H-%M-%S-", tm_info);
407 snprintf(name, sizeof(name), "%s%03llu.cpuprofile", buffer, (long long unsigned int)((profiler->stop / 1000) % 1000));
408 file = fopen(name, "w");
409 }
410
411 fprintf(file, "{\"nodes\":[");
412 txU4 recordIndex = 0;
413 while (recordIndex < profiler->recordCount) {
414 txProfilerRecord* record = profiler->records[recordIndex];
415 if (record) {
416 if (recordIndex > 0)
417 fprintf(file, ",");
418 fprintf(file, "{\"id\":%d,\"callFrame\":{\"functionName\":\"", record->recordID);
419 if (recordIndex == 0)
420 fprintf(file, "(host)");
421 else if (recordIndex == 1)
422 fprintf(file, "(gc)");
423 else if (record->functionID != XS_NO_ID) {
424 if (record->constructorID != XS_NO_ID) {
425 fxPrintID(the, file, record->constructorID);
426 fprintf(file, ".");
427 }
428 if (record->prototypeID != XS_NO_ID) {
429 fxPrintID(the, file, record->prototypeID);
430 fprintf(file, ".");
431 }
432 fxPrintID(the, file, record->functionID);
433 }
434 else if (record->functionAddress) {
435#if mxMacOSX || mxLinux
436 Dl_info info;
437 if (dladdr(record->functionAddress, &info) && info.dli_sname)
438 fprintf(file, "@%s",info.dli_sname );
439 else
440#endif
441 fprintf(file, "@anonymous-%d", record->recordID);
442 }
443 else
444 fprintf(file, "(anonymous-%d)", record->recordID);
445
446 fprintf(file, "\",\"scriptId\":\"0\",\"url\":\"");
447 if (record->file != XS_NO_ID)
448 fxPrintID(the, file, record->file);

Callers 1

fxDeleteProfilerFunction · 0.85

Calls 4

fxRemoveProfilerCycleFunction · 0.85
timeFunction · 0.85
fxTicksToMicrosecondsFunction · 0.85
fxPrintIDFunction · 0.70

Tested by

no test coverage detected