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
CommitLineData
378e7718 1/*******************************************************************************
576f0a4e 2 * Copyright (c) 2009, 2014 Ericsson
20ff3b75 3 *
378e7718
WB
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
20ff3b75 8 *
378e7718
WB
9 * Contributors:
10 * William Bourque - Initial API and implementation
c392540b
FC
11 * Yuriy Vashchuk - Heritage correction.
12 * Francois Chouinard - Cleanup and refactoring
e0752744 13 * Francois Chouinard - Moved from LTTng to TMF
95aa81ef 14 * Simon Delisle - Added a new parameter to the constructor
2fc582d2 15 * Xavier Raynaud - Support multi-trace coloring
378e7718 16 *******************************************************************************/
c392540b 17
2bdf0193 18package org.eclipse.tracecompass.tmf.ui.views.histogram;
6e512b93 19
2bdf0193
AM
20import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
21import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
22import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
23import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
2bdf0193 24import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
6e512b93 25
378e7718 26/**
95aa81ef
JCK
27 * Class to request events for given time range from a trace to fill a
28 * HistogramDataModel and HistogramView.
20ff3b75 29 *
b544077e
BH
30 * @version 1.0
31 * @author Francois Chouinard
95aa81ef 32 * <p>
378e7718 33 */
6256d8ad 34public class HistogramRequest extends TmfEventRequest {
c392540b
FC
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
b544077e
BH
40 /**
41 * The histogram data model to fill.
42 */
fbd124dd 43 protected final HistogramDataModel fHistogram;
c392540b 44
95aa81ef
JCK
45 private final boolean fFullRange;
46
c392540b
FC
47 // ------------------------------------------------------------------------
48 // Constructor
49 // ------------------------------------------------------------------------
50
95aa81ef
JCK
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
95aa81ef
JCK
68 */
69 public HistogramRequest(HistogramDataModel histogram, TmfTimeRange range,
70 int rank, int nbEvents, int blockSize,
fd3f1eff 71 ITmfEventRequest.ExecutionType execType, boolean fullRange) {
5cc0453a 72 super(ITmfEvent.class, range, rank, nbEvents, execType);
95aa81ef
JCK
73 fHistogram = histogram;
74 fFullRange = fullRange;
c392540b
FC
75 }
76
c392540b
FC
77 // ------------------------------------------------------------------------
78 // TmfEventRequest
79 // ------------------------------------------------------------------------
20ff3b75 80
b544077e
BH
81 /**
82 * Handle the event from the trace by updating the histogram data model.
20ff3b75 83 *
95aa81ef
JCK
84 * @param event
85 * a event from the trace
2bdf0193 86 * @see org.eclipse.tracecompass.tmf.core.request.TmfEventRequest#handleData(org.eclipse.tracecompass.tmf.core.event.ITmfEvent)
b544077e 87 */
c392540b 88 @Override
e0752744 89 public void handleData(ITmfEvent event) {
c392540b 90 super.handleData(event);
4540412a
PT
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);
95aa81ef 97
4540412a 98 } else { /* handle lost event */
16801c72 99 long timestamp = event.getTimestamp().toNanos();
4540412a
PT
100 fHistogram.countEvent(getNbRead(), timestamp, event.getTrace());
101 }
102 }
7ef9ae3f 103 }
6e512b93 104 }
c392540b 105
b544077e 106 /**
95aa81ef
JCK
107 * Complete the request. It also notifies the histogram model about the
108 * completion.
20ff3b75 109 *
2bdf0193 110 * @see org.eclipse.tracecompass.tmf.core.request.TmfEventRequest#handleCompleted()
b544077e 111 */
6e512b93 112 @Override
5419a136 113 public void handleCompleted() {
fbd124dd 114 fHistogram.complete();
c392540b 115 super.handleCompleted();
6e512b93 116 }
6e512b93 117}
This page took 0.112315 seconds and 5 git commands to generate.