PluginProbe
InfiniteWP Client / trunk
InfiniteWP Client vtrunk
1.13.10 1.13.7 trunk 0.1.4 0.1.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.11.0 1.11.1 1.12.1 1.12.3 All 92 releases
iwp-client / debug-chart / index.php

index.php in InfiniteWP Client trunk, at debug-chart/index.php

115 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 include_once ("src/fusioncharts.php");
3 ?>
4 <html>
5
6 <head>
7 <title>IWP DEBUG CHART</title>
8 <script src="https://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
9 </head>
10 <body>
11 <?php
12 if (empty($_GET['historyID'])) {
13 exit();
14 }
15 $iwp_multicall_hisID = $_GET['historyID'];
16 $iwp_multicall_hisID = abs( (int) $iwp_multicall_hisID );
17 $current_dir = dirname( dirname( dirname( dirname(__FILE__) ) ) ).'/infinitewp/backups';
18 $memoryPeakLog = 'DE_clMemoryPeak.'.$iwp_multicall_hisID.'.txt';
19 $memoryUsageLog = 'DE_clMemoryUsage.'.$iwp_multicall_hisID.'.txt';
20 $timeTakenLog = 'DE_clTimeTaken.'.$iwp_multicall_hisID.'.txt';
21 $cpuUsageLog = 'DE_clCPUUsage.'.$iwp_multicall_hisID.'.txt';
22 new IWP_Debug_Chart('Memory Usage in Real Time', ' MB', $current_dir . '/'.$memoryUsageLog, 'Memory Usage', 'chart-1');
23 new IWP_Debug_Chart('Time Taken', ' Sec', $current_dir . '/'.$timeTakenLog, 'Time Taken', 'chart-2');
24 new IWP_Debug_Chart('CPU Usage', ' ', $current_dir . '/'.$cpuUsageLog, 'CPU Usage', 'chart-3');
25 // new IWP_Debug_Chart('Memory Peak', ' MB', $current_dir . '/'.$memoryPeakLog, 'Memory Peak', 'chart-4');
26
27 ?>
28 <div id="chart-1"><!-- Fusion Charts will render here--></div>
29 <div id="chart-2"><!-- Fusion Charts will render here--></div>
30 <div id="chart-3"><!-- Fusion Charts will render here--></div>
31 <div id="chart-4"><!-- Fusion Charts will render here--></div>
32 </body>
33 </html>
34
35
36 <?php
37
38 Class IWP_Debug_Chart{
39 private $chart_meta;
40 private $dataset;
41
42 public function __construct($caption, $numbersuffix, $file, $graph_name, $chart_id){
43 $this->init_chart_meta($caption, $numbersuffix);
44 $this->read_logs($file);
45 $this->plot_graph($graph_name, $chart_id);
46 }
47
48 private function plot_graph($graph_name, $chart_id){
49 $encoded_data = $this->struct_data();
50 $pieChart = new FusionCharts("line", $graph_name , "100%", 300, $chart_id, "json", $encoded_data);
51 $pieChart->render();
52 }
53
54 private function struct_data(){
55 $this->chart_meta['data'] = $this->dataset;
56 return json_encode($this->chart_meta);
57 }
58
59 private function read_logs($file) {
60 if (!file_exists($file)) {
61 return;
62 }
63 $file = fopen($file, "r");
64
65 if(empty($file)){
66 return false;
67 }
68
69 while(!feof($file)) {
70 $data = explode(' ', fgets($file));
71
72 if (empty($data[0]) || empty($data[1] ) ) {
73 continue;
74 }
75 $this->dataset[] = array(
76 "label" => $data[1],
77 "value" => trim($data[2]),
78 "color" => "008ee4",
79 "stepSkipped" => false,
80 "appliedSmartLabel" => true
81 );
82 }
83
84 fclose($file);
85 }
86
87 private function init_chart_meta($caption, $numbersuffix){
88 $this->chart_meta = array(
89 "chart" => array(
90 "caption" =>$caption,
91 "numbersuffix" => $numbersuffix,
92 "bgcolor" => "FFFFFF",
93 "showalternatehgridcolor" => "0",
94 "plotbordercolor" => "008ee4",
95 "plotborderthickness" => "3",
96 "showvalues" => "0",
97 "divlinecolor" => "CCCCCC",
98 "showcanvasborder" => "0",
99 "tooltipbgcolor" => "00396d",
100 "tooltipcolor" => "FFFFFF",
101 "tooltipbordercolor" => "00396d",
102 "numdivlines" => "20",
103 "yaxisvaluespadding" => "20",
104 "anchorbgcolor" => "008ee4",
105 "anchorborderthickness" => "0",
106 "showshadow" => "0",
107 "showLabels" =>"0",
108 "anchorradius" => "2",
109 "chartrightmargin" => "25",
110 "canvasborderalpha" => "0",
111 "showborder" => "1",
112 )
113 );
114 }
115 }