Ticket #5218 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years ago

SAVEQUERIES: log calling function name

Reported by: tellyworth Owned by: anonymous
Priority: normal Milestone: 2.5
Component: General Version:
Severity: normal Keywords: has-patch
Cc:

Description

The SAVEQUERIES constant tells wp-db to record SQL queries and execution time in the $wpdb->queries array. The included patch adds a third element to that array: the name of the function that called wpdb.

This makes it much easier to identify the code that caused a particular query to be run.

Attachments

wpdb-get-caller-r6256.diff Download (1.2 KB) - added by tellyworth 4 years ago.
wpdb-get-caller-r6256-a.diff Download (1.3 KB) - added by tellyworth 4 years ago.

Change History

  • Keywords has-patch added

comment:2   DD324 years ago

debug_backtrace() is PHP 4.3+, WP requires PHP 4.2+

But Thats a nice addition which will be useful to some debuggers i'm sure.. another thought is what kind of performance hit is there when using debug_backtrace()?

comment:3   ryan4 years ago

It's a debug method that is not enabled by default, so performance isn't such a big deal. We can do a function exists check on debug_backtrace so we don't break 4.2 users who enable this.

wpdb-get-caller-r6256-a.diff adds an is_callable() check, and fixes up the style a little.

  • Milestone changed from 2.5 to 2.4

comment:6   DD324 years ago

Another place which this would be useful is the SQL Errors, It'd be nice for the SQL error messages to include the function which is running the failing SQL.

comment:7   ryan4 years ago

  • Status changed from new to closed
  • Resolution set to fixed

(In [6342]) Debug backtrace for queries. Props tellyworth. fixes #5218

comment:8   matt4 years ago

I like this!

We should warn people about using it in production though, debug_backtrace can be SLOW.

comment:9   ozh4 years ago

Very great stuff! Can we have this for 2.3.2 even ?

Note: See TracTickets for help on using tickets.