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
This commit is contained in:
dswitkin 2008-04-11 21:16:08 +00:00
parent 4c10031a67
commit 66ae9f7ed4
5 changed files with 37 additions and 8 deletions

View file

@ -23,6 +23,7 @@
<item type="id" name="set_decode_all_mode"/>
<item type="id" name="set_decode_1D_mode"/>
<item type="id" name="set_decode_QR_mode"/>
<item type="id" name="toggle_tracing"/>
<item type="id" name="decode_started"/>
<item type="id" name="decode_succeeded"/>
<item type="id" name="decode_failed"/>

View file

@ -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 {

View file

@ -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.
*/

View file

@ -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<DecodeHintType, Object> 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();
}
}
/**

View file

@ -22,7 +22,7 @@
<string name="menu_about">About...</string>
<string name="menu_help">Help...</string>
<string name="msg_about">ZXing Barcode Reader v@VERSION@\nhttp://code.google.com/p/zxing</string>
<string name="msg_help">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</string>
<string name="msg_help">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</string>
<string name="title_about">About</string>
<string name="title_add_contact">Add Contact?</string>
<string name="title_barcode_detected">Barcode Detected</string>