GNOME Bugzilla – Bug 597406
Stop tracking when suspended
Last modified: 2012-09-24 18:32:53 UTC
It would be nice to be able to "Stop tracking when suspended" (=> when the computer is in standby or sleeping). Maybe a checkbox for this would be right, as in "Stop tracking when computer becomes idle" or "Stop tracking on shutdown".
I looked into this a while ago. The trick is that Hamster merely records beginning time, and ending time; as such there is no real good way to "pause" the tracking. The only option would be to stop tracking once the computer is in standby, and start a new tracking item when the computer comes out of standby. I'll look into the possibility.
The problem is there is no guarantee of delivering any signals (or being able to handle them) before suspend kicks in. Detecting resume is easy but it won't tell us when the suspend happened (actually, adding the suspension timestamp to the "resumed" signal seems to be the best solution - any kernel devs around?).
Then how do we currently stop tracking during suspend?
We rely on the signal from power manager... which fails under load when sometimes the machine goes to sleep before you get to receive/handle the signal :)
Why not record current clock time (prev_wall_clock_tm) every-so-often (e.g. time tracker resolution / 2 == T). Then sleep for T. In each loop compare prev_wall_clock_tm with the current time; if the difference is > than (T + some_tolerance) then we must have gone through a suspend period. In that case, conclude the previous timing with the prev_wall_clock_tm and start new tracking item.
moved https://github.com/projecthamster/hamster/issues/8