00:00:09,740 Hello, today we're going to have a look at how to make a flame graph, a new feature 2 00:00:09,740 --> 00:00:11,920 in Xdebug 3.3. 3 00:00:12,620 --> 00:00:16,920 Flame graphs are an interesting way of showing where an application spends a lot of time. */ $f = json_decode( file_get_contents( $argv[1] ) ); $segmentCounter = 0; $segmentText = ''; $segmentLength = 0; $segmentStart = 0; $lastStart = 0; $lastEnd = 0; foreach ( $f->segments as $segment ) { foreach ( $segment->words as $word ) { if ($word->start > $lastEnd + 0.25) { $segmentEnd = $lastEnd; emit(); $segmentStart = $word->start; } if ($segmentLength > 60) { $segmentText = trim($segmentText) . "\n" . ltrim($word->word); $segmentLength = strlen($word->word); } else { $segmentText .= $word->word; $segmentLength += strlen($word->word); } $lastEnd = $word->end; } } $segmentEnd = $lastEnd; emit(); function emit() { global $segmentCounter, $segmentStart, $segmentEnd, $segmentText, $segmentLength; $secondsStart = (int) $segmentStart; $milliSecondsStart = (int) (($segmentStart - $secondsStart) * 1000); $secondsEnd = (int) $segmentEnd; $milliSecondsEnd = (int) (($segmentEnd - $secondsEnd) * 1000); $segmentStartFmt = sprintf("%02d:%02d:%02d,%03d", $secondsStart / 3600, $secondsStart / 60, $secondsStart % 60, $milliSecondsStart); $segmentEndFmt = sprintf("%02d:%02d:%02d,%03d", $secondsEnd / 3600, $secondsEnd / 60, $secondsEnd % 60, $milliSecondsEnd); if (strlen($segmentText) == 0) { return; } printf("%s\n%s --> %s\n%s\n\n", $segmentCounter, $segmentStartFmt, $segmentEndFmt, trim($segmentText)); $segmentText = ''; $segmentLength = 0; $segmentCounter++; }