diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-13 12:57:48 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-13 12:57:48 -0800 |
commit | b58a893bf9ba96db9a544cd33af4828826b73061 (patch) | |
tree | fad6c5dfcfd5be12a702d9117d260db7bdc05254 /ddms/libs/ddmuilib/src | |
parent | 6990abcbc03c25aeff94da27ed6893e7993d2709 (diff) | |
download | sdk-b58a893bf9ba96db9a544cd33af4828826b73061.zip sdk-b58a893bf9ba96db9a544cd33af4828826b73061.tar.gz sdk-b58a893bf9ba96db9a544cd33af4828826b73061.tar.bz2 |
auto import from //branches/cupcake/...@131421
Diffstat (limited to 'ddms/libs/ddmuilib/src')
7 files changed, 477 insertions, 220 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java index fa3f0e4..d168476 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java @@ -200,22 +200,26 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen case DEVICE_COL_STATE: return getStateString(device); case DEVICE_COL_BUILD: { - String avdName = device.getAvdName(); - String debuggable = device.getProperty(Device.PROP_DEBUGGABLE); String version = device.getProperty(Device.PROP_BUILD_VERSION); - if (device.isEmulator()) { - if (debuggable != null && debuggable.equals("1")) { //$NON-NLS-1$ - return String.format("%1$s [%2$s, debug]", avdName, //$NON-NLS-1$ - version); + if (version != null) { + String debuggable = device.getProperty(Device.PROP_DEBUGGABLE); + if (device.isEmulator()) { + String avdName = device.getAvdName(); + if (debuggable != null && debuggable.equals("1")) { //$NON-NLS-1$ + return String.format("%1$s [%2$s, debug]", avdName, + version); + } else { + return String.format("%1$s [%2$s]", avdName, version); //$NON-NLS-1$ + } } else { - return String.format("%1$s [%2$s]", avdName, version); //$NON-NLS-1$ + if (debuggable != null && debuggable.equals("1")) { //$NON-NLS-1$ + return String.format("%1$s, debug", version); + } else { + return String.format("%1$s", version); //$NON-NLS-1$ + } } } else { - if (debuggable != null && debuggable.equals("1")) { //$NON-NLS-1$ - return String.format("%1$s, debug", version); //$NON-NLS-1$ - } else { - return String.format("%1$s", version); //$NON-NLS-1$ - } + return "unknown"; } } } diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySync.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySync.java index 0057c86..82cc7a4 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySync.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySync.java @@ -39,7 +39,7 @@ import java.util.List; import java.util.Scanner; import java.util.regex.Pattern; -public class DisplaySync extends EventDisplay { +public class DisplaySync extends SyncCommon { // Information to graph for each authority private TimePeriodValues mDatasetsSync[]; @@ -49,27 +49,12 @@ public class DisplaySync extends EventDisplay { // Dataset of error events to graph private TimeSeries mDatasetError; - - // State information while processing the event stream - private int mLastState; // 0 if event started, 1 if event stopped - private long mLastStartTime; // ms - private long mLastStopTime; //ms - private String mLastDetails; - private int mLastEvent; // server, poll, etc public DisplaySync(String name) { super(name); } /** - * Resets the display. - */ - @Override - void resetUI() { - initSyncDisplay(); - } - - /** * Creates the UI for the event display. * @param parent the parent composite. * @param logParser the current log parser. @@ -79,21 +64,22 @@ public class DisplaySync extends EventDisplay { public Control createComposite(final Composite parent, EventLogParser logParser, final ILogColumnListener listener) { Control composite = createCompositeChart(parent, logParser, "Sync Status"); - initSyncDisplay(); + resetUI(); return composite; } /** - * Initialize the Plot and series data for the sync display. + * Resets the display. */ - void initSyncDisplay() { + @Override + void resetUI() { + super.resetUI(); XYPlot xyPlot = mChart.getXYPlot(); XYBarRenderer br = new XYBarRenderer(); mDatasetsSync = new TimePeriodValues[NUM_AUTHS]; mTooltipsSync = new List[NUM_AUTHS]; mTooltipGenerators = new CustomXYToolTipGenerator[NUM_AUTHS]; - mLastDetails = ""; TimePeriodValuesCollection tpvc = new TimePeriodValuesCollection(); xyPlot.setDataset(tpvc); @@ -123,62 +109,29 @@ public class DisplaySync extends EventDisplay { br.setSeriesToolTipGenerator(i, mTooltipGenerators[i]); mTooltipGenerators[i].addToolTipSeries(mTooltipsSync[i]); - mDatasetsSyncTickle[i] = new TimeSeries(AUTH_NAMES[i] + " tickle", FixedMillisecond.class); + mDatasetsSyncTickle[i] = new TimeSeries(AUTH_NAMES[i] + " tickle", + FixedMillisecond.class); tsc.addSeries(mDatasetsSyncTickle[i]); ls.setSeriesShape(i, ShapeUtilities.createUpTriangle(2.5f)); } } /** - * Updates the display with a new event. This is the main entry point for - * each event. This method has the logic to tie together the start event, - * stop event, and details event into one graph item. Note that the details - * can happen before or after the stop event. - * @param event The event - * @param logParser the log parser (unused) + * Updates the display with a new event. + * + * @param event The event + * @param logParser The parser providing the event. */ @Override void newEvent(EventContainer event, EventLogParser logParser) { + super.newEvent(event, logParser); // Handle sync operation try { - if (event.mTag == EVENT_SYNC) { - int state = Integer.parseInt(event.getValueAsString(1)); - if (state == 0) { // start - mLastStartTime = (long)event.sec * 1000L + (event.nsec / 1000000L); - mLastState = 0; - mLastEvent = Integer.parseInt(event.getValueAsString(2)); - mLastDetails = ""; - } else if (state == 1) { // stop - if (mLastState == 0) { - mLastStopTime = (long)event.sec * 1000L + (event.nsec / 1000000L); - if (mLastStartTime == 0) { - // Log starts with a stop event - mLastStartTime = mLastStopTime; - } - addEvent(event); - mLastState = 1; - } - } - } else if (event.mTag == EVENT_TICKLE) { + if (event.mTag == EVENT_TICKLE) { int auth = getAuth(event.getValueAsString(0)); if (auth >= 0) { long msec = (long)event.sec * 1000L + (event.nsec / 1000000L); mDatasetsSyncTickle[auth].addOrUpdate(new FixedMillisecond(msec), -1); } - } else if (event.mTag == EVENT_SYNC_DETAILS) { - int auth = getAuth(event.getValueAsString(0)); - mLastDetails = event.getValueAsString(3); - if (mLastState != 0) { // Not inside event - long updateTime = (long)event.sec * 1000L + (event.nsec / 1000000L); - if (updateTime - mLastStopTime <= 250) { - // Got details within 250ms after event, so delete and re-insert - // Details later than 250ms (arbitrary) are discarded as probably - // unrelated. - int lastItem = mDatasetsSync[auth].getItemCount(); - mDatasetsSync[auth].delete(lastItem-1, lastItem-1); - mTooltipsSync[auth].remove(lastItem-1); - addEvent(event); - } - } } } catch (InvalidTypeException e) { } @@ -300,29 +253,31 @@ public class DisplaySync extends EventDisplay { return sb.toString(); } + /** - * Helper to add an event to the data series. - * Also updates error series if appropriate (x or X in details). - * @param event The event + * Callback to process a sync event. */ - private void addEvent(EventContainer event) { - try { - int auth = getAuth(event.getValueAsString(0)); - double height = getHeightFromDetails(mLastDetails); - height = height / (mLastStopTime - mLastStartTime + 1) * 10000; - if (height > 30) { - height = 30; - } - mDatasetsSync[auth].add(new SimpleTimePeriod(mLastStartTime, mLastStopTime), height); - mTooltipsSync[auth].add(getTextFromDetails(auth, mLastDetails, - mLastEvent)); - mTooltipGenerators[auth].addToolTipSeries(mTooltipsSync[auth]); - if (mLastDetails.indexOf('x') >= 0 || mLastDetails.indexOf('X') >= 0) { - long msec = (long)event.sec * 1000L + (event.nsec / 1000000L); - mDatasetError.addOrUpdate(new FixedMillisecond(msec), -1); - } - } catch (InvalidTypeException e) { - e.printStackTrace(); + @Override + void processSyncEvent(EventContainer event, int auth, long startTime, long stopTime, + String details, boolean newEvent, int syncSource) { + if (!newEvent) { + // Details arrived for a previous sync event + // Remove event before reinserting. + int lastItem = mDatasetsSync[auth].getItemCount(); + mDatasetsSync[auth].delete(lastItem-1, lastItem-1); + mTooltipsSync[auth].remove(lastItem-1); + } + double height = getHeightFromDetails(details); + height = height / (stopTime - startTime + 1) * 10000; + if (height > 30) { + height = 30; + } + mDatasetsSync[auth].add(new SimpleTimePeriod(startTime, stopTime), height); + mTooltipsSync[auth].add(getTextFromDetails(auth, details, syncSource)); + mTooltipGenerators[auth].addToolTipSeries(mTooltipsSync[auth]); + if (details.indexOf('x') >= 0 || details.indexOf('X') >= 0) { + long msec = (long)event.sec * 1000L + (event.nsec / 1000000L); + mDatasetError.addOrUpdate(new FixedMillisecond(msec), -1); } } diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySyncHistogram.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySyncHistogram.java index 3087997..36d90ce 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySyncHistogram.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySyncHistogram.java @@ -18,7 +18,6 @@ package com.android.ddmuilib.log.event; import com.android.ddmlib.log.EventContainer; import com.android.ddmlib.log.EventLogParser; -import com.android.ddmlib.log.InvalidTypeException; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.jfree.chart.plot.XYPlot; @@ -35,29 +34,18 @@ import java.util.HashMap; import java.util.Map; import java.util.TimeZone; -public class DisplaySyncHistogram extends EventDisplay { +public class DisplaySyncHistogram extends SyncCommon { + Map<SimpleTimePeriod, Integer> mTimePeriodMap[]; - // State information while processing the event stream - protected int mLastState; // 0 if event started, 1 if event stopped - protected long mLastStartTime; // ms - protected long mLastStopTime; //ms - protected String mLastDetails; - protected int mLastEvent; // server, poll, etc + // Information to graph for each authority + private TimePeriodValues mDatasetsSyncHist[]; public DisplaySyncHistogram(String name) { super(name); } /** - * Resets the display. - */ - @Override - void resetUI() { - initSyncHistogramDisplay(); - } - - /** * Creates the UI for the event display. * @param parent the parent composite. * @param logParser the current log parser. @@ -67,22 +55,20 @@ public class DisplaySyncHistogram extends EventDisplay { public Control createComposite(final Composite parent, EventLogParser logParser, final ILogColumnListener listener) { Control composite = createCompositeChart(parent, logParser, "Sync Histogram"); - initSyncHistogramDisplay(); + resetUI(); return composite; } - // Information to graph for each authority - private TimePeriodValues mDatasetsSyncHist[]; - /** - * Initializes the display. + * Resets the display. */ - private void initSyncHistogramDisplay() { + @Override + void resetUI() { + super.resetUI(); XYPlot xyPlot = mChart.getXYPlot(); AbstractXYItemRenderer br = new XYBarRenderer(); mDatasetsSyncHist = new TimePeriodValues[NUM_AUTHS+1]; - mLastDetails = ""; mTimePeriodMap = new HashMap[NUM_AUTHS + 1]; TimePeriodValuesCollection tpvc = new TimePeriodValuesCollection(); @@ -99,72 +85,44 @@ public class DisplaySyncHistogram extends EventDisplay { } /** - * Updates the display with a new event. This is the main entry point for - * each event. This method has the logic to tie together the start event, - * stop event, and details event into one graph item. Note that the details - * can happen before or after the stop event. - * @param event The event + * Callback to process a sync event. + * + * @param event The sync event + * @param startTime Start time (ms) of events + * @param stopTime Stop time (ms) of events + * @param details Details associated with the event. + * @param newEvent True if this event is a new sync event. False if this event + * @param syncSource */ @Override - void newEvent(EventContainer event, EventLogParser logParser) { - try { - if (event.mTag == EVENT_SYNC) { - int state = Integer.parseInt(event.getValueAsString(1)); - if (state == 0) { // start - mLastStartTime = (long)event.sec * 1000L + (event.nsec / 1000000L); - mLastState = 0; - mLastEvent = Integer.parseInt(event.getValueAsString(2)); - mLastDetails = ""; - } else if (state == 1) { // stop - if (mLastState == 0) { - mLastStopTime = (long)event.sec * 1000L + (event.nsec / 1000000L); - if (mLastStartTime == 0) { - // Log starts with a stop event - mLastStartTime = mLastStopTime; - } - int auth = getAuth(event.getValueAsString(0)); - if (mLastDetails.indexOf('x') >= 0 || mLastDetails.indexOf('X') >= 0) { - auth = ERRORS; - } - double delta = (mLastStopTime - mLastStartTime) * 100. / 1000 / 3600; // Percent of hour - addHistEvent(event, auth, delta); - mLastState = 1; - } - } - } else if (event.mTag == EVENT_SYNC_DETAILS) { - int auth = getAuth(event.getValueAsString(0)); - mLastDetails = event.getValueAsString(3); - if (mLastState != 0) { // Not inside event - long updateTime = (long)event.sec * 1000L + (event.nsec / 1000000L); - if (updateTime - mLastStopTime <= 250) { - // Got details within 250ms after event, so delete and re-insert - // Details later than 250ms (arbitrary) are discarded as probably - // unrelated. - //int lastItem = mDatasetsSync[auth].getItemCount(); - //addHistEvent(event); - if (mLastDetails.indexOf('x') >= 0 || mLastDetails.indexOf('X') >= 0) { - // Item turns out to be in error, so transfer time from old auth to error. - - double delta = (mLastStopTime - mLastStartTime) * 100. / 1000 / 3600; // Percent of hour - addHistEvent(event, auth, -delta); - addHistEvent(event, ERRORS, delta); - } - } - } + void processSyncEvent(EventContainer event, int auth, long startTime, long stopTime, + String details, boolean newEvent, int syncSource) { + if (newEvent) { + if (details.indexOf('x') >= 0 || details.indexOf('X') >= 0) { + auth = ERRORS; + } + double delta = (stopTime - startTime) * 100. / 1000 / 3600; // Percent of hour + addHistEvent(0, auth, delta); + } else { + // sync_details arrived for an event that has already been graphed. + if (details.indexOf('x') >= 0 || details.indexOf('X') >= 0) { + // Item turns out to be in error, so transfer time from old auth to error. + double delta = (stopTime - startTime) * 100. / 1000 / 3600; // Percent of hour + addHistEvent(0, auth, -delta); + addHistEvent(0, ERRORS, delta); } - } catch (InvalidTypeException e) { } } /** * Helper to add an event to the data series. * Also updates error series if appropriate (x or X in details). - * @param event The event - * @param auth - * @param value + * @param stopTime Time event ends + * @param auth Sync authority + * @param value Value to graph for event */ - private void addHistEvent(EventContainer event, int auth, double value) { - SimpleTimePeriod hour = getTimePeriod(mLastStopTime, mHistWidth); + private void addHistEvent(long stopTime, int auth, double value) { + SimpleTimePeriod hour = getTimePeriod(stopTime, mHistWidth); // Loop over all datasets to do the stacking. for (int i = auth; i <= ERRORS; i++) { @@ -172,9 +130,8 @@ public class DisplaySyncHistogram extends EventDisplay { } } - Map<SimpleTimePeriod, Integer> mTimePeriodMap[]; - - private void addToPeriod(TimePeriodValues tpv[], int auth, SimpleTimePeriod period, double value) { + private void addToPeriod(TimePeriodValues tpv[], int auth, SimpleTimePeriod period, + double value) { int index; if (mTimePeriodMap[auth].containsKey(period)) { index = mTimePeriodMap[auth].get(period); @@ -198,7 +155,8 @@ public class DisplaySyncHistogram extends EventDisplay { TimeZone zone = RegularTimePeriod.DEFAULT_TIME_ZONE; Calendar calendar = Calendar.getInstance(zone); calendar.setTime(date); - long hoursOfYear = calendar.get(Calendar.HOUR_OF_DAY) + calendar.get(Calendar.DAY_OF_YEAR) * 24; + long hoursOfYear = calendar.get(Calendar.HOUR_OF_DAY) + + calendar.get(Calendar.DAY_OF_YEAR) * 24; int year = calendar.get(Calendar.YEAR); hoursOfYear = (hoursOfYear / numHoursWide) * numHoursWide; calendar.clear(); diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySyncPerf.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySyncPerf.java new file mode 100644 index 0000000..9ce7045 --- /dev/null +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/DisplaySyncPerf.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ddmuilib.log.event; + +import com.android.ddmlib.log.EventContainer; +import com.android.ddmlib.log.EventLogParser; +import com.android.ddmlib.log.InvalidTypeException; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.jfree.chart.labels.CustomXYToolTipGenerator; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYBarRenderer; +import org.jfree.data.time.SimpleTimePeriod; +import org.jfree.data.time.TimePeriodValues; +import org.jfree.data.time.TimePeriodValuesCollection; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +public class DisplaySyncPerf extends SyncCommon { + + CustomXYToolTipGenerator mTooltipGenerator; + List mTooltips[]; + + // The series number for each graphed item. + // sync authorities are 0-3 + private static final int DB_QUERY = 4; + private static final int DB_WRITE = 5; + private static final int HTTP_NETWORK = 6; + private static final int HTTP_PROCESSING = 7; + private static final int NUM_SERIES = (HTTP_PROCESSING + 1); + private static final String SERIES_NAMES[] = {"Calendar", "Gmail", "Feeds", "Contacts", + "DB Query", "DB Write", "HTTP Response", "HTTP Processing",}; + private static final Color SERIES_COLORS[] = {Color.MAGENTA, Color.GREEN, Color.BLUE, + Color.ORANGE, Color.RED, Color.CYAN, Color.PINK, Color.DARK_GRAY}; + private static final double SERIES_YCOORD[] = {0, 0, 0, 0, 1, 1, 2, 2}; + + // Values from data/etc/event-log-tags + private static final int EVENT_DB_OPERATION = 52000; + private static final int EVENT_HTTP_STATS = 52001; + // op types for EVENT_DB_OPERATION + final int EVENT_DB_QUERY = 0; + final int EVENT_DB_WRITE = 1; + + // Information to graph for each authority + private TimePeriodValues mDatasets[]; + + /** + * TimePeriodValuesCollection that supports Y intervals. This allows the + * creation of "floating" bars, rather than bars rooted to the axis. + */ + class YIntervalTimePeriodValuesCollection extends TimePeriodValuesCollection { + /** default serial UID */ + private static final long serialVersionUID = 1L; + + private double yheight; + + /** + * Constructs a collection of bars with a fixed Y height. + * + * @param yheight The height of the bars. + */ + YIntervalTimePeriodValuesCollection(double yheight) { + this.yheight = yheight; + } + + /** + * Returns ending Y value that is a fixed amount greater than the starting value. + * + * @param series the series (zero-based index). + * @param item the item (zero-based index). + * @return The ending Y value for the specified series and item. + */ + @Override + public Number getEndY(int series, int item) { + return getY(series, item).doubleValue() + yheight; + } + } + + /** + * Constructs a graph of network and database stats. + * + * @param name The name of this graph in the graph list. + */ + public DisplaySyncPerf(String name) { + super(name); + } + + /** + * Creates the UI for the event display. + * + * @param parent the parent composite. + * @param logParser the current log parser. + * @return the created control (which may have children). + */ + @Override + public Control createComposite(final Composite parent, EventLogParser logParser, + final ILogColumnListener listener) { + Control composite = createCompositeChart(parent, logParser, "Sync Performance"); + resetUI(); + return composite; + } + + /** + * Resets the display. + */ + @Override + void resetUI() { + super.resetUI(); + XYPlot xyPlot = mChart.getXYPlot(); + xyPlot.getRangeAxis().setVisible(false); + mTooltipGenerator = new CustomXYToolTipGenerator(); + mTooltips = new List[NUM_SERIES]; + + XYBarRenderer br = new XYBarRenderer(); + br.setUseYInterval(true); + mDatasets = new TimePeriodValues[NUM_SERIES]; + + TimePeriodValuesCollection tpvc = new YIntervalTimePeriodValuesCollection(1); + xyPlot.setDataset(tpvc); + xyPlot.setRenderer(br); + + for (int i = 0; i < NUM_SERIES; i++) { + br.setSeriesPaint(i, SERIES_COLORS[i]); + mDatasets[i] = new TimePeriodValues(SERIES_NAMES[i]); + tpvc.addSeries(mDatasets[i]); + mTooltips[i] = new ArrayList<String>(); + mTooltipGenerator.addToolTipSeries(mTooltips[i]); + br.setSeriesToolTipGenerator(i, mTooltipGenerator); + } + } + + /** + * Updates the display with a new event. + * + * @param event The event + * @param logParser The parser providing the event. + */ + @Override + void newEvent(EventContainer event, EventLogParser logParser) { + super.newEvent(event, logParser); // Handle sync operation + try { + if (event.mTag == EVENT_DB_OPERATION) { + // 52000 db_operation (name|3),(op_type|1|5),(time|2|3) + String tip = event.getValueAsString(0); + long endTime = (long) event.sec * 1000L + (event.nsec / 1000000L); + int opType = Integer.parseInt(event.getValueAsString(1)); + long duration = Long.parseLong(event.getValueAsString(2)); + + if (opType == EVENT_DB_QUERY) { + mDatasets[DB_QUERY].add(new SimpleTimePeriod(endTime - duration, endTime), + SERIES_YCOORD[DB_QUERY]); + mTooltips[DB_QUERY].add(tip); + } else if (opType == EVENT_DB_WRITE) { + mDatasets[DB_WRITE].add(new SimpleTimePeriod(endTime - duration, endTime), + SERIES_YCOORD[DB_WRITE]); + mTooltips[DB_WRITE].add(tip); + } + } else if (event.mTag == EVENT_HTTP_STATS) { + // 52001 http_stats (useragent|3),(response|2|3),(processing|2|3),(tx|1|2),(rx|1|2) + String tip = event.getValueAsString(0) + ", tx:" + event.getValueAsString(3) + + ", rx: " + event.getValueAsString(4); + long endTime = (long) event.sec * 1000L + (event.nsec / 1000000L); + long netEndTime = endTime - Long.parseLong(event.getValueAsString(2)); + long netStartTime = netEndTime - Long.parseLong(event.getValueAsString(1)); + mDatasets[HTTP_NETWORK].add(new SimpleTimePeriod(netStartTime, netEndTime), + SERIES_YCOORD[HTTP_NETWORK]); + mDatasets[HTTP_PROCESSING].add(new SimpleTimePeriod(netEndTime, endTime), + SERIES_YCOORD[HTTP_PROCESSING]); + mTooltips[HTTP_NETWORK].add(tip); + mTooltips[HTTP_PROCESSING].add(tip); + } + } catch (InvalidTypeException e) { + } + } + + /** + * Callback from super.newEvent to process a sync event. + * + * @param event The sync event + * @param startTime Start time (ms) of events + * @param stopTime Stop time (ms) of events + * @param details Details associated with the event. + * @param newEvent True if this event is a new sync event. False if this event + * @param syncSource + */ + @Override + void processSyncEvent(EventContainer event, int auth, long startTime, long stopTime, + String details, boolean newEvent, int syncSource) { + if (newEvent) { + mDatasets[auth].add(new SimpleTimePeriod(startTime, stopTime), SERIES_YCOORD[auth]); + } + } + + /** + * Gets display type + * + * @return display type as an integer + */ + @Override + int getDisplayType() { + return DISPLAY_TYPE_SYNC_PERF; + } +} diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventDisplay.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventDisplay.java index bbd3e1b..2223a4d 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventDisplay.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventDisplay.java @@ -45,7 +45,6 @@ import org.jfree.data.time.TimeSeriesCollection; import org.jfree.experimental.chart.swt.ChartComposite; import org.jfree.experimental.swt.SWTUtils; -import java.awt.Color; import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.Date; @@ -71,27 +70,12 @@ abstract class EventDisplay { public final static int DISPLAY_TYPE_GRAPH = 2; public final static int DISPLAY_TYPE_SYNC = 3; public final static int DISPLAY_TYPE_SYNC_HIST = 4; + public final static int DISPLAY_TYPE_SYNC_PERF = 5; private final static int EVENT_CHECK_FAILED = 0; protected final static int EVENT_CHECK_SAME_TAG = 1; protected final static int EVENT_CHECK_SAME_VALUE = 2; - // Some common variables for sync display. These define the sync backends - //and how they should be displayed. - protected static final int CALENDAR = 0; - protected static final int GMAIL = 1; - protected static final int FEEDS = 2; - protected static final int CONTACTS = 3; - protected static final int ERRORS = 4; - protected static final int NUM_AUTHS = (CONTACTS + 1); - protected static final String AUTH_NAMES[] = {"Calendar", "Gmail", "Feeds", "Contacts", "Errors"}; - protected static final Color AUTH_COLORS[] = {Color.MAGENTA, Color.GREEN, Color.BLUE, Color.ORANGE, Color.RED}; - - // Values from data/etc/event-log-tags - final int EVENT_SYNC = 2720; - final int EVENT_TICKLE = 2742; - final int EVENT_SYNC_DETAILS = 2743; - /** * Creates the appropriate EventDisplay subclass. * @@ -111,8 +95,10 @@ abstract class EventDisplay { return new DisplaySyncHistogram(name); case DISPLAY_TYPE_GRAPH: return new DisplayGraph(name); + case DISPLAY_TYPE_SYNC_PERF: + return new DisplaySyncPerf(name); default: - throw new InvalidParameterException("Unknown Display Type"); //$NON-NLS-1$ + throw new InvalidParameterException("Unknown Display Type " + type); //$NON-NLS-1$ } } @@ -982,28 +968,4 @@ abstract class EventDisplay { long getHistWidth() { return mHistWidth; } - - /** - * Convert authority name to auth number. - * - * @param authname "calendar", etc. - * @return number series number associated with the authority - */ - protected int getAuth(String authname) throws InvalidTypeException { - if ("calendar".equals(authname) || "cl".equals(authname)) { - return CALENDAR; - } else if ("contacts".equals(authname) || "cp".equals(authname)) { - return CONTACTS; - } else if ("subscribedfeeds".equals(authname)) { - return FEEDS; - } else if ("gmail-ls".equals(authname) || "mail".equals(authname)) { - return GMAIL; - } else if ("gmail-live".equals(authname)) { - return GMAIL; - } else if ("unknown".equals(authname)) { - return -1; // Unknown tickles; discard - } else { - throw new InvalidTypeException("Unknown authname " + authname); - } - } } diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventDisplayOptions.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventDisplayOptions.java index b9daa41..88c3cb2 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventDisplayOptions.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventDisplayOptions.java @@ -438,7 +438,8 @@ class EventDisplayOptions extends Dialog { mDisplayTypeCombo.add("Filtered Log"); mDisplayTypeCombo.add("Graph"); mDisplayTypeCombo.add("Sync"); - mDisplayTypeCombo.add("Sync histogram"); + mDisplayTypeCombo.add("Sync Histogram"); + mDisplayTypeCombo.add("Sync Performance"); mDisplayTypeCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/SyncCommon.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/SyncCommon.java new file mode 100644 index 0000000..108c097 --- /dev/null +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/SyncCommon.java @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ddmuilib.log.event; + +import com.android.ddmlib.log.EventContainer; +import com.android.ddmlib.log.EventLogParser; +import com.android.ddmlib.log.InvalidTypeException; + +import java.awt.Color; + +abstract public class SyncCommon extends EventDisplay { + + // State information while processing the event stream + private int mLastState; // 0 if event started, 1 if event stopped + private long mLastStartTime; // ms + private long mLastStopTime; //ms + private String mLastDetails; + private int mLastSyncSource; // poll, server, user, etc. + + // Some common variables for sync display. These define the sync backends + //and how they should be displayed. + protected static final int CALENDAR = 0; + protected static final int GMAIL = 1; + protected static final int FEEDS = 2; + protected static final int CONTACTS = 3; + protected static final int ERRORS = 4; + protected static final int NUM_AUTHS = (CONTACTS + 1); + protected static final String AUTH_NAMES[] = {"Calendar", "Gmail", "Feeds", "Contacts", + "Errors"}; + protected static final Color AUTH_COLORS[] = {Color.MAGENTA, Color.GREEN, Color.BLUE, + Color.ORANGE, Color.RED}; + + // Values from data/etc/event-log-tags + final int EVENT_SYNC = 2720; + final int EVENT_TICKLE = 2742; + final int EVENT_SYNC_DETAILS = 2743; + + protected SyncCommon(String name) { + super(name); + } + + /** + * Resets the display. + */ + @Override + void resetUI() { + mLastStartTime = 0; + mLastStopTime = 0; + mLastState = -1; + mLastSyncSource = -1; + mLastDetails = ""; + } + + /** + * Updates the display with a new event. This is the main entry point for + * each event. This method has the logic to tie together the start event, + * stop event, and details event into one graph item. The combined sync event + * is handed to the subclass via processSycnEvent. Note that the details + * can happen before or after the stop event. + * + * @param event The event + * @param logParser The parser providing the event. + */ + @Override + void newEvent(EventContainer event, EventLogParser logParser) { + try { + if (event.mTag == EVENT_SYNC) { + int state = Integer.parseInt(event.getValueAsString(1)); + if (state == 0) { // start + mLastStartTime = (long) event.sec * 1000L + (event.nsec / 1000000L); + mLastState = 0; + mLastSyncSource = Integer.parseInt(event.getValueAsString(2)); + mLastDetails = ""; + } else if (state == 1) { // stop + if (mLastState == 0) { + mLastStopTime = (long) event.sec * 1000L + (event.nsec / 1000000L); + if (mLastStartTime == 0) { + // Log starts with a stop event + mLastStartTime = mLastStopTime; + } + int auth = getAuth(event.getValueAsString(0)); + processSyncEvent(event, auth, mLastStartTime, mLastStopTime, mLastDetails, + true, mLastSyncSource); + mLastState = 1; + } + } + } else if (event.mTag == EVENT_SYNC_DETAILS) { + mLastDetails = event.getValueAsString(3); + if (mLastState != 0) { // Not inside event + long updateTime = (long) event.sec * 1000L + (event.nsec / 1000000L); + if (updateTime - mLastStopTime <= 250) { + // Got details within 250ms after event, so delete and re-insert + // Details later than 250ms (arbitrary) are discarded as probably + // unrelated. + int auth = getAuth(event.getValueAsString(0)); + processSyncEvent(event, auth, mLastStartTime, mLastStopTime, mLastDetails, + false, mLastSyncSource); + } + } + } + } catch (InvalidTypeException e) { + } + } + + /** + * Callback hook for subclass to process a sync event. newEvent has the logic + * to combine start and stop events and passes a processed event to the + * subclass. + * + * @param event The sync event + * @param auth The sync authority + * @param startTime Start time (ms) of events + * @param stopTime Stop time (ms) of events + * @param details Details associated with the event. + * @param newEvent True if this event is a new sync event. False if this event + * @param syncSource Poll, user, server, etc. + */ + abstract void processSyncEvent(EventContainer event, int auth, long startTime, long stopTime, + String details, boolean newEvent, int syncSource); + + /** + * Converts authority name to auth number. + * + * @param authname "calendar", etc. + * @return number series number associated with the authority + */ + protected int getAuth(String authname) throws InvalidTypeException { + if ("calendar".equals(authname) || "cl".equals(authname)) { + return CALENDAR; + } else if ("contacts".equals(authname) || "cp".equals(authname)) { + return CONTACTS; + } else if ("subscribedfeeds".equals(authname)) { + return FEEDS; + } else if ("gmail-ls".equals(authname) || "mail".equals(authname)) { + return GMAIL; + } else if ("gmail-live".equals(authname)) { + return GMAIL; + } else if ("unknown".equals(authname)) { + return -1; // Unknown tickles; discard + } else { + throw new InvalidTypeException("Unknown authname " + authname); + } + } +} |