I highly recommend RescueTime, which tracks exactly this - it looks at what software you are interacting with/what websites you are on, and reports many hours a week you were on your computer and how much of that was productive. For example, last week I was on my computer 30 hours (I had a lot of meetings) and I was productive 75% of that time, which averages to 4.5 hours of productive computer time per workday.
It's neat to track my productive hours per week over time - I can see clear cycles based on projects, number of meetings, and my general motivation level. Some weeks I'll average just 2-3 hours of productive time a day, others I can get close to 6. 5-6 hours seems to be a ceiling on how long I can spend coding in one day.