What apps do I use most?

This is going to be my first ever ‘tech’ post on my blog, thanks to Avinash. Yesterday when we were chatting casually, he mentioned of creating an app that would track the apps that consume most of his time on the computer. It seemed a very interesting tool to have, I googled a bit and found that X on GNU/Linux platforms has a very nice querying interface through ‘xprop’ and the complete list of reference is over here: http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html . So I hacked up a small script that prints active window every 10s, here it is:

while 1; do
active_wid=$(xprop -root _NET_ACTIVE_WINDOW | cut -d’#’ -f2|tr -d ‘ ‘)
active_pid=$(xprop -id $active_wid _NET_WM_PID| cut -d’=’ -f2|tr -d ‘ ‘)
active_process=$(ps -p $active_pid -o comm= )
echo $active_process
sleep 10
done;

Avinash came up with another hacked script for windows:

#include <windows.h>
#include <cstdlib>
#include <cstdio>
#include <ctime>
using namespace std;
void delay (clock_t sec);
int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    while (1) {
        HWND wind = GetForegroundWindow();
        LPTSTR titlebartext;
        if (GetWindowText( wind, titlebartext, 100 ) != 0) {
            printf (“\n%s”, titlebartext);
        }
        delay (3);
    }
}
void delay (clock_t sec) {
    clock_t start_time = clock();
    clock_t end_time = sec * 1000 + start_time;
    while(clock() != end_time);
    return;
}
(PS: If you want to use it for any real world app, then kindly consider switching over from busy-wait to timer/signal based wait – http://www.kernel.org/doc/man-pages/online/pages/man2/timer_create.2.html )
I had the following output some time later:

chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
chromium-browse
~
gedit
~
pidgin
~
pidgin
~
pidgin
~
pidgin
~
gnome-terminal

It was my browsing time clearly ;). Until next time, happy analyzing :).

(UPDATED: 5mins after posting)

We also had an interesting conversation along line, here it is:

Avinash Krishnan: a linux person is also the kind of person who doesn’t nned to monitor his productivity quite as closely as a windows person. 😛
Adarsh: lol, true 😉
Adarsh: but I think there already exists such tools for windows
Avinash Krishnan: but, counter-irony : a windows person is also the kind of person who, when presented with performance data, i snot likely to act on it.
Avinash Krishnan: * is not likely
Avinash Krishnan: so, its useless for windows.
Avinash Krishnan: 😛
Adarsh: right 😛

2 Replies to “What apps do I use most?”

  1. Consider using the WM_NAME field from xprop output too..
    That’ll tell you /what/ you were browsing, or with /whom/ you were chatting, 😉 , with a side-effect that you might not post /that/ data quite as readily on your blog. 😛

  2. Hi,

    I created a similar application sometime ago.
    I made it in java, and added some analytics feature to it.
    It sums up the total time spend on a particular application for the entire week and gives pie charts.

    Checkout https://sourceforge.net/projects/jitendriya/

    Right now this “window name finding” part works only on windows.
    Trying to get it to work on linux.

    Thanks
    Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.