You are not logged in.

#1 2015-08-09 21:11:12

Gregosky
Member
From: UK
Registered: 2013-07-26
Posts: 174

Logging time spent on active window

Hi guys,

I have been googling and could not find anything that would help me to measure how much time do I waste when sitting in front of computer.
I would like to measure time of active windows (so i.e. if I'm doing coding and kwrite is opened and active I would like to know how much time I have spent on it, and if in the meantime I do firefox to check facebook I want that logged)

I found this: https://www.archlinux.org/packages/comm … e-tracker/
- the problem with that is that (as far as I understand) it is not fully background thing, I have to switch tasks myself - and I would like such program to do all the measurements behind the scenes.

I also found this comparison: http://alternativeto.net/software/time- … form=linux
- most of the stuff listed there is 'freemium' which won't show up in our repos

Do you guys know a software package I would use to measure time spent on active window?

Offline

#2 2015-08-09 23:03:11

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Logging time spent on active window

Not System Admin, moving to "Applications & Desktop Environments"

Offline

#3 2015-08-09 23:44:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: Logging time spent on active window

I don't know much about the programs you refer to - but unless you need some fancy interface, there isn't much needed for this.  The following code will track any focus changes and output tab separated values of a unix time stamp and the title of the (newly) focused window.  If you pipe this to a file, you can pull it into your favorite spreadsheet or data analysis software and do whatever calculations or summary statistics you'd like.

#include <stdio.h>
#include <time.h>
#include <X11/Xlib.h>

int main() {
        Display *dpy = XOpenDisplay(0x0);
        XSelectInput(dpy, DefaultRootWindow(dpy), FocusChangeMask);
        Window win;
        int ignore;
        char *title;
        XEvent ev;
        while (!XNextEvent(dpy,&ev)) {
                XGetInputFocus(dpy, &win, &ignore);
                if (XFetchName(dpy, win, &title)) {
                        printf("%d\t%s\n", time(NULL), title);
                        XFree(title);
                }
        }
        return 0;
}

(compile with `gcc -o track track.c -lX11`)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2015-08-10 10:45:33

Gregosky
Member
From: UK
Registered: 2013-07-26
Posts: 174

Re: Logging time spent on active window

Thanks Trilby,

Would I then run this program only once on startup or somehow bind it to KDE?

Offline

#5 2015-08-10 10:57:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: Logging time spent on active window

That's up to you - it has to be started after X.  If I were to use it, I'd put it in my xinitrc:

track > ~/track.log &

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2015-08-10 14:38:24

Gregosky
Member
From: UK
Registered: 2013-07-26
Posts: 174

Re: Logging time spent on active window

I see - the program runs in infinite loop waiting for events. So when added to xinitrc it will simply run after X. I assume when system will shut down the program will just receive kill (therefore system won't hung waiting for the program to terminate),
Need to test this, thanks Trillby!

Offline

Board footer

Powered by FluxBB