Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: tinypoodle on March 23, 2013, 12:01:31 PM
-
Freqmon is a minimalistic approach to monitor CPU frequency in the context of dynamic frequency scaling.
Depends: aterm
Bugs: This version as is only supports 1 CPU (1 core).
-
Hi tinypoodle
On my monitor most of the displayed terminal is off the left side of the screen. Running Xorg7.5 at 1920x1080.
-
Thanks for reporting.
Either such is unexpected with "-geometry 4x2+0+30" or I am missing something...
It was supposed to align to left screen border.
-
New version without screen positioning attached, lets users window manager handle positioning.
-
Hi tinypoodle
Flwm_topside positioned it right on top of wbar. I would make it something like:
-geometry 4x2+30+30
just so it's visible. The end user will probably want to reposition it where they want it anyway.
-
The end user will probably want to reposition it where they want it anyway.
That is the idea, I only added geometry just before uploading it, thinking about some safe generic default, but that proves to be more complicated than I thought.
My motivation to write this was for "something which does not get in the way", after always having ended up with a default aterm sticky and top layer, just to keep track of cpufreq. I have a preference for "best value per screen estate", and 'watcher' which does an excellent job inspired me, the only thing it lacks for my needs was cpufreq. On my system I have freqmon right bottom, to have that extra newline which I didn't manage to eliminate off screen.
Attached with -geometry 4x2+30+30 as requested.
-
Hi tinypoodle
I have a preference for "best value per screen estate", and 'watcher' which does an excellent job....
Saving screen real estate is always a good thing however for some reason 'watch' always adds an extra line to it's output.
To save a line one could (theoretically) use this:
echo -en "\033[1;23f"
and call aterm with a geometry of 4x1
but that does not work.
If you are really keen on saving one line then why not try this:
printf '\33]2;%s\007' $MyVariableToDisplay
This will change the aterm title bar with the value in $MyVariableToDisplay
then use aterm with a geometry of 4x1.
Another advantage of using the title bar to display the required data is that the script can be minimized thus taking
no screen real estate at all and by simply glancing at the task bar will let you see it.
By the way, I also tried using a geometry of 4x0 since only the title bar is needed, but aterm goes bonkers.
One more thing that can be done is to right click on the title bar then select "shade".
This will leave only the title bar and thus saving one more line.
Hope it's of some help.
-
The title output sounds like an interesting approach, though not very portable, I guess. Not sure how exactly it would be done.
I tried piping output of watch to a named pipe and then using cat or dd, but I always get the extra line, yeah well, just gonna hide it off the bottom of screen :D
-
Hi tinypoodle
Using the title bar will work with terminals such as aterm, xterm and rxvt.
As regards the extra line, I am convinced that it's due to 'watch' because I tried with making the script loop with a timer
instead of using 'watch' and there was no extra line.
Perhaps 'tput' is the way to go as then there are no worries about portability and just maybe it will over-ride the extra line.
DESCRIPTION
The tput utility uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell
Something like:
tput cup <row> <column>
-
Yes, it's definitely watch - I ended up to nc the output (using 127.0.0.1 as address) from 1 aterm to another, exactly same result.
-
Hi guys
I did something similar for displaying time a while back and also struggled with getting rid of the line feed, but I did it.
Maybe there is something of use to you in my script:
http://forum.tinycorelinux.net/index.php/topic,13794.msg77140.html#msg77140
-
Thanks, but I really come to believe there is something particular to watch, which might make the newline unavoidable.
-
Also keep in mind that the watch that comes with TC is the BusyBox version and not the "normal" version
as found here: http://procps.cvs.sourceforge.net/viewvc/procps/procps/watch.c?revision=1.16&view=markup (http://procps.cvs.sourceforge.net/viewvc/procps/procps/watch.c?revision=1.16&view=markup)
Just had a quick look at the source and straight away I see differences with options available so there could be others too
that forces the extra line.
-
Not impossible.
-
Hi tinypoodle
I really come to believe there is something particular to watch, which might make the newline unavoidable.
I think you may be right. I tried stripping the newline like this:
watch -t grep M /proc/cpuinfo | tr -d '\n'
and got no output. If you don't mind replacing watch with sleep 2 then this works:
aterm -fade 100 -title Freqmon -fg green -bg black -ib 0 -bl +sb -cr black -geometry 4x1+30+30 -e sh -c "while true; do echo -ne '\033[1K\033[1G'; echo -ne `grep MHz /proc/cpuinfo | cut -d: -f2 | cut -d. -f1`; sleep 2; done" &
-
I tried stripping the newline like this:
watch -t grep M /proc/cpuinfo | tr -d '\n'
and got no output.
OMG yes! :o
That does the job!
Well... approximately, it sort of cripples the last of the 4 digits, which doesn't occur if size is 5x1.
I had tried '\n' in many ways, e.g. with sed and awk, but never invoked tr.
EDIT:
I think I figured what is happening with last digit, there is still a cursor, even if pseudo-invisible (same color as bg).
-
Hi tinypoodle
it sort of cripples the last of the 4 digits, which doesn't occur if size is 5x1.
Sorry, didn't notice that on my 863Mhz machine. This fixes it:
aterm -fade 100 -title Freqmon -fg green -bg black -ib 0 -bl +sb -geometry 4x1+30+30 -e sh -c "echo -ne '\033[?25l'; while true; do echo -ne '\033[1K\033[1G'; echo -ne `grep MHz /proc/cpuinfo | cut -d: -f2 | cut -d. -f1`; sleep 2; done" &
Added:
echo -ne '\033[?25l';
to hide the cursor and removed
-cr black
which was the black cursor obscuring the last digit.
-
aterm -fade 100 -title Freqmon -fg green -bg black -ib 0 -bl +sb -geometry 4x1+30+30 -e sh -c "echo -ne '\033[?25l'; while true; do echo -ne '\033[1K\033[1G'; echo -ne `grep MHz /proc/cpuinfo | cut -d: -f2 | cut -d. -f1`; sleep 2; done" &
This does not work for me at all, i.e. output will remain same as at the moment it is invoked.
Added:
echo -ne '\033[?25l';
to hide the cursor
Wondering if and how this could be combined with 'watch', as I really have a preference for using watch for many purposes.
Either way, increasing geometry by 1 horizontally is not a biggie, I am most happy with the method of using 'tr' to remove newline which you provided :D
-
Hi tinypoodle
... output will remain same as at the moment it is invoked.
You mean the numbers never change? Even if you make the machine do some work?
Wondering if and how this could be combined with 'watch', ...
Even though it only needs to be executed once, adding it like this works:
... -e watch -t "echo -ne '\033[?25l'; grep M ...
I am most happy with the method of using 'tr' to remove newline which you provided
Could you show me how you got tr to work? When I tried, I got no output, like it wasn't even running:
tc@box:~$ watch -t grep M /proc/cpuinfo | tr -d '\n'
^C
tc@box:~$ watch -t grep M /proc/cpuinfo | tr -d '\n'
^C
tc@box:~$
-
You mean the numbers never change? Even if you make the machine do some work?
Exactly
Even though it only needs to be executed once, adding it like this works:
... -e watch -t "echo -ne '\033[?25l'; grep M ...
Ah, thanks, I didn't know how exactly to integrate it.
So, adding that results in:
- Without tr, 5x1 : does not work
- Without tr, 4x2 : works as desired
- With tr, 4x1 : works as desired, with a side effect of output blinking.
Could you show me how you got tr to work? When I tried, I got no output, like it wasn't even running:
tc@box:~$ watch -t grep M /proc/cpuinfo | tr -d '\n'
^C
tc@box:~$ watch -t grep M /proc/cpuinfo | tr -d '\n'
^C
tc@box:~$
This command works for me, showing cursor positioned imminently after output.
Attached my version including tr, see at end of line. (working as desired with 4x1, side effect of last digit getting crippled by pseudo-invisible cursor).
-
Hi tinypoodle
(working as desired with 4x1, side effect of last digit getting crippled by pseudo-invisible cursor).
My machine shows the same effect, until I move the focus to another window, then the last digit is visible. If I
change it to this:
aterm -fade 100 -title Freqmon -fg green -bg black -cr black -ib 0 -bl +sb -geometry 4x1+30+30 -e watch -t "echo -ne '\033[?25l'; grep M /proc/cpuinfo|cut -d: -f2|cut -d. -f1|sed 's/^.//'|tr -d '\n'" &
the last digit is always visible.
- With tr, 4x1 : works as desired, with a side effect of output blinking.
The blinking "feature" tells you it's working. ::)
-
My machine shows the same effect, until I move the focus to another window, then the last digit is visible.
Here looks crippled when unfocused and invisible when focused.
aterm -fade 100 -title Freqmon -fg green -bg black -cr black -ib 0 -bl +sb -geometry 4x1+30+30 -e watch -t "echo -ne '\033[?25l'; grep M /proc/cpuinfo|cut -d: -f2|cut -d. -f1|sed 's/^.//'|tr -d '\n'" &
the last digit is always visible.
Works to perfection now, thanks a lot! :D
I can't see anything being different from what I had tried earlier... but... I later found multiple stale 'watch' PIDs running, leftovers from experiencing, so I suspect that may have been causing the excessive blinking (I didn't mean the characteristic to watch slight blinking, that's expected).
-
Oh, and '-cr black' has now become redundant