-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerformance.class.php
More file actions
54 lines (46 loc) · 1.42 KB
/
Performance.class.php
File metadata and controls
54 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
Author: Facundo Giardino
*/
/**
* Clase para testear la performance del proyecto
*
* @author facundo
*/
class Performance {
//put your code here
public $tiempo;
public $memoria;
public $rutaLogPer;
public function __construct(){
$this->rutaLogPer = ROOT."/logs/LogPerformance-".date('Ymd').".log";
}
/*
* Comienza el contador de tiempo y de memoria
*/
public function iniPerformance(){
$this->tiempo = microtime(TRUE);
$this->memoria = memory_get_usage();
}
/*
* Finaliza el contador de tiempo y de memoria y lo inserta en un log (se debe llamar a iniPerformance() con anterioridad)
*/
public function finPerformance(){
$memoria = memory_get_usage() - $this->memoria;
$tiempo = microtime(TRUE) - $this->tiempo;
$data = "Performance-tiempo: ".$tiempo."\n ";
file_put_contents($this->rutaLogPer, $data, FILE_APPEND | LOCK_EX);
}
/*
* Recupera el contenido del log del dia de la fecha y lo vuelva en el html
*/
public function showLog(){
$logPer = file_get_contents($this->rutaLogPer);
$logPer = explode("\n", $logPer);
foreach($logPer as $linea)
echo $linea."<br/>";
}
public function imprimirTest(){
print_r(array($this->tiempo, $this->memoria));
}
}