whmcs-profiling
Code profiling for WHMCS
SKILL.mdskills/whmcs-profiling/SKILL.md
GitHubWHMCS Code Profiling Skill
Overview
This skill provides patterns for profiling code in WHMCS to identify performance bottlenecks.
Implementation Patterns
Profiler
<?php
/**
* WHMCS Code Profiling
* Profiles code execution time
*/
namespace WHMCS\Module\Diagnostics\Profiler;
class Profiler {
private $marks = [];
/**
* Start profiling
*/
public function start(string $label): void {
$this->marks[$label] = [
'start' => microtime(true),
'memory_start' => memory_get_usage(true)
];
}
/**
* End profiling
*/
public function end(string $label): array {
if (!isset($this->marks[$label])) {
return null;
}
$start = $this->marks[$label];
$duration = microtime(true) - $start['start'];
$memoryDelta = memory_get_usage(true) - $start['memory_start'];
return [
'label' => $label,
'duration_ms' => round($duration * 1000, 2),
'memory_delta_mb' => round($memoryDelta / 1024 / 1024, 2)
];
}
/**
* Get all profile data
*/
public function getReport(): array {
$report = [];
foreach ($this->marks as $label => $mark) {
if (isset($mark['end'])) {
$report[] = $mark;
}
}
return $report;
}
}
Best Practices
- Strategic Markers: Profile key sections only
- Memory Tracking: Watch for memory issues
- Compare Runs: Track before/after changes
- Aggregate Data: Build performance baselines
- Visualize: Use profiling tools
Related Skills
- whmcs-debug-mode
- whmcs-api-latency
- whmcs-slow-query
- whmcs-memory-debugging