El blog de Juan Palómez

18 abril 2013

Memory usage treemap / WinDirStat for memory

Filed under: Uncategorized — Etiquetas: , , , , — thisisoneball @ 15:11

Warning: this is a quick hack, it’s not complete and it has bugs. Feel free to correct them and send me the changes.
Also, unlike WinDirStat, measuring memory usage is more difficult than measuring disk space. There are many different memory sizes for one process (Private Bytes, Working Set, Virtual Size, …), this just uses the output of the Windows tasklist command.


It’s a Perl program that tries to run that command, parses the output, and uses Google Charts Treemap to render the output.
It prints the HTML to stdout so the best way to run it is:
perl memoryusage.pl > memoryusage.html && start memoryusage.html

my %groups = ();
my $output;

my $output_pre = "
            <script type='text/javascript' src='https://www.google.com/jsapi'></script>
            <script type='text/javascript'>
              google.load('visualization', '1', {packages:['treemap']});
              function drawChart() {
                  // Create and populate the data table.
                  var data = google.visualization.arrayToDataTable([
                    ['Process', 'Parent', 'Size'],
                    ['root',    null,                 0],

my $output_post = "

                  // Create and draw the visualization.
                  var treemap = new google.visualization.TreeMap(document.getElementById('chart_div'));
                  treemap.draw(data, {
                    minColor: 'red',
                    midColor: '#ddd',
                    maxColor: '#0d0',
                    headerHeight: 15,
                    fontColor: 'black',
                    showScale: true});

    <div id='chart_div' style='width: 900px; height: 500px;'></div>

open TASKLIST, "tasklist /nh /fo CSV |" or die "Can't execute tasklist command $!\n";
while (<TASKLIST>) {
        if (m/"(.+)","(.+)",".+",".+","(.+) KB?"/) {
                $name = $1;
                $pid  = $2;
                $size = $3;
                $size =~ s/\.//;
                $output .= "['$pid','$name',$size],\n";
                $groups{"$name"} = 1;


while ( my ($key, $value) = each(%groups) ) {
        $output .= "['$key','root',0],\n";

chop $output;
chop $output;

print $output_pre . $output . $output_post;

Dejar un comentario »

Aún no hay comentarios.

RSS feed for comments on this post. TrackBack URI


Por favor, inicia sesión con uno de estos métodos para publicar tu comentario:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s

Crea un blog o un sitio web gratuitos con WordPress.com.

A %d blogueros les gusta esto: