diff options
author | Siva Velusamy <vsiva@google.com> | 2011-08-29 15:37:30 -0700 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2011-09-01 13:17:08 -0700 |
commit | 58c55cdc5f9173f337fcb143105790f2affa5c6e (patch) | |
tree | 46cec28c5b09833e045693f20d6eb0cb312abf84 /ddms | |
parent | d9e813f08e94442050d18dcc9ac5949577f7618a (diff) | |
download | sdk-58c55cdc5f9173f337fcb143105790f2affa5c6e.zip sdk-58c55cdc5f9173f337fcb143105790f2affa5c6e.tar.gz sdk-58c55cdc5f9173f337fcb143105790f2affa5c6e.tar.bz2 |
Reduce the number of UI refreshes of the logcat table.
Currently, every time a logcat message is received, the UI is refreshed.
If multiple messages are received in close succession, multiple refreshes
are enqueued to the UI thread to be run. This results in the UI spending
all its time refreshing the table.
This patch adds a refresh to the queue only if there are no pending
refreshes. We can do so since any refresh automatically picks up the latest
state of the logcat messages received.
Change-Id: I2d9df679299710e54986c86a3610d3546924aba8
Diffstat (limited to 'ddms')
-rw-r--r-- | ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java index eda5fe9..c80e16e 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java @@ -714,19 +714,38 @@ public final class LogCatPanel extends SelectionDependentPanel }); } + /** Task currently submitted to {@link Display#asyncExec} to be run in UI thread. */ + private LogCatTableRefresherTask mCurrentRefresher; + + /** + * Refresh the logcat table asynchronously from the UI thread. + * This method adds a new async refresh only if there are no pending refreshes for the table. + * Doing so eliminates redundant refresh threads from being queued up to be run on the + * display thread. + */ private void refreshLogCatTable() { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (mViewer.getTable().isDisposed()) { - return; - } - mViewer.refresh(); + synchronized (this) { + if (mCurrentRefresher == null) { + mCurrentRefresher = new LogCatTableRefresherTask(); + Display.getDefault().asyncExec(mCurrentRefresher); + } + } + } - if (shouldScrollToLatestLog()) { - scrollToLatestLog(); - } + private class LogCatTableRefresherTask implements Runnable { + public void run() { + if (mViewer.getTable().isDisposed()) { + return; } - }); + synchronized (LogCatPanel.this) { + mCurrentRefresher = null; + } + mViewer.refresh(); + + if (shouldScrollToLatestLog()) { + scrollToLatestLog(); + } + } } /** Scroll to the last line. */ |