Better time management through profiling

By Abhijit Menon-Sen <>

This page is about the most potent charm in my long-standing quest for better time management: a program to help me keep track of exactly where and how my time is spent.

Of course, I can't tell you how best to manage your own time, but just as profiling is the best guide to code optimisation, I found it useful (and sometimes very surprising) to begin by knowing exactly where time goes. I've been very happy with the results, and I know of others who have evolved similar approaches to the problem.

Instrumentation

The idea is that you run a program (ts) every time you change what you are doing. This sounds intrusive, and it does take a while to get used to; but ts goes out of its way to make it easy, and it's almost second nature to me now. I find the benefits worth this extra investment.

To run ts, you will need to have Perl installed along with the DBI and DBD::Pg modules. You'll also need to provide a PostgreSQL database for it to use, and you'll have to create the activities table from ts.sql.

The profiling data is stored in this very simple SQL table:

    create table activities (
        id          serial,
        category    text not NULL,
        comment     text,
        started     timestamp(0) not NULL default current_timestamp,
        stopped     timestamp(0)
                    check (stopped is NULL or stopped > started)
    );

A row in this table describes a period of time spent on some activity. The category is usually something like "work/mail" or "work/src", the latter perhaps with a comment like "Fixing Jamfile". I find it useful to organise my activities into a hierarchy, but you can decide for yourself how you want to categorise things.

When you start a new activity ("ts work/src Fixing bug 42"), its started time is set, and the stopped time of any activity that doesn't have one (any activity that is in progress, in other words) is also set. You can also specify the start and end times explicitly ("ts -s 12:00 -e 12:30 lunch").

My .zshrc contains "compctl -/ -W ~/.categories ts", and I've created directories that reflect my categorisation under ~/.categories. Now I can do things like "ts w<TAB>e<TAB>" instead of having to type the category name ("work/email") in full.

Running ts without arguments explains how to use it.

Visualisation

Once the data is available, it's up to you to figure out how to use it to your advantage ("How much time did I spend on the phone last week?" "Let me generate a time sheet for work/some-client/code/" ...). Just playing with the data in psql is often instructive.

The tsc program generates sc spreadsheets from the profiling data. It presents, for a given time period (the last week by default), a list of the categories matching some pattern (everything by default), and a table (with totals) of how much time has been spent on them on each of the days in the period under consideration. (You need a patched version of sc to use tsc.)

I plan to write something that generates nicely-formatted time sheets from this data, but I haven't gotten around to it yet. If you have an interesting visualisation idea, please let me know.

Download

Here's a tarball of the source code. It contains the ts and tsc programs, the SQL table definition, a patch required for sc to understand the tsc output, and some documentation. (You can also download a patched version of sc.)

Please write to ams@toroid.org if you have any questions, comments, or suggestions. If this program is useful to you in some way, I'd love to hear about it.