FileDocCategorySizeDatePackage
DisplaySyncHistogram.javaAPI DocAndroid 1.5 API6441Wed May 06 22:41:08 BST 2009com.android.ddmuilib.log.event

DisplaySyncHistogram

public class DisplaySyncHistogram extends SyncCommon

Fields Summary
Map[]
mTimePeriodMap
private org.jfree.data.time.TimePeriodValues[]
mDatasetsSyncHist
Constructors Summary
public DisplaySyncHistogram(String name)

        super(name);
    
Methods Summary
private voidaddHistEvent(long stopTime, int auth, double value)
Helper to add an event to the data series. Also updates error series if appropriate (x or X in details).

param
stopTime Time event ends
param
auth Sync authority
param
value Value to graph for event

        SimpleTimePeriod hour = getTimePeriod(stopTime, mHistWidth);

        // Loop over all datasets to do the stacking.
        for (int i = auth; i <= ERRORS; i++) {
            addToPeriod(mDatasetsSyncHist, i, hour, value);
        }
    
private voidaddToPeriod(org.jfree.data.time.TimePeriodValues[] tpv, int auth, org.jfree.data.time.SimpleTimePeriod period, double value)

        int index;
        if (mTimePeriodMap[auth].containsKey(period)) {
            index = mTimePeriodMap[auth].get(period);
            double oldValue = tpv[auth].getValue(index).doubleValue();
            tpv[auth].update(index, oldValue + value);
        } else {
            index = tpv[auth].getItemCount();
            mTimePeriodMap[auth].put(period, index);
            tpv[auth].add(period, value);
        }
    
public org.eclipse.swt.widgets.ControlcreateComposite(org.eclipse.swt.widgets.Composite parent, com.android.ddmlib.log.EventLogParser logParser, ILogColumnListener listener)
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).

        Control composite = createCompositeChart(parent, logParser, "Sync Histogram");
        resetUI();
        return composite;
    
intgetDisplayType()
Gets display type

return
display type as an integer

        return DISPLAY_TYPE_SYNC_HIST;
    
private org.jfree.data.time.SimpleTimePeriodgetTimePeriod(long time, long numHoursWide)
Creates a multiple-hour time period for the histogram.

param
time Time in milliseconds.
param
numHoursWide: should divide into a day.
return
SimpleTimePeriod covering the number of hours and containing time.

        Date date = new Date(time);
        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;
        int year = calendar.get(Calendar.YEAR);
        hoursOfYear = (hoursOfYear / numHoursWide) * numHoursWide;
        calendar.clear();
        calendar.set(year, 0, 1, 0, 0); // Jan 1
        long start = calendar.getTimeInMillis() + hoursOfYear * 3600 * 1000;
        return new SimpleTimePeriod(start, start + numHoursWide * 3600 * 1000);
    
voidprocessSyncEvent(com.android.ddmlib.log.EventContainer event, int auth, long startTime, long stopTime, java.lang.String details, boolean newEvent, int syncSource)
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

        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);
            }
        }
    
voidresetUI()
Resets the display.

        super.resetUI();
        XYPlot xyPlot = mChart.getXYPlot();

        AbstractXYItemRenderer br = new XYBarRenderer();
        mDatasetsSyncHist = new TimePeriodValues[NUM_AUTHS+1];
        mTimePeriodMap = new HashMap[NUM_AUTHS + 1];

        TimePeriodValuesCollection tpvc = new TimePeriodValuesCollection();
        xyPlot.setDataset(tpvc);
        xyPlot.setRenderer(br);

        for (int i = 0; i < NUM_AUTHS + 1; i++) {
            br.setSeriesPaint(i, AUTH_COLORS[i]);
            mDatasetsSyncHist[i] = new TimePeriodValues(AUTH_NAMES[i]);
            tpvc.addSeries(mDatasetsSyncHist[i]);
            mTimePeriodMap[i] = new HashMap<SimpleTimePeriod, Integer>();

        }