Profiler
- profilerStart()
- profilerEnd()
- profilerShow()
- profilerShowLargerThan()
- profilerShowLongerThan()
To start collecting queries to profile, after your connection use the profilerStart() method:
1 2 |
DB::MySQL()->connect('host', 'username', 'password'); DB::MySQL()->profilerStart(); |
The profiler will now catch ALL MySQL queries, regardless of connection or database. To limit the number of queries you want catched, you can use profilerEnd() to stop the profiler.
1 2 3 4 |
DB::MySQL()->connect('host', 'username', 'password'); DB::MySQL()->profilerStart(); /** queries go here **/ DB::MySQL()->profilerEnd(); |
To view the query details, the profiler provides three different options.
profilerShow( void )
profilerShow() shows all of the queries captured. To get the relevant data from each query, you can use the getQuery(), getExecutionTime, and getMemoryUsage.
1 2 3 4 5 6 7 8 9 10 |
DB::MySQL()->connect('host', 'username', 'password'); DB::MySQL()->profilerStart(); /** queries go here **/ DB::MySQL()->profilerEnd(); foreach(DB::MySQL()->profilerShow() as $profile) { echo $profile->getQuery(); // query run
echo $profile->getExecutionTime(); // execution time in seconds
echo $profile->getMemoryUsage(); // memory used to perform query
} |
profilerShowLargerThan( int $memory )
profilerShowLargerThan() allows you to retrieve ONLY queries that use more memory than specified, giving you the ability to quickly scan your site for large and daunting queries.
1 |
DB::MySQL()->profilerShowLargerThan(1000); // 1000 bytes |
profilerShowLongerThan( float $seconds )
profilerShowLongerThan() allows you to retrieve ONLY queries that take longer than the time (in seconds) specified, giving you the ability to quickly scan your site for queries that drag and should be optimized.
1 |
DB::MySQL()->profilerShowLongerThan(0.1); // 1/10 of a second |