Jun
3

Plugin Resource Profiler

06/03/2025 12:00 AM by Publisher in Wordpress


Plugin Resource Profiler

The Plugin Resource Profiler is a WordPress plugin that helps site administrators monitor the resource usage of active plugins. It offers a clear breakdown of:

  • Hook count per plugin

  • Number of PHP files and classes loaded

  • Detection of slow WordPress hooks (>50ms)

  • Log of slow hooks with plugin origin

  • Admin interface with sorting and filtering options


Features Overview

1. Hook Usage Analysis

Displays the number of WordPress hooks registered by each plugin.

  • Useful to understand which plugin adds the most filters/actions.

2. File and Class Count

Shows how many PHP files and classes each plugin loads.

  • Helps detect heavy plugins that may slow down performance.

3. Slow Hook Logger

Any hook that takes more than 50ms to process is logged, along with its name, execution time, and originating plugin.

  • Logs are stored in /wp-content/prp_log.log

4. Admin Interface

Accessible via Admin > Plugin Profiler:

  • Plugins tab:

    • Overview table of all plugins

    • Sortable and filterable

  • Logs tab:

    • Shows slow hook events from the log

    • Also sortable and filterable

    • Includes delete log button

5. Settings Link

A quick link to the plugin settings is added in the WordPress plugins list.


Code Breakdown (Main Parts)

Hook Tracking (add_action('all', ...))

Tracks execution time between each hook and logs slow ones (>50ms):

add_action('all', function($hook_name) {
  static $last_time = null;
  $now = microtime(true);
  if ($last_time !== null) {
    $delta = $now - $last_time;
    if ($delta > 0.05) {
      // Find plugin source of the hook via debug_backtrace
      // Log to prp_log.log with hook name, time, and plugin
    }
  }
  $last_time = $now;
});

Plugin Metrics: Hook, File & Class Count

Two functions scan:

  • $wp_filter to count unique hooks per plugin

  • get_included_files() and get_declared_classes() to count how many files/classes each plugin loads

Admin Page: prp_render_admin_page()

Renders the "Plugins" tab with a sortable and searchable table of all active plugins.

Logs Page: prp_render_log_page()

Reads the prp_log.log file and displays each logged entry in a table.
Includes:

  • Filter search box

  • Sortable headers

  • Delete log functionality

Sorting/Filtering Script

A small JavaScript snippet is embedded to:

  • Enable click-to-sort per column (numeric or text)

  • Add a search field to filter rows live

  • Show ASC/DSC arrows for clarity


Use Cases

  • Identify plugins that slow down your WordPress site

  • Debug performance issues related to hooks

  • Analyze plugin bloat (too many files/classes/hooks)


Installation

  1. Upload the plugin archive via Plugins > Add New > Upload Plugin

  2. Activate the plugin

  3. Go to Tools > Plugin Profiler to view performance data


Future Improvements

  • Export CSV/PDF

  • Hook execution charts

  • REST API endpoint for performance stats

  • Integration with Query Monitor


Author

Nicușor Gurău
WP Plugins URI: https://webmastertool.org/blog/category/wordpress


 

📎 Download Now

👉 Download Plugin Resource Profiler



leave a comment
Please post your comments here.