Changeset 517 for trunk/admin/xcache.php


Ignore:
Timestamp:
2008-02-17T11:52:38+01:00 (7 years ago)
Author:
moo
Message:

show free blocks as graph

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/xcache.php

    r421 r517  
    7373
    7474    return '0 s';
     75}
     76
     77function freeblock_to_graph($freeblocks, $size)
     78{
     79    global $free_graph_width;
     80
     81    // cached in static variable
     82    static $graph_initial;
     83    if (!isset($graph_initial)) {
     84        for ($i = 0; $i < $free_graph_width; $i ++) {
     85            $graph_initial[$i] = 0;
     86        }
     87    }
     88    $graph = $graph_initial;
     89    foreach ($freeblocks as $b) {
     90        $begin = $b['offset'] / $size * $free_graph_width;
     91        $end = ($b['offset'] + $b['size']) / $size * $free_graph_width;
     92
     93        $graph[(int) $begin] += 1 - ($begin - (int) $begin);
     94        $graph[(int) $end] += ($end - (int) $end);
     95        for ($i = (int) $begin + 1, $e = (int) $end; $i < $e; $i ++) {
     96            $graph[$i] = 1;
     97        }
     98    }
     99    $html = array();
     100    $c = 255;
     101    foreach ($graph as $k => $v) {
     102        $v = (int) ($v * $c);
     103        $r = $g = $c - $v;
     104        $b = $c;
     105        $html[] = '<div style="background: rgb(' . "$r,$g,$b" . ')"></div>';
     106    }
     107    return implode('', $html);
    75108}
    76109
Note: See TracChangeset for help on using the changeset viewer.