Commit c2ecb39e authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Capture the duration for a Descriptive Statistics measurement

parent 4dabbcdd
...@@ -136,6 +136,8 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -136,6 +136,8 @@ public class MetricOutputDAO extends AbstractOutput {
private final Map<String, List<SimHost>> hostsByGroup; private final Map<String, List<SimHost>> hostsByGroup;
private long timestampLastEvent = -1;
public MetricDaoAdapter(ActiveMetric metric) { public MetricDaoAdapter(ActiveMetric metric) {
this.metric = metric; this.metric = metric;
this.md = new MetricDescription(MetricOutputDAO.class.getName(), this.md = new MetricDescription(MetricOutputDAO.class.getName(),
...@@ -201,9 +203,14 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -201,9 +203,14 @@ public class MetricOutputDAO extends AbstractOutput {
} }
} }
// Write Group stats // Write Group stats
long observationDuration = Time.getCurrentTime() - timestampLastEvent;
if (timestampLastEvent == -1) {
observationDuration = Time.getCurrentTime() - timeEnableDao;
}
MeasurementDAO.storeGroupStatisticsMeasurement(md, MeasurementDAO.storeGroupStatisticsMeasurement(md,
group, time, stats); group, time, stats, observationDuration, false);
} }
timestampLastEvent = Time.getCurrentTime();
} else { } else {
for (SimHost host : hosts) { for (SimHost host : hosts) {
MetricValue mv = metric.getPerHostMetric(host.getId()); MetricValue mv = metric.getPerHostMetric(host.getId());
......
...@@ -151,13 +151,21 @@ public class MeasurementDAO extends DAO { ...@@ -151,13 +151,21 @@ public class MeasurementDAO extends DAO {
* A time for the measurement in simulation time * A time for the measurement in simulation time
* @param stats * @param stats
* the {@link DescriptiveStatistics} object used as input * the {@link DescriptiveStatistics} object used as input
* @param observationDuration
* duration of this observation in simulation time
* @param describesWholeSimulation
* true, if this measurement is a description of the WHOLE
* simulation
*/ */
public static void storeGroupStatisticsMeasurement( public static void storeGroupStatisticsMeasurement(
MetricDescription metricDesc, String groupName, long time, MetricDescription metricDesc, String groupName, long time,
DescriptiveStatistics stats) { DescriptiveStatistics stats, long observationDuration,
boolean describesWholeSimulation) {
Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc); Metric metric = MetricDAO.lookupStatisticsMetric(metricDesc);
GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric, groupName); GroupMetric groupMetric = GroupMetricDAO.lookupGroupMetric(metric,
MeasurementStatistic measurement = new MeasurementStatistic(time, stats, groupMetric); groupName);
MeasurementStatistic measurement = new MeasurementStatistic(time, stats,
groupMetric, observationDuration, describesWholeSimulation);
addToPersistQueue(measurement); addToPersistQueue(measurement);
} }
......
...@@ -58,6 +58,16 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -58,6 +58,16 @@ public class MeasurementStatistic implements GroupMetricBound {
@Column(nullable = true, name = "[time]") @Column(nullable = true, name = "[time]")
private long time; private long time;
@Column(nullable = false, name = "[describesWholeSimulation]")
private boolean describesWholeSimulation;
/**
* The simulation time for to this measurement in simulator time, that is,
* microseconds.
*/
@Column(nullable = true, name = "[observationDuration]")
private long observationDuration;
/** /**
* The number of values * The number of values
*/ */
...@@ -70,7 +80,6 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -70,7 +80,6 @@ public class MeasurementStatistic implements GroupMetricBound {
@Column(nullable = true, name = "[sum2]") @Column(nullable = true, name = "[sum2]")
private Double sum2; private Double sum2;
/** /**
* The minimum of all values for this measurement * The minimum of all values for this measurement
*/ */
...@@ -101,6 +110,12 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -101,6 +110,12 @@ public class MeasurementStatistic implements GroupMetricBound {
@Column(nullable = true, name = "[perc2]") @Column(nullable = true, name = "[perc2]")
private Double perc2; // 2,3 private Double perc2; // 2,3
@Column(nullable = true, name = "[perc95]")
private Double perc95; // 95
@Column(nullable = true, name = "[perc5]")
private Double perc5; // 5
@Column(nullable = true, name = "[skewness]") @Column(nullable = true, name = "[skewness]")
private Double skewness; private Double skewness;
...@@ -125,24 +140,32 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -125,24 +140,32 @@ public class MeasurementStatistic implements GroupMetricBound {
* @param hostMetric * @param hostMetric
* The reference to the {@link HostMetric}-Object, which * The reference to the {@link HostMetric}-Object, which
* describes this metric. Is used for the mapping. * describes this metric. Is used for the mapping.
* @param observationDuration
* duration of the observation
* @param describesWholeSimulation
* true, if this measurement describes the whole simulation
*/ */
public MeasurementStatistic(long time, DescriptiveStatistics stats, public MeasurementStatistic(long time, DescriptiveStatistics stats,
GroupMetric groupMetric) { GroupMetric groupMetric, long observationDuration,
this(time, stats); boolean describesWholeSimulation) {
this(time, stats, observationDuration, describesWholeSimulation);
this.groupMetric = groupMetric; this.groupMetric = groupMetric;
} }
/** /**
* Internal - write statistics * Internal - write statistics
*
* @param time * @param time
* @param stats * @param stats
* @param observationDuration
* duration covered by this measurement in simulation units
*/ */
private MeasurementStatistic(long time, DescriptiveStatistics stats) { private MeasurementStatistic(long time, DescriptiveStatistics stats,
long observationDuration, boolean describesWholeSimulation) {
super(); super();
this.time = time; this.time = time;
/* this.observationDuration = observationDuration;
* TODO add stats this.describesWholeSimulation = describesWholeSimulation;
*/
this.values = checkForSpecialNumbers((double) stats.getN()); this.values = checkForSpecialNumbers((double) stats.getN());
this.sum = checkForSpecialNumbers(stats.getSum()); this.sum = checkForSpecialNumbers(stats.getSum());
this.sum2 = checkForSpecialNumbers(stats.getSumsq()); this.sum2 = checkForSpecialNumbers(stats.getSumsq());
...@@ -154,6 +177,8 @@ public class MeasurementStatistic implements GroupMetricBound { ...@@ -154,6 +177,8 @@ public class MeasurementStatistic implements GroupMetricBound {
this.perc25 = checkForSpecialNumbers(stats.getPercentile(25)); this.perc25 = checkForSpecialNumbers(stats.getPercentile(25));
this.perc75 = checkForSpecialNumbers(stats.getPercentile(75)); this.perc75 = checkForSpecialNumbers(stats.getPercentile(75));
this.perc97 = checkForSpecialNumbers(stats.getPercentile(97.7)); this.perc97 = checkForSpecialNumbers(stats.getPercentile(97.7));
this.perc5 = checkForSpecialNumbers(stats.getPercentile(5));
this.perc95 = checkForSpecialNumbers(stats.getPercentile(95));
this.skewness = checkForSpecialNumbers(stats.getSkewness()); this.skewness = checkForSpecialNumbers(stats.getSkewness());
this.kurtosis = checkForSpecialNumbers(stats.getKurtosis()); this.kurtosis = checkForSpecialNumbers(stats.getKurtosis());
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment