collector->getContext()->getStats(); foreach ( $stats as $stat ) { // Sanitize the key $key = str_replace( '::', '.', $stat['name'] ); $key = preg_replace( '/[^a-z.]+/i', '_', $key ); $key = trim( $key, '_.' ); $key = str_replace( array( '._', '_.' ), '.', $key ); // Convert fractional seconds to whole milliseconds $cpu = round( $stat['cpu'] * 1000 ); $real = round( $stat['real'] * 1000 ); $contextStats->increment( "{$key}.calls" ); $contextStats->timing( "{$key}.cpu", $cpu ); $contextStats->timing( "{$key}.real", $real ); } } }