Results 1 to 2 of 2

Thread: Any MySql Profilers

  1. #1
    Join Date
    Nov 2010
    Thanked 0 Times in 0 Posts

    Default Any MySql Profilers

    Hi All,

    Can anyone tell me any opensource mysql profiler? I want to see the execution time of all the queries.

  2. #2
    Join Date
    Mar 2006
    Illinois, USA
    Thanked 690 Times in 678 Posts


    I'm not sure on any specifics, but you should be able to find relevant information by searching for "MySQL analysis/analyzer" and "MySQL statistics", and perhaps "MySQL performance" as well.

    I'm sure there's a package that can do this, but you could also relatively easily do it yourself. Just track the time from the start of the script to the end of the script (or by query). Lots of pages have a "processing time" displayed at the bottom.

    Another way to do this would be to create a class that has a __construct() function, which starts a timer, and a __destruct() function, which stops the timer and records it (in a database? somewhere else?), and it just has a single function in it-- execute a mysql query. Does that make sense?

    Something like this:
    PHP Code:
    class mysqlprofiler
    __create() {
    $this->time time()+microtime();
        public function 
    query($q) {
    __destruct() {
            if isset(
    $this->q) {
    $this->time = (time()+microtime())-$this->time;
    //track time:
    mysql_query('INSERT INTO mysqlprofiler ....'$this->time');
    function mysql_query_profile($q) {
        $m = new mysqlprofiler();
        unset($m); //perform __destruct();

    //untested, but should work in general, probably after some adjustments for your setup, especially with tracking the times. 
    Of course you could also do a simpler version with just one function that does all of that, but using the class will allow you to make it more complicated if needed -- including additional operations like executing a search in a loop -- or for doing several queries at once. The simpler version would be:
    PHP Code:
    function mysql_query_profile($q) {
    $t time()+microtime();
       return (
    time()+microtime())-$t//return the length as the output of this query, or put it in the DB now if you want

    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts