arbtt – automatic rule-base time tracker
The Automatic Rule-Based Time Tracker (arbtt) is a background daemon that stores which windows are open, which one has the focus and how long since your last action (and possibly more sources later), and stores this.
This is also software that will, based on expressive rules you specify, derive what you were doing, and what for.
This is free and open source software.