]> xenbits.xensource.com Git - xentesttools/bootstrap.git/commitdiff
Rename to drfb_load.c
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Wed, 9 Feb 2011 16:36:41 +0000 (11:36 -0500)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Wed, 9 Feb 2011 16:36:41 +0000 (11:36 -0500)
root_image/tools/drfb_load/df_cpuload.c [deleted file]
root_image/tools/drfb_load/drfb_load.c [new file with mode: 0644]

diff --git a/root_image/tools/drfb_load/df_cpuload.c b/root_image/tools/drfb_load/df_cpuload.c
deleted file mode 100644 (file)
index dd350dd..0000000
+++ /dev/null
@@ -1,437 +0,0 @@
-/*
-   (c) Copyright 2000-2002  convergence integrated media GmbH.
-   All rights reserved.
-
-   Written by Denis Oliver Kropp <dok@directfb.org>,
-              Andreas Hundt <andi@fischlustig.de> and
-              Sven Neumann <neo@directfb.org>.
-
-   This file is subject to the terms and conditions of the MIT License:
-
-   Permission is hereby granted, free of charge, to any person
-   obtaining a copy of this software and associated documentation
-   files (the "Software"), to deal in the Software without restriction,
-   including without limitation the rights to use, copy, modify, merge,
-   publish, distribute, sublicense, and/or sell copies of the Software,
-   and to permit persons to whom the Software is furnished to do so,
-   subject to the following conditions:
-
-   The above copyright notice and this permission notice shall be
-   included in all copies or substantial portions of the Software.
-
-   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <directfb.h>
-
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-/******************************************************************************/
-
-static IDirectFB             *dfb     = NULL;
-static IDirectFBDisplayLayer *layer   = NULL;
-static IDirectFBWindow       *window_cpu  = NULL;
-static IDirectFBWindow       *window_net  = NULL;
-static IDirectFBSurface      *surface_cpu = NULL;
-static IDirectFBSurface      *surface_net = NULL;
-static IDirectFBEventBuffer  *events_cpu  = NULL;
-static int def_width = 0;
-/******************************************************************************/
-
-char *wanted_iface="switch";
-
-static void init_application( int *argc, char **argv[] );
-static void exit_application( int status );
-
-static void update_cpu();
-static void update_net();
-
-/******************************************************************************/
-
-int
-main( int argc, char *argv[] )
-{
-     /* Initialize application. */
-     init_application( &argc, &argv );
-
-     surface_cpu->Clear( surface_cpu, 0xff, 0xff, 0xff, 0x30 );
-     surface_net->Clear( surface_net, 0xff, 0xff, 0xff, 0x30 );
-
-     window_cpu->SetOpacity( window_cpu, 0xff );
-     window_net->SetOpacity( window_net, 0xff );
-
-     /* Main loop. */
-     while (1) {
-          DFBWindowEvent event;
-
-         update_cpu();
-          update_net();
-
-          events_cpu->WaitForEventWithTimeout( events_cpu, 0, 100 );
-
-          /* Check for new events_cpu. */
-          while (events_cpu->GetEvent( events_cpu, DFB_EVENT(&event) ) == DFB_OK) {
-               switch (event.type) {
-                    default:
-                         break;
-               }
-          }
-     }
-
-     /* Shouldn't reach this. */
-     return 0;
-}
-
-/******************************************************************************/
-
-static void
-init_application( int *argc, char **argv[] )
-{
-     DFBResult             ret;
-     DFBWindowDescription  desc;
-     DFBDisplayLayerConfig config;
-
-     /* Initialize DirectFB including command line parsing. */
-     ret = DirectFBInit( argc, argv );
-     if (ret) {
-          DirectFBError( "DirectFBInit() failed", ret );
-          exit_application( 1 );
-     }
-
-     /* Create the super interface. */
-     ret = DirectFBCreate( &dfb );
-     if (ret) {
-          DirectFBError( "DirectFBCreate() failed", ret );
-          exit_application( 2 );
-     }
-
-     /* Get the primary display layer. */
-     ret = dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );
-     if (ret) {
-          DirectFBError( "IDirectFB::GetDisplayLayer() failed", ret );
-          exit_application( 3 );
-     }
-
-     /* Get the screen size etc. */
-     layer->GetConfiguration( layer, &config );
-
-     /* Fill the window_cpu description. */
-     desc.flags  = DWDESC_POSX | DWDESC_POSY |
-                   DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS;
-     def_width   = config.width-8; 
-     desc.posx   = 8;
-     desc.posy   = 8;
-     desc.width  = def_width;
-     desc.height = 127;
-     desc.caps   = DWCAPS_ALPHACHANNEL | DWCAPS_NODECORATION;
-
-     /* Create the window_cpu. */
-     ret = layer->CreateWindow( layer, &desc, &window_cpu );
-     if (ret) {
-          DirectFBError( "IDirectFBDisplayLayer::CreateWindow() failed", ret );
-          exit_application( 4 );
-     }
-
-     /* Create the window_net. */
-     desc.posy += 127;
-     ret = layer->CreateWindow( layer, &desc, &window_net );
-     if (ret) {
-          DirectFBError( "IDirectFBDisplayLayer::CreateWindow() failed", ret );
-          exit_application( 4 );
-     }
-     ret = window_cpu->GetSurface( window_cpu, &surface_cpu );
-     if (ret) {
-          DirectFBError( "IDirectFBWindow::GetSurface() failed", ret );
-          exit_application( 5 );
-     }
-     /* Get the window_cpu's surface_cpu. */
-     ret = window_cpu->GetSurface( window_net, &surface_net );
-     if (ret) {
-          DirectFBError( "IDirectFBWindow::GetSurface() failed", ret );
-          exit_application( 5 );
-     }
-
-     /* Create an event buffer for all keyboard events_cpu. */
-     ret = window_cpu->CreateEventBuffer( window_cpu, &events_cpu );
-     if (ret) {
-          DirectFBError( "IDirectFBWindow::CreateEventBuffer() failed", ret );
-          exit_application( 6 );
-     }
-     /* Add ghost option (behave like an overlay). */
-     window_cpu->SetOptions( window_cpu, DWOP_ALPHACHANNEL | DWOP_GHOST );
-
-     /* Move window_cpu to upper stacking class. */
-     window_cpu->SetStackingClass( window_cpu, DWSC_UPPER );
-
-     /* Make it the top most window_cpu. */
-     window_cpu->RaiseToTop( window_cpu );
-
-     /* Add ghost option (behave like an overlay). */
-     window_net->SetOptions( window_net, DWOP_ALPHACHANNEL | DWOP_GHOST );
-
-
-     /* Move window_net to upper stacking class. */
-     //window_net->SetStackingClass( window_net, DWSC_UPPER );
-
-     /* Make it the top most window_net. */
-     //window_net->RaiseToTop( window_net );
-}
-
-static void
-exit_application( int status )
-{
-     /* Release the event buffer. */
-     if (events_cpu)
-          events_cpu->Release( events_cpu );
-
-     /* Release the window_cpu's surface_cpu. */
-     if (surface_cpu)
-          surface_cpu->Release( surface_cpu );
-     if (surface_net)
-          surface_net->Release( surface_net );
-
-     /* Release the window_cpu. */
-     if (window_cpu)
-          window_cpu->Release( window_cpu );
-
-     if (window_net)
-          window_net->Release( window_net );
-
-     /* Release the layer. */
-     if (layer)
-          layer->Release( layer );
-
-     /* Release the super interface. */
-     if (dfb)
-          dfb->Release( dfb );
-
-     /* Terminate application. */
-     exit( status );
-}
-
-/******************************************************************************/
-
-#define SET_IF_DESIRED(x,y) do{  if(x) *(x) = (y); }while(0)
-#define JT unsigned long
-static void four_cpu_numbers(int *uret, int *nret, int *sret, int *iret)
-{
-     int       tmp_u, tmp_n, tmp_s, tmp_i;
-     static JT old_u, old_n, old_s, old_i, old_wa, old_hi, old_si;
-     JT        new_u, new_n, new_s, new_i, new_wa = 0, new_hi = 0, new_si = 0;
-     JT        ticks_past; /* avoid div-by-0 by not calling too often :-( */
-     char      dummy[16];
-     FILE     *stat;
-
-     stat = fopen ("/proc/stat", "r");
-     if (!stat)
-          return;
-
-     if (fscanf (stat, "%s %lu %lu %lu %lu %lu %lu %lu", dummy,
-                 &new_u, &new_n, &new_s, &new_i, &new_wa, &new_hi, &new_si) < 5)
-     {
-          fclose (stat);
-          return;
-     }
-
-     fclose (stat);
-
-     ticks_past = ((new_u + new_n + new_s + new_i + new_wa + new_hi + new_si) -
-                   (old_u + old_n + old_s + old_i + old_wa + old_hi + old_si));
-     if (ticks_past) {
-          tmp_u = ((new_u - old_u) << 16) / ticks_past;
-          tmp_n = ((new_n - old_n) << 16) / ticks_past;
-          tmp_s = ((new_s - old_s) << 16) / ticks_past;
-          tmp_i = ((new_i - old_i) << 16) / ticks_past;
-     }
-     else {
-          tmp_u = 0;
-          tmp_n = 0;
-          tmp_s = 0;
-          tmp_i = 0;
-     }
-
-     SET_IF_DESIRED(uret, tmp_u);
-     SET_IF_DESIRED(nret, tmp_n);
-     SET_IF_DESIRED(sret, tmp_s);
-     SET_IF_DESIRED(iret, tmp_i);
-
-     old_u  = new_u;
-     old_n  = new_n;
-     old_s  = new_s;
-     old_i  = new_i;
-     old_wa = new_wa;
-     old_hi = new_hi;
-     old_si = new_si;
-}
-#undef JT
-
-static int
-get_load()
-{
-     static int old_load = 0;
-
-     int u = 0, n = 0, s = 0, i, load;
-
-     four_cpu_numbers( &u, &n, &s, &i );
-
-     load = u + n + s;
-
-     old_load = (load + load + load + old_load) >> 2;
-     return old_load >> 9;
-}
-
-static void
-update_cpu()
-{
-     int load = get_load();
-
-       /* Black? */
-     surface_cpu->SetColor( surface_cpu, 0xff, 0xff, 0xff, 0x30 );
-     surface_cpu->FillRectangle( surface_cpu, def_width, 0, 1, 127 - load );
-
-       /* load colors */
-     surface_cpu->SetColor( surface_cpu, 0x00, 0x50, 0xd0, 0xcc );
-     surface_cpu->FillRectangle( surface_cpu, def_width-1, 127 - load, 1, load );
-
-     surface_cpu->Blit( surface_cpu, surface_cpu, NULL, -1, 0 );
-
-       /* White? */
-     surface_cpu->SetColor( surface_cpu, 0x00, 0x00, 0x00, 0x60 );
-     surface_cpu->DrawRectangle( surface_cpu, 0, 0, def_width /* width */, 127 );
-
-
-     surface_cpu->Flip( surface_cpu, NULL, 0 );
-}
-/******************************************************************************/
-
-#define SET_IF_DESIRED(x,y) do{  if(x) *(x) = (y); }while(0)
-#define JT unsigned long
-static void input_output(double *in, double *out)
-{
-     static JT      old_in = 0, old_out = 0;
-     static double  top_in = 10, top_out = 10;
-     double         tmp_in = 0, tmp_out = 0;
-     JT             new_in, new_out;
-     JT             dummy;
-     int            found = 0;
-     char           iface[64];
-     char           buf[256];
-     FILE          *stat;
-
-     stat = fopen ("/proc/net/dev", "r");
-     if (!stat)
-          return;
-
-     while (fgets (buf, 256, stat)) {
-          int i = 0;
-
-          while (buf[i] != 0) {
-               if (buf[i] == ':')
-                    buf[i] = ' ';
-
-               i++;
-          }
-
-          if (sscanf (buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu "
-                      "%lu %lu %lu %lu\n", iface, &new_in, &dummy, &dummy,
-                      &dummy, &dummy, &dummy, &dummy, &dummy, &new_out, &dummy,
-                      &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17)
-               continue;
-          
-          if (!strcmp (iface, wanted_iface)) {
-               found = 1;
-               break;
-          }
-     }
-
-     fclose (stat);
-
-     if (found) {
-          if (old_in) {
-               tmp_in = new_in - old_in;
-
-               if (top_in < tmp_in)
-                    top_in = tmp_in;
-
-               tmp_in /= top_in;
-          }
-
-          if (old_out) {
-               tmp_out = new_out - old_out;
-
-               if (top_out < tmp_out)
-                    top_out = tmp_out;
-
-               tmp_out /= top_out;
-          }
-
-          old_in  = new_in;
-          old_out = new_out;
-     }
-
-     SET_IF_DESIRED(in, tmp_in);
-     SET_IF_DESIRED(out, tmp_out);
-}
-#undef JT
-
-static void
-get_net_load(int mult, int *ret_r_total, int *ret_t_total)
-{
-     static double old_r_total = 0;
-     static double old_t_total = 0;
-
-     double r_total = 0, t_total = 0;
-
-     input_output( &r_total, &t_total );
-
-     *ret_r_total = ((r_total + old_r_total + old_r_total + old_r_total) / 3.0)*mult;
-     *ret_t_total = ((t_total + old_t_total + old_t_total + old_t_total) / 3.0)*mult;
-
-     old_r_total = r_total;
-     old_t_total = t_total;
-}
-
-static void
-update_net()
-{
-     int rx_load, tx_load;
-
-     get_net_load(127, &rx_load,&tx_load);
-
-     surface_net->SetColor( surface_net, 0xff, 0xff, 0xff, 0x30 );
-
-     if (rx_load > tx_load) {
-       surface_net->FillRectangle( surface_net, def_width, 0, 1, 127 - rx_load );
-       surface_net->SetColor( surface_net, 0x00, 0xA0, 0x00, 0xcc );
-       surface_net->FillRectangle( surface_net, def_width-1, 127 - rx_load, 1, rx_load );
-       surface_net->SetColor( surface_net, 0x00, 0xF0, 0x00, 0xcc );
-       surface_net->FillRectangle( surface_net, def_width-1, 127 - tx_load, 1, tx_load );
-     } else {
-       surface_net->FillRectangle( surface_net, def_width-1, 0, 1, 127 - tx_load );
-       surface_net->SetColor( surface_net, 0x00, 0xF0, 0x00, 0xcc );
-       surface_net->FillRectangle( surface_net, def_width-1, 127 - tx_load, 1, tx_load );
-       surface_net->SetColor( surface_net, 0x00, 0xA0, 0x00, 0xcc );
-       surface_net->FillRectangle( surface_net, def_width-1, 127 - rx_load, 1, rx_load );
-     }
-
-     surface_net->Blit( surface_net, surface_net, NULL, -1, 0 );
-
-     surface_net->SetColor( surface_net, 0x00, 0x00, 0x00, 0x60 );
-     surface_net->DrawRectangle( surface_net, 0, 0, def_width, 127 );
-
-
-     surface_net->Flip( surface_net, NULL, 0 );
-}
-
diff --git a/root_image/tools/drfb_load/drfb_load.c b/root_image/tools/drfb_load/drfb_load.c
new file mode 100644 (file)
index 0000000..dd350dd
--- /dev/null
@@ -0,0 +1,437 @@
+/*
+   (c) Copyright 2000-2002  convergence integrated media GmbH.
+   All rights reserved.
+
+   Written by Denis Oliver Kropp <dok@directfb.org>,
+              Andreas Hundt <andi@fischlustig.de> and
+              Sven Neumann <neo@directfb.org>.
+
+   This file is subject to the terms and conditions of the MIT License:
+
+   Permission is hereby granted, free of charge, to any person
+   obtaining a copy of this software and associated documentation
+   files (the "Software"), to deal in the Software without restriction,
+   including without limitation the rights to use, copy, modify, merge,
+   publish, distribute, sublicense, and/or sell copies of the Software,
+   and to permit persons to whom the Software is furnished to do so,
+   subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be
+   included in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <directfb.h>
+
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+/******************************************************************************/
+
+static IDirectFB             *dfb     = NULL;
+static IDirectFBDisplayLayer *layer   = NULL;
+static IDirectFBWindow       *window_cpu  = NULL;
+static IDirectFBWindow       *window_net  = NULL;
+static IDirectFBSurface      *surface_cpu = NULL;
+static IDirectFBSurface      *surface_net = NULL;
+static IDirectFBEventBuffer  *events_cpu  = NULL;
+static int def_width = 0;
+/******************************************************************************/
+
+char *wanted_iface="switch";
+
+static void init_application( int *argc, char **argv[] );
+static void exit_application( int status );
+
+static void update_cpu();
+static void update_net();
+
+/******************************************************************************/
+
+int
+main( int argc, char *argv[] )
+{
+     /* Initialize application. */
+     init_application( &argc, &argv );
+
+     surface_cpu->Clear( surface_cpu, 0xff, 0xff, 0xff, 0x30 );
+     surface_net->Clear( surface_net, 0xff, 0xff, 0xff, 0x30 );
+
+     window_cpu->SetOpacity( window_cpu, 0xff );
+     window_net->SetOpacity( window_net, 0xff );
+
+     /* Main loop. */
+     while (1) {
+          DFBWindowEvent event;
+
+         update_cpu();
+          update_net();
+
+          events_cpu->WaitForEventWithTimeout( events_cpu, 0, 100 );
+
+          /* Check for new events_cpu. */
+          while (events_cpu->GetEvent( events_cpu, DFB_EVENT(&event) ) == DFB_OK) {
+               switch (event.type) {
+                    default:
+                         break;
+               }
+          }
+     }
+
+     /* Shouldn't reach this. */
+     return 0;
+}
+
+/******************************************************************************/
+
+static void
+init_application( int *argc, char **argv[] )
+{
+     DFBResult             ret;
+     DFBWindowDescription  desc;
+     DFBDisplayLayerConfig config;
+
+     /* Initialize DirectFB including command line parsing. */
+     ret = DirectFBInit( argc, argv );
+     if (ret) {
+          DirectFBError( "DirectFBInit() failed", ret );
+          exit_application( 1 );
+     }
+
+     /* Create the super interface. */
+     ret = DirectFBCreate( &dfb );
+     if (ret) {
+          DirectFBError( "DirectFBCreate() failed", ret );
+          exit_application( 2 );
+     }
+
+     /* Get the primary display layer. */
+     ret = dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );
+     if (ret) {
+          DirectFBError( "IDirectFB::GetDisplayLayer() failed", ret );
+          exit_application( 3 );
+     }
+
+     /* Get the screen size etc. */
+     layer->GetConfiguration( layer, &config );
+
+     /* Fill the window_cpu description. */
+     desc.flags  = DWDESC_POSX | DWDESC_POSY |
+                   DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS;
+     def_width   = config.width-8; 
+     desc.posx   = 8;
+     desc.posy   = 8;
+     desc.width  = def_width;
+     desc.height = 127;
+     desc.caps   = DWCAPS_ALPHACHANNEL | DWCAPS_NODECORATION;
+
+     /* Create the window_cpu. */
+     ret = layer->CreateWindow( layer, &desc, &window_cpu );
+     if (ret) {
+          DirectFBError( "IDirectFBDisplayLayer::CreateWindow() failed", ret );
+          exit_application( 4 );
+     }
+
+     /* Create the window_net. */
+     desc.posy += 127;
+     ret = layer->CreateWindow( layer, &desc, &window_net );
+     if (ret) {
+          DirectFBError( "IDirectFBDisplayLayer::CreateWindow() failed", ret );
+          exit_application( 4 );
+     }
+     ret = window_cpu->GetSurface( window_cpu, &surface_cpu );
+     if (ret) {
+          DirectFBError( "IDirectFBWindow::GetSurface() failed", ret );
+          exit_application( 5 );
+     }
+     /* Get the window_cpu's surface_cpu. */
+     ret = window_cpu->GetSurface( window_net, &surface_net );
+     if (ret) {
+          DirectFBError( "IDirectFBWindow::GetSurface() failed", ret );
+          exit_application( 5 );
+     }
+
+     /* Create an event buffer for all keyboard events_cpu. */
+     ret = window_cpu->CreateEventBuffer( window_cpu, &events_cpu );
+     if (ret) {
+          DirectFBError( "IDirectFBWindow::CreateEventBuffer() failed", ret );
+          exit_application( 6 );
+     }
+     /* Add ghost option (behave like an overlay). */
+     window_cpu->SetOptions( window_cpu, DWOP_ALPHACHANNEL | DWOP_GHOST );
+
+     /* Move window_cpu to upper stacking class. */
+     window_cpu->SetStackingClass( window_cpu, DWSC_UPPER );
+
+     /* Make it the top most window_cpu. */
+     window_cpu->RaiseToTop( window_cpu );
+
+     /* Add ghost option (behave like an overlay). */
+     window_net->SetOptions( window_net, DWOP_ALPHACHANNEL | DWOP_GHOST );
+
+
+     /* Move window_net to upper stacking class. */
+     //window_net->SetStackingClass( window_net, DWSC_UPPER );
+
+     /* Make it the top most window_net. */
+     //window_net->RaiseToTop( window_net );
+}
+
+static void
+exit_application( int status )
+{
+     /* Release the event buffer. */
+     if (events_cpu)
+          events_cpu->Release( events_cpu );
+
+     /* Release the window_cpu's surface_cpu. */
+     if (surface_cpu)
+          surface_cpu->Release( surface_cpu );
+     if (surface_net)
+          surface_net->Release( surface_net );
+
+     /* Release the window_cpu. */
+     if (window_cpu)
+          window_cpu->Release( window_cpu );
+
+     if (window_net)
+          window_net->Release( window_net );
+
+     /* Release the layer. */
+     if (layer)
+          layer->Release( layer );
+
+     /* Release the super interface. */
+     if (dfb)
+          dfb->Release( dfb );
+
+     /* Terminate application. */
+     exit( status );
+}
+
+/******************************************************************************/
+
+#define SET_IF_DESIRED(x,y) do{  if(x) *(x) = (y); }while(0)
+#define JT unsigned long
+static void four_cpu_numbers(int *uret, int *nret, int *sret, int *iret)
+{
+     int       tmp_u, tmp_n, tmp_s, tmp_i;
+     static JT old_u, old_n, old_s, old_i, old_wa, old_hi, old_si;
+     JT        new_u, new_n, new_s, new_i, new_wa = 0, new_hi = 0, new_si = 0;
+     JT        ticks_past; /* avoid div-by-0 by not calling too often :-( */
+     char      dummy[16];
+     FILE     *stat;
+
+     stat = fopen ("/proc/stat", "r");
+     if (!stat)
+          return;
+
+     if (fscanf (stat, "%s %lu %lu %lu %lu %lu %lu %lu", dummy,
+                 &new_u, &new_n, &new_s, &new_i, &new_wa, &new_hi, &new_si) < 5)
+     {
+          fclose (stat);
+          return;
+     }
+
+     fclose (stat);
+
+     ticks_past = ((new_u + new_n + new_s + new_i + new_wa + new_hi + new_si) -
+                   (old_u + old_n + old_s + old_i + old_wa + old_hi + old_si));
+     if (ticks_past) {
+          tmp_u = ((new_u - old_u) << 16) / ticks_past;
+          tmp_n = ((new_n - old_n) << 16) / ticks_past;
+          tmp_s = ((new_s - old_s) << 16) / ticks_past;
+          tmp_i = ((new_i - old_i) << 16) / ticks_past;
+     }
+     else {
+          tmp_u = 0;
+          tmp_n = 0;
+          tmp_s = 0;
+          tmp_i = 0;
+     }
+
+     SET_IF_DESIRED(uret, tmp_u);
+     SET_IF_DESIRED(nret, tmp_n);
+     SET_IF_DESIRED(sret, tmp_s);
+     SET_IF_DESIRED(iret, tmp_i);
+
+     old_u  = new_u;
+     old_n  = new_n;
+     old_s  = new_s;
+     old_i  = new_i;
+     old_wa = new_wa;
+     old_hi = new_hi;
+     old_si = new_si;
+}
+#undef JT
+
+static int
+get_load()
+{
+     static int old_load = 0;
+
+     int u = 0, n = 0, s = 0, i, load;
+
+     four_cpu_numbers( &u, &n, &s, &i );
+
+     load = u + n + s;
+
+     old_load = (load + load + load + old_load) >> 2;
+     return old_load >> 9;
+}
+
+static void
+update_cpu()
+{
+     int load = get_load();
+
+       /* Black? */
+     surface_cpu->SetColor( surface_cpu, 0xff, 0xff, 0xff, 0x30 );
+     surface_cpu->FillRectangle( surface_cpu, def_width, 0, 1, 127 - load );
+
+       /* load colors */
+     surface_cpu->SetColor( surface_cpu, 0x00, 0x50, 0xd0, 0xcc );
+     surface_cpu->FillRectangle( surface_cpu, def_width-1, 127 - load, 1, load );
+
+     surface_cpu->Blit( surface_cpu, surface_cpu, NULL, -1, 0 );
+
+       /* White? */
+     surface_cpu->SetColor( surface_cpu, 0x00, 0x00, 0x00, 0x60 );
+     surface_cpu->DrawRectangle( surface_cpu, 0, 0, def_width /* width */, 127 );
+
+
+     surface_cpu->Flip( surface_cpu, NULL, 0 );
+}
+/******************************************************************************/
+
+#define SET_IF_DESIRED(x,y) do{  if(x) *(x) = (y); }while(0)
+#define JT unsigned long
+static void input_output(double *in, double *out)
+{
+     static JT      old_in = 0, old_out = 0;
+     static double  top_in = 10, top_out = 10;
+     double         tmp_in = 0, tmp_out = 0;
+     JT             new_in, new_out;
+     JT             dummy;
+     int            found = 0;
+     char           iface[64];
+     char           buf[256];
+     FILE          *stat;
+
+     stat = fopen ("/proc/net/dev", "r");
+     if (!stat)
+          return;
+
+     while (fgets (buf, 256, stat)) {
+          int i = 0;
+
+          while (buf[i] != 0) {
+               if (buf[i] == ':')
+                    buf[i] = ' ';
+
+               i++;
+          }
+
+          if (sscanf (buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu "
+                      "%lu %lu %lu %lu\n", iface, &new_in, &dummy, &dummy,
+                      &dummy, &dummy, &dummy, &dummy, &dummy, &new_out, &dummy,
+                      &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17)
+               continue;
+          
+          if (!strcmp (iface, wanted_iface)) {
+               found = 1;
+               break;
+          }
+     }
+
+     fclose (stat);
+
+     if (found) {
+          if (old_in) {
+               tmp_in = new_in - old_in;
+
+               if (top_in < tmp_in)
+                    top_in = tmp_in;
+
+               tmp_in /= top_in;
+          }
+
+          if (old_out) {
+               tmp_out = new_out - old_out;
+
+               if (top_out < tmp_out)
+                    top_out = tmp_out;
+
+               tmp_out /= top_out;
+          }
+
+          old_in  = new_in;
+          old_out = new_out;
+     }
+
+     SET_IF_DESIRED(in, tmp_in);
+     SET_IF_DESIRED(out, tmp_out);
+}
+#undef JT
+
+static void
+get_net_load(int mult, int *ret_r_total, int *ret_t_total)
+{
+     static double old_r_total = 0;
+     static double old_t_total = 0;
+
+     double r_total = 0, t_total = 0;
+
+     input_output( &r_total, &t_total );
+
+     *ret_r_total = ((r_total + old_r_total + old_r_total + old_r_total) / 3.0)*mult;
+     *ret_t_total = ((t_total + old_t_total + old_t_total + old_t_total) / 3.0)*mult;
+
+     old_r_total = r_total;
+     old_t_total = t_total;
+}
+
+static void
+update_net()
+{
+     int rx_load, tx_load;
+
+     get_net_load(127, &rx_load,&tx_load);
+
+     surface_net->SetColor( surface_net, 0xff, 0xff, 0xff, 0x30 );
+
+     if (rx_load > tx_load) {
+       surface_net->FillRectangle( surface_net, def_width, 0, 1, 127 - rx_load );
+       surface_net->SetColor( surface_net, 0x00, 0xA0, 0x00, 0xcc );
+       surface_net->FillRectangle( surface_net, def_width-1, 127 - rx_load, 1, rx_load );
+       surface_net->SetColor( surface_net, 0x00, 0xF0, 0x00, 0xcc );
+       surface_net->FillRectangle( surface_net, def_width-1, 127 - tx_load, 1, tx_load );
+     } else {
+       surface_net->FillRectangle( surface_net, def_width-1, 0, 1, 127 - tx_load );
+       surface_net->SetColor( surface_net, 0x00, 0xF0, 0x00, 0xcc );
+       surface_net->FillRectangle( surface_net, def_width-1, 127 - tx_load, 1, tx_load );
+       surface_net->SetColor( surface_net, 0x00, 0xA0, 0x00, 0xcc );
+       surface_net->FillRectangle( surface_net, def_width-1, 127 - rx_load, 1, rx_load );
+     }
+
+     surface_net->Blit( surface_net, surface_net, NULL, -1, 0 );
+
+     surface_net->SetColor( surface_net, 0x00, 0x00, 0x00, 0x60 );
+     surface_net->DrawRectangle( surface_net, 0, 0, def_width, 127 );
+
+
+     surface_net->Flip( surface_net, NULL, 0 );
+}
+