Uptime


Alvin

Member
Joined
Mar 26, 2006
Messages
171
You know there's always those silly websites with people recording how long their computer has idled for? Well, I was poking around with my GP2X last night and remembered you could check how long it had been on.

Now, do you think people are willing enough to try this and have a competition? If you use the unmount utility from the wiki, you shouldn't have to reboot your GP2X unless you install new firmware. I know, I know, 2X's go really hot after a while and it will probably catch fire, but none the less, I'd like to see if people are willing to give this a go. Just type uptime into a terminal and it should say how long it's been on.

Find some way of proving it though, no cheating! Pictures or something.
 
Hmm, I run on batteries so no big score from me there. Also, the gp2x is usually carted around the house. A high uptime would take a psu and keeping it in one place? Longest uptime is when the wife is playing tilematch :)
Dunno how much interest you will strike up for this one but you never know.
 
would be interesting for recording how long the unit lasts with batteries... maybe someking of a script that works with a watch-dog type indicator that will show when the gp2x stopped responging (due to running out of juice)
 
Code:
dialog --title "Uptime recorder" --inputbox "Save uptime to" 8 60 2>/tmp/input.$$

sel=$?

file=`cat /tmp/input.$$`
case $sel in
    0)  echo "Uptime is being recorded, ^C to exit."
        while [ E ]
        do
            uptime > $file
            sync
        done;;
esac

rm -f /tmp/input.$$
sync

I hope that works. No output, although you can just add
Code:
echo "<string>"
to the loop.
 
Actually, if you're logging to the SD / NAND in a gp2x you might want to commit only once every 10 seconds or something. And possibly overwrite the file rather than delete/recreate.

You could easily run this script in the background if you wanted to record uptime, just have it spawn a menu process.

Or in C you could do something like:
Code:
#include <stdio.h>
main()
{
    FILE * out;
    long int uptime; /*not sure what type uptime returns. int?*/
    long int uptime_old;
    uptime=uptime_old=0;

    while(1)
    {
        uptime = system("/bin/uptime"); /*correct path?*/
        if(uptime > uptime_old+10000) /*milliseconds?  =10 seconds*/
        {
            uptime_old=uptime;
            out = fopen("uptime.log","w");
            fprintf(out,"%d",uptime);
            fclose (pFile);
            sync();
        }
    }

    return 0;
}

I think that should be right, but I haven't tested it (nor will I most likely)
 
In that case, does the GP2X have a cron daemon?
uptime is located in /usr/bin and returns something like:
Code:
alvin@localhost ~ $ /usr/bin/uptime
 15:04:39 up  5:08,  3 users,  load average: 0.32, 0.37, 0.46
 
critical posted on Mar 27 2006 at 02:46 PM said:
Alvin posted on Mar 27 2006 at 02:19 PM said:
Oops, forgot that! Thanks.
If you're really lucky, the unit won't run out of power as it's writing to flash.
heh, I didn't even consider that. I was more thinking about limiting the number of writes it would be doing.

Still, once every 10 seconds for a fraction of a second is low enough chance as far as I'm concerned. And you could always make it once every couple of minutes or so since timing to the second doesn't seem very important anyway.
 
Last edited by a moderator:
There's a file with the battery power somewhere if I remember (it was 2AM though, so I could be wrong, there is a directory in /usr/gp2x with some battery related things in it though, maybe just images). If that is low then you can stop recording the uptime, it wouldn't last much longer (providing it's set properly) anyway.
 
Alvin posted on Mar 27 2006 at 03:03 PM said:
In that case, does the GP2X have a cron daemon?
I kind of hope not. That would be pretty wasteful for the gp2x.
Alvin posted on Mar 27 2006 at 03:03 PM said:
uptime is located in /usr/bin
I'll leave updating it as an exercise for whoever feels like compiling it ;)
 
Last edited by a moderator:
Alvin posted on Mar 27 2006 at 03:08 PM said:
There's a file with the battery power somewhere if I remember
There's a node of /dev/ that squidge used for his cool battery monitor. It returns the current voltage.
 
Last edited by a moderator:
FluffyPanda posted on Mar 27 2006 at 03:10 PM said:
Alvin posted on Mar 27 2006 at 03:08 PM said:
There's a file with the battery power somewhere if I remember
There's a node of /dev/ that squidge used for his cool battery monitor. It returns the current voltage.
/dev/batt
 
Last edited by a moderator:
Alvin posted on Mar 27 2006 at 03:17 PM said:
FluffyPanda posted on Mar 27 2006 at 03:10 PM said:
Alvin posted on Mar 27 2006 at 03:08 PM said:
There's a file with the battery power somewhere if I remember
There's a node of /dev/ that squidge used for his cool battery monitor. It returns the current voltage.
/dev/batt
Reference and example code here:

http://wiki.gp2x.org/wiki/Devbatt
 
Last edited by a moderator:
I left mine running over USB Serial with this script:

Code:
#/bin/bash
s=0
m=0
h=0
while [ 1 ]
do
	sleep 1
	s=$((s+1))
	if [ $s = 60 ]; then
  s=0
  m=$((m+1))
	fi
	if [ $m = 60 ]; then
  m=0
  h=$((h+1))
	fi
	clear
	echo "$h:$m:$s"
done

I'm using it to time how long my batteries last. Haven't got round to it yet, though.
 
Back
Top