Bug 741281 - Add Telemetry timers in Java. r=blassey

This commit is contained in:
Gian-Carlo Pascutto 2012-04-12 23:19:57 +02:00
parent c81eabf714
commit 587c7e6213

View File

@ -5,9 +5,9 @@
package org.mozilla.gecko;
import android.os.SystemClock;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -33,4 +33,23 @@ public class Telemetry {
Log.e(LOGTAG, "JSON exception: ", e);
}
}
public static class Timer {
private long mStartTime;
private String mName;
public Timer(String name) {
mName = name;
mStartTime = SystemClock.uptimeMillis();
}
public void stop() {
long elapsed = SystemClock.uptimeMillis() - mStartTime;
if (elapsed < Integer.MAX_VALUE) {
HistogramAdd(mName, (int)(elapsed));
} else {
Log.e(LOGTAG, "Duration of " + elapsed + " ms is too long.");
}
}
}
}