Posts

Showing posts with the label Utility

Handy utility to log timings

TimingLogger is a handy class provided by Google. It is built into Android, so you don't need to do anything to set it up. It acts like a stopwatch within a method, in that it allows you to 'hit the split button' a number of times (attaching a message each time) and the dump this whole lot out to the log in one go. This avoids any messing with trying to filter the log to just return your times of interest. For example here is an onClick method I wrote: public void onClick(View v) {                                TimingLogger timings = new TimingLogger("TAG", "onClick"); longThing(); timings.addSplit("long thing done"); longThing(); timings.addSplit("long thing done again"); longThing(); timings.dumpToLog(); Log.d(TAG, "finished"); } The output in the log once dumpToLog is called is this: D/TAG     ( 4434): onClick: ...