tmf.all: use ITmfTimestamp#toNanos when possible
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / histogram / HistogramRequest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * William Bourque - Initial API and implementation
11 * Yuriy Vashchuk - Heritage correction.
12 * Francois Chouinard - Cleanup and refactoring
13 * Francois Chouinard - Moved from LTTng to TMF
14 * Simon Delisle - Added a new parameter to the constructor
15 * Xavier Raynaud - Support multi-trace coloring
16 *******************************************************************************/
17
18 package org.eclipse.tracecompass.tmf.ui.views.histogram;
19
20 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
21 import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
22 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
23 import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
24 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
25
26 /**
27 * Class to request events for given time range from a trace to fill a
28 * HistogramDataModel and HistogramView.
29 *
30 * @version 1.0
31 * @author Francois Chouinard
32 * <p>
33 */
34 public class HistogramRequest extends TmfEventRequest {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 /**
41 * The histogram data model to fill.
42 */
43 protected final HistogramDataModel fHistogram;
44
45 private final boolean fFullRange;
46
47 // ------------------------------------------------------------------------
48 // Constructor
49 // ------------------------------------------------------------------------
50
51 /**
52 * Constructor
53 *
54 * @param histogram
55 * The histogram data model
56 * @param range
57 * The time range to request data
58 * @param rank
59 * The index of the first event to retrieve
60 * @param nbEvents
61 * The number of events requested
62 * @param blockSize
63 * The number of events per block
64 * @param execType
65 * The requested execution priority
66 * @param fullRange
67 * Full range or time range for histogram request
68 */
69 public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range,
70 int rank, int nbEvents, int blockSize,
71 ITmfEventRequest.ExecutionType execType, boolean fullRange) {
72 super(ITmfEvent.class, range, rank, nbEvents, execType);
73 fHistogram = histogram;
74 fFullRange = fullRange;
75 }
76
77 // ------------------------------------------------------------------------
78 // TmfEventRequest
79 // ------------------------------------------------------------------------
80
81 /**
82 * Handle the event from the trace by updating the histogram data model.
83 *
84 * @param event
85 * a event from the trace
86 * @see org.eclipse.tracecompass.tmf.core.request.TmfEventRequest#handleData(org.eclipse.tracecompass.tmf.core.event.ITmfEvent)
87 */
88 @Override
89 public void handleData(ITmfEvent event) {
90 super.handleData(event);
91 synchronized (fHistogram) {
92 if (!isCancelled()) {
93 if (event instanceof ITmfLostEvent) {
94 ITmfLostEvent lostEvents = (ITmfLostEvent) event;
95 /* clear the old data when it is a new request */
96 fHistogram.countLostEvent(lostEvents.getTimeRange(), lostEvents.getNbLostEvents(), fFullRange);
97
98 } else { /* handle lost event */
99 long timestamp = event.getTimestamp().toNanos();
100 fHistogram.countEvent(getNbRead(), timestamp, event.getTrace());
101 }
102 }
103 }
104 }
105
106 /**
107 * Complete the request. It also notifies the histogram model about the
108 * completion.
109 *
110 * @see org.eclipse.tracecompass.tmf.core.request.TmfEventRequest#handleCompleted()
111 */
112 @Override
113 public void handleCompleted() {
114 fHistogram.complete();
115 super.handleCompleted();
116 }
117 }
This page took 0.034525 seconds and 5 git commands to generate.