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: begin

D/TAG     ( 4434): onClick:      390 ms, long thing done

D/TAG     ( 4434): onClick:      412 ms, long thing done again

D/TAG     ( 4434): onClick: end, 802 ms

D/TraceviewActivity( 4434): finished

In order to get anything at all into the log from this you need to set the logging level on the emulator (or device) to VERBOSE. You do this with the following command line:

$ adb shell setprop log.tag.TAG VERBOSE

 What I find curious about this is that the log messages are prefixed with 'D' - this indicates that these are Debug level messages. However if you set the device logging level to DEBUG you don't see anything. All of the documentation says that these are VERBOSE items, but the D is still there...

Comments

Popular posts from this blog

Building a choropleth map for Irish agricultural data

Early Stopping with Keras

AutoCompleteTextView backed with data from SQLite in Android