Revision #2 has been created by M0ka on Jun 24, 2014, 11:10:24 AM with the memo:
Added the two methods and new timer to minus from
« previous (#1)
Changes
Title
unchanged
Profiling user requests
Category
unchanged
Tutorials
Yii version
unchanged
Tags
unchanged
profiling, optimization
Content
changed
[...]
public static function starter(CEvent $event) {
self::$start = microtime(true);
}
public static function bytesToKb($bytes) {
return $bytes * 1024;
}
public static function bytesToMb($bytes) {
return self::bytesToKb($bytes) * 1024;
}
public static function ender(CEvent $event) {
$memory = floatval(memory_get_usage(true));
$peak = floatval(memory_get_peak_usage(true));
$error = Yii::app()->getErrorHandler()->error;
$param = array(
'request_memory_kb' =>
Hsel
perf::bytesToKb($memory),
'request_memory_mb' =>
Hsel
perf::bytesToMb($memory),
'request_memory_peak_kb' =>
Hsel
perf::bytesToKb($peak),
'request_memory_peak_mb' =>
Hsel
perf::bytesToMb($peak),
'request_url' => Yii::app()->request->requestUri,
'request_type' => Yii::app()->request->requestType,
'request_errors' => $error,
'user_status' =>
!Yii::app()->user->isGuest
? 'Guest' : Yii::app()->user->id,
'user_ip' =>
!Yii::app()->request->userHostAddress,
'date' => time(),
'time_taken' => microtime(true) - self::$start
//or you can minus the current microtime from the constant YII_BEGIN_TIME
);
}
}
```[...]