Skip to content

Commit

Permalink
Merge pull request rlerdorf#31 from tessus/master
Browse files Browse the repository at this point in the history
display thousand separator (can be turned off)
  • Loading branch information
rlerdorf committed Jan 21, 2015
2 parents a978692 + 91ab3fb commit a024341
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions opcache.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

define('THOUSAND_SEPARATOR',true);

if (!extension_loaded('Zend OPcache')) {
echo '<div style="background-color: #F2DEDE; color: #B94A48; padding: 1em;">You do not have the Zend OPcache extension loaded, sample data is being shown instead.</div>';
require 'data-sample.php';
Expand Down Expand Up @@ -55,6 +57,9 @@ public function getStatusDataRows()
if ($k === 'start_time' || $k === 'last_restart_time') {
$v = ($v ? date(DATE_RFC822, $v) : 'never');
}
if (THOUSAND_SEPARATOR === true && is_int($v)) {
$v = number_format($v);
}

$rows[] = "<tr><th>$k</th><td>$v</td></tr>\n";
}
Expand Down Expand Up @@ -131,7 +136,7 @@ public function getScriptStatusRows()

foreach ($files as $file => $data) {
$rows[] = "<tr id=\"row-{$id}\">";
$rows[] = "<td>{$data["hits"]}</td>";
$rows[] = "<td>" . $this->_format_value($data["hits"]) . "</td>";
$rows[] = "<td>" . $this->_size_for_humans($data["memory_consumption"]) . "</td>";
$rows[] = $count > 1 ? "<td>{$file}</td>" : "<td>{$dir}/{$file}</td>";
$rows[] = '</tr>';
Expand Down Expand Up @@ -175,6 +180,12 @@ public function getGraphDataSetJson()
$this->_status['opcache_statistics']['hash_restarts'],
);

if (THOUSAND_SEPARATOR === true) {
$dataset['TSEP'] = 1;
} else {
$dataset['TSEP'] = 0;
}

return json_encode($dataset);
}

Expand Down Expand Up @@ -233,6 +244,15 @@ private function _processPartition($value, $name = null)
return $array;
}

private function _format_value($value)
{
if (THOUSAND_SEPARATOR === true) {
return number_format($value);
} else {
return $value;
}
}

private function _size_for_humans($bytes)
{
if ($bytes > 1048576) {
Expand Down Expand Up @@ -563,13 +583,13 @@ function set_text(t) {
);
} else if (t === "keys") {
d3.select("#stats").html(
"<table><tr><th style='background:#B41F1F;'>Cached keys</th><td>"+dataset[t][0]+"</td></tr>"+
"<tr><th style='background:#1FB437;'>Free Keys</th><td>"+dataset[t][1]+"</td></tr></table>"
"<table><tr><th style='background:#B41F1F;'>Cached keys</th><td>"+format_value(dataset[t][0])+"</td></tr>"+
"<tr><th style='background:#1FB437;'>Free Keys</th><td>"+format_value(dataset[t][1])+"</td></tr></table>"
);
} else if (t === "hits") {
d3.select("#stats").html(
"<table><tr><th style='background:#B41F1F;'>Misses</th><td>"+dataset[t][0]+"</td></tr>"+
"<tr><th style='background:#1FB437;'>Cache Hits</th><td>"+dataset[t][1]+"</td></tr></table>"
"<table><tr><th style='background:#B41F1F;'>Misses</th><td>"+format_value(dataset[t][0])+"</td></tr>"+
"<tr><th style='background:#1FB437;'>Cache Hits</th><td>"+format_value(dataset[t][1])+"</td></tr></table>"
);
} else if (t === "restarts") {
d3.select("#stats").html(
Expand Down Expand Up @@ -604,6 +624,14 @@ function size_for_humans(bytes) {
} else return bytes + ' bytes';
}

function format_value(value) {
if (dataset["TSEP"] == 1) {
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} else {
return value;
}
}

var w = window.innerWidth,
h = window.innerHeight,
x = d3.scale.linear().range([0, w]),
Expand Down

0 comments on commit a024341

Please sign in to comment.