How to measure that how much time is the active window opened

gnomewindow

How can we measure that in a given period, what window was on the top? (active one)

I already tried based on "wmctrl", but I can't show the currently active window.. in the second example I tried with ":ACTIVE:", it showed ALL again, but only the terminal was the active then..

$ wmctrl -l | awk '$2 != "-1"'
0x044006a3  8 notebook Mozilla Firefox
0x0456fb4c  0 notebook How to measure that how much time is the active window opened? - Unix & Linux Stack Exchange - Mozilla Firefox
0x03000004  0 notebook Terminal
$ 
$ wmctrl -l :ACTIVE: | awk '$2 != "-1"'
0x044006a3  8 notebook Mozilla Firefox
0x0456fb4c  0 notebook How to measure that how much time is the active window opened? - Unix & Linux Stack Exchange - Mozilla Firefox
0x03000004  0 notebook Terminal
$ 

Purpose: The output would be something like this (from an example 8 hour shift, so 480 minutes):

MINUTE  TASK
195 Mozilla Firefox
165 Terminal
74  Thunderbird
36  Idle (was away, machine locked, no app was on top..)
10  Unknown (the machine wasn't powered on)

With the awk '$2 != "-1"' I just excluded the "Bottom Expanded Edge Panel".

Question: I only need the part that how can I show the currently active window. I can do the part where I run a script in ex.: every 10 seconds and gather the time information.

p.s.: I'm using Ubuntu 12.04 or CentOS 6 both with GNOME.

Best Answer

The tool arbtt (link1 & link2) sounds like what you want.

excerpt #1

The Automatic Rule-Based Time Tracker is a desktop daemon that runs in the background and, every minute, records what windows are open on your desktop, what their titles are, which one is active. The accompanied statistics program lets you derive information from this log file, i.e. what how much of your time have you been spending with e-Mail, or what projects are your largest time wasters. The mapping from the raw window titles to sensible „tags“ is done by a configuration file with an powerful syntax. See the documentation for more detailed information.

excerpt #2

arbtt, on the other hand, is a time tracker that gets out of the way. Its core component (arbtt-capture) silently captures data about what you are doing, completely autonomously. No interaction required, no distraction possible. This information is continuously stored in a log file. A separate tool (arbtt-stats) the allows you to investigate this data, at whatever time is convenient to you, by using simple text-based rules.

You initially need to setup a rules file that arbtt-capture, a daemon, runs which collects the statistics on the various apps as you run them. Later on you can then use the other tool arbtt-stat to get a "report" of usage.

And here's the corresponding output of arbtt-stats -c "Program":

Statistics for category "Program"
=================================
__________________Tag_|_________Time_|_Percentage_
      Program:Firefox |  8d06h20m00s |      49.01
Program:Google Chrome |  3d15h24m00s |      21.60
  Program:Text editor |  1d04h04m00s |       6.94
        Program:Skype |    13h55m00s |       3.44
     Program:Terminal |     9h22m00s |       2.31
   Program:PDF reader |     6h10m00s |       1.52
      Program:Desktop |     5h13m00s |       1.29
 Program:File browser |     4h11m00s |       1.03
 (53 entries omitted) |    22h59m00s |       5.68
Related Question