Tiny Core Linux

Tiny Core Extensions => TCE News => TCE 2.x => Topic started by: curaga on September 13, 2009, 12:28:10 PM

Title: Watcher, the cpu/mem/swap/battery meter
Post by: curaga on September 13, 2009, 12:28:10 PM
Quote
Title:          watcher.tcz
Description:    FLTK cpu/ram/swap/battery meter
Version:        1.7
Author:         Curaga
Original-site:  http://tinycorelinux.com
Copying-policy: GPL
Size:      8K
Extension_by:   Curaga
Comments:       The latest watcher, now available as an extension. :P
      Changes from 1.6:
      - battery support
      - no borders (looking better on non-swallowing WMs)
-
      Use the X standard -g option to position watcher where-ever
      wanted. X counts from top-left, so watcher in top-left corner:
      watcher -g +0+0
      
      Top-right would be "-0+0", bottom left "+0-0", bottom right
      "-0-0".
-
      This extension is PPI compatible.
Change-log:    
Current:        2009/09/13 Original

Screenshot showing a ton of watchers, all in different options:
(http://preview.shareapic.net/preview6/019261759.png) (http://www.shareapic.net/View-19261759-TC.html)

The "Sun 13" at the bottom is from the JWM tray; my laptop runs JWM, and I wanted to get at least one battery shot in.
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: jpeters on September 20, 2009, 10:26:27 PM
I'm wondering how watcher gets CPU data, since it's quite different from that shown by Conky and top.
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: curaga on September 25, 2009, 11:42:37 AM
ftp://ftp.nluug.nl/pub/metalab/distributions/tinycorelinux/2.x/tce/src/watcher.cxx

:D
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: mavrothal on February 16, 2010, 12:41:39 PM
ftp://ftp.nluug.nl/pub/metalab/distributions/tinycorelinux/2.x/tce/src/watcher.cxx

:D

Tried to recompile for the OLPC XO-1 that has totaly differnt path for battery but even the original  gives me a bunch of undefined references (F1_window..., F1:: run ()... etc) and fails
What do I miss?
PS: This is my first attempt to compile...
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: curaga on February 16, 2010, 12:47:11 PM
Looks like you don't have FLTK (fltk.org), the gui toolkit.
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: mavrothal on February 16, 2010, 10:45:32 PM
Looks like you don't have FLTK (fltk.org), the gui toolkit.

It makes sense but I assumed that it can be done on TC and I do have fltk2.tcz and fltk-fluid.tcz, along with compiletc.tcz and base-dev.tcz loaded. Anything else I need? Should it be done in another distro?

To be honest since there is no makefile all I tried was "gcc (or c++/g++) -c watcher.cxx"  ::) but as I said this IS my first stub at compiling, at least from cxx.

 
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: roberts on February 16, 2010, 11:05:37 PM
Although I am not familar with the watcher code, to link in the fltk support you would typically use -lfltk
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: curaga on February 17, 2010, 12:43:16 AM
g++ -o watcher watcher.cxx -lfltk

Watcher uses fltk 1.1, included in the base and devs in compiletc.
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: mavrothal on February 17, 2010, 08:39:58 AM
g++ -o watcher watcher.cxx -lfltk

Watcher uses fltk 1.1, included in the base and devs in compiletc.

Worked like a charm.
However, the -bat option gives me segmentation fault, no matter what.
I guess I'll have to understand what exactly is doing to calculate the battery output.
The problem is that while the bat state file reports a number (actually % full) the bat full file reports a word  ???
Just reporting the the output of the -bat state file would be sufficient!
Well,... I have to figure out how to do this :-\
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: mavrothal on April 17, 2010, 01:43:10 PM
From what I understand watcher just gives the output of a division between the current bat state and the full one.
The OLPC XO does not have that, but outputs directly the percent full as a 2 digit number.
So I pointed "batnow" to this file, commented out the "batfull" bit and I set the "batmsg" to read "batnow" directly.
so lines 24 to 49 look like that
Code: [Select]
float timeout=1.5,mem=0,swap=0,cpu=0,used=0,oldused=0,cputotal=0,oldcputotal=0;
float batnow=0; //batfull=0;
int arg_i=0, fontsize=10, mib=0, showswap=1;
char memind[2]="m", swapind[2]="m", batname[6]="", longpath[PATH_MAX]="", batmsg[10]="";
FILE *meminfo,*cpuinfo,*batinfo;

void batcheckup(){
  sprintf(longpath,"/sys/class/power_supply/%s/capacity",batname);
if((batinfo=fopen(longpath,"r"))==NULL) {
  fprintf(stderr,"Error opening batinfo %s\n",longpath);
  exit(1);
}
fscanf(batinfo,"%f",&batnow);
fclose(batinfo);

/*  sprintf(longpath,"/sys/class/power_supply/%s/capacity",batname);
if((batinfo=fopen(longpath,"r"))==NULL) {
  fprintf(stderr,"Error opening batinfo %s\n",longpath);
  exit(1);
}
fscanf(batinfo,"%f",&batfull);
fclose(batinfo);
*/
sprintf(batmsg," %.1f%%B",(float)(batnow));
}

Complies and runs fine but as soon as I rum with the -bat option I get segfault.
Tried with different versions of the sprintf, same segfault every time. >:(
Any idea ???
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: curaga on April 17, 2010, 03:26:29 PM
Not really. You should probably try to build with debug symbols (-g) and run under gdb.

There are good beginner instructions for this on the Pidgin site if you haven't used gdb before.
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: mavrothal on April 18, 2010, 03:14:28 AM
Tried it but I just get "no stack" ??? when I try to exec-file either "watcher -bat" or "watcher --args -bat". So I do not really know if I really  run "watcher -bat" :(
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: curaga on April 18, 2010, 03:33:11 AM
gdb ./watcher
run -bat -otherargs
bt full
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: mavrothal on April 19, 2010, 12:00:33 PM
gdb ./watcher
run -bat -otherargs
bt full

Now this is something...
Run as above runs fine! No faults or anything.
run as ./watcher -bat -> segfault ???
change permissions, directory etc and run directly -> still segfault

bt full only reports
Code: [Select]
#0  0xb761ae68 in ___newselect_nocancel () from /lib/libc.so.6
No symbol table info available.
#1  0xb77df8fb in fl_wait () from /usr/lib/libfltk.so.1.1
No symbol table info available.
#2  0xb77a0bfd in Fl::wait () from /usr/lib/libfltk.so.1.1
No symbol table info available.
#3  0xb77a0cab in Fl::run () from /usr/lib/libfltk.so.1.1
No symbol table info available.
#4  0x08048df6 in main (argc=3, argv=0xbfd80a84) at watcher.cxx:223
        w = 164
        window = (struct Fl_Window *) 0x983d0a8
        box = (struct Fl_Box *) 0x983d130

 ???
Title: Re: Watcher, the cpu/mem/swap/battery meter
Post by: mavrothal on April 20, 2010, 11:35:33 PM
Oh, well...
I gutted watcher and turned it to xo_bat ;D, and this works fine.
Is just a battery monitor for the OLPC XO-1. Binary and source here (http://ftp.cc.uoc.gr/mirrors/linux/TinyCore_for_XO1/TC-XO_sources/)