$wpdb
counts the queries ran and saves the value in the $num_queries
class variable.
$num_queries
The number of queries that have been executed.
All you need to do is retrieve it:
echo $wpdb->num_queries;
You may also be interested in the $queries
class variable.
$queries
You may save all of the queries run on the database and their stop times by setting the SAVEQUERIES constant to TRUE (this constant
defaults to FALSE). If SAVEQUERIES is TRUE, your queries will be
stored in this variable as an array.
$num_queries
will reflect all queries. The queries
variable should have information enough that you can isolate and count only your plugin’s queries, if that is what you want.