From 66ae9f7ed411830a4fa96ed19cea8f11c47250ef Mon Sep 17 00:00:00 2001 From: dswitkin Date: Fri, 11 Apr 2008 21:16:08 +0000 Subject: [PATCH] Added 'T' as a shortcut to toggle debug method tracing using android.os.Debug and traceview for analysis. The traces are written to /sdcard, which means the SD Card must not be mounted as a volume by USB at the time. Tracing can slow down decoding by a factor of 5 or more but gives very useful insights into where the time is going. git-svn-id: https://zxing.googlecode.com/svn/trunk@358 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- android-m3/res/values/ids.xml | 1 + .../android/BarcodeReaderCaptureActivity.java | 2 ++ .../zxing/client/android/CameraThread.java | 5 +++ .../zxing/client/android/DecodeThread.java | 35 +++++++++++++++---- android-m3/strings.xml.template | 2 +- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/android-m3/res/values/ids.xml b/android-m3/res/values/ids.xml index be39f8eaa..688fc6041 100644 --- a/android-m3/res/values/ids.xml +++ b/android-m3/res/values/ids.xml @@ -23,6 +23,7 @@ + diff --git a/android-m3/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java b/android-m3/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java index 861f44940..b5453ca46 100644 --- a/android-m3/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java +++ b/android-m3/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java @@ -110,6 +110,8 @@ public final class BarcodeReaderCaptureActivity extends Activity { cameraThread.setDecodeQRMode(); } else if (keyCode == KeyEvent.KEYCODE_S) { cameraManager.setUsePreviewForDecode(false); + } else if (keyCode == KeyEvent.KEYCODE_T) { + cameraThread.toggleTracing(); } else if (keyCode == KeyEvent.KEYCODE_U) { cameraThread.setDecode1DMode(); } else { diff --git a/android-m3/src/com/google/zxing/client/android/CameraThread.java b/android-m3/src/com/google/zxing/client/android/CameraThread.java index 1c3644056..b8f27a395 100644 --- a/android-m3/src/com/google/zxing/client/android/CameraThread.java +++ b/android-m3/src/com/google/zxing/client/android/CameraThread.java @@ -144,6 +144,11 @@ final class CameraThread extends Thread { message.sendToTarget(); } + public void toggleTracing() { + Message message = Message.obtain(decodeThread.handler, R.id.toggle_tracing); + message.sendToTarget(); + } + /** * Start a decode if possible, but not now if the DecodeThread is in the middle of saving. */ diff --git a/android-m3/src/com/google/zxing/client/android/DecodeThread.java b/android-m3/src/com/google/zxing/client/android/DecodeThread.java index efdcfef28..2c4b90409 100644 --- a/android-m3/src/com/google/zxing/client/android/DecodeThread.java +++ b/android-m3/src/com/google/zxing/client/android/DecodeThread.java @@ -18,6 +18,7 @@ package com.google.zxing.client.android; import android.app.Application; import android.graphics.Bitmap; +import android.os.Debug; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -51,10 +52,14 @@ final class DecodeThread extends Thread { private final CameraManager cameraManager; private Hashtable hints; private Handler cameraThreadHandler; + private int methodTraceCount; + private boolean tracing; DecodeThread(BarcodeReaderCaptureActivity activity, CameraManager cameraManager) { this.activity = activity; this.cameraManager = cameraManager; + methodTraceCount = 0; + tracing = false; } @Override @@ -81,6 +86,9 @@ final class DecodeThread extends Thread { case R.id.set_decode_QR_mode: setDecodeQRMode(); break; + case R.id.toggle_tracing: + tracing = !tracing; + break; } } }; @@ -123,19 +131,32 @@ final class DecodeThread extends Thread { Message restart = Message.obtain(cameraThreadHandler, R.id.decode_started); restart.sendToTarget(); - Result rawResult; + if (tracing) { + Debug.startMethodTracing("/sdcard/ZXingDecodeThread" + methodTraceCount); + methodTraceCount++; + } + boolean success; + Result rawResult = null; try { MonochromeBitmapSource source = new RGBMonochromeBitmapSource(bitmap); rawResult = new MultiFormatReader().decode(source, hints); + success = true; } catch (ReaderException e) { - Message failure = Message.obtain(cameraThreadHandler, R.id.decode_failed); - failure.sendToTarget(); - return; + success = false; + } + if (tracing) { + Debug.stopMethodTracing(); } Date endDate = new Date(); - Message success = Message.obtain(cameraThreadHandler, R.id.decode_succeeded, rawResult); - success.arg1 = (int) (endDate.getTime() - startDate.getTime()); - success.sendToTarget(); + + if (success) { + Message message = Message.obtain(cameraThreadHandler, R.id.decode_succeeded, rawResult); + message.arg1 = (int) (endDate.getTime() - startDate.getTime()); + message.sendToTarget(); + } else { + Message message = Message.obtain(cameraThreadHandler, R.id.decode_failed); + message.sendToTarget(); + } } /** diff --git a/android-m3/strings.xml.template b/android-m3/strings.xml.template index 3b5d67278..f6acd899d 100644 --- a/android-m3/strings.xml.template +++ b/android-m3/strings.xml.template @@ -22,7 +22,7 @@ About... Help... ZXing Barcode Reader v@VERSION@\nhttp://code.google.com/p/zxing - A: Decode all barcodes\nC: Capture and save a JPEG\nP: Use the preview image for decoding\nQ: Decode only QR Codes\nS: Use a still image for decoding\nU: Decode only UPC/1D barcodes + A: Decode all barcodes\nC: Capture and save a JPEG\nP: Use the preview image for decoding\nQ: Decode only QR Codes\nS: Use a still image for decoding\nT: Toggle debug method tracing\nU: Decode only UPC/1D barcodes About Add Contact? Barcode Detected