blob: e49277703bdf90bca8baaf5ac390f0efed6e58b0 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.perfmon;
2
3import java.io.IOException;
4import java.sql.Timestamp;
5
6
7import org.codehaus.jackson.JsonGenerator;
8import org.codehaus.jackson.JsonProcessingException;
9import org.codehaus.jackson.map.JsonSerializer;
10import org.codehaus.jackson.map.SerializerProvider;
11
12public class CumulativeTimeBucketJSONSerializer
13 extends JsonSerializer<CumulativeTimeBucket> {
14 /**
15 * Performs the serialization of a OneComponentTime object
16 */
17 @Override
18 public void serialize(CumulativeTimeBucket ctb,
19 JsonGenerator jGen,
20 SerializerProvider serializer)
21 throws IOException, JsonProcessingException {
22 jGen.writeStartObject();
23 Timestamp ts = new Timestamp(ctb.getStartTimeNs()/1000000);
24 jGen.writeStringField("start-time", ts.toString());
25 jGen.writeStringField("current-time",
26 new Timestamp(System.currentTimeMillis()).toString());
27 jGen.writeNumberField("total-packets", ctb.getTotalPktCnt());
28 jGen.writeNumberField("average", ctb.getAverageProcTimeNs());
29 jGen.writeNumberField("min", ctb.getMinTotalProcTimeNs());
30 jGen.writeNumberField("max", ctb.getMaxTotalProcTimeNs());
31 jGen.writeNumberField("std-dev", ctb.getTotalSigmaProcTimeNs());
32 jGen.writeArrayFieldStart("modules");
33 for (OneComponentTime oct : ctb.getModules()) {
34 serializer.defaultSerializeValue(oct, jGen);
35 }
36 jGen.writeEndArray();
37 jGen.writeEndObject();
38 }
39
40 /**
41 * Tells SimpleModule that we are the serializer for OFMatch
42 */
43 @Override
44 public Class<CumulativeTimeBucket> handledType() {
45 return CumulativeTimeBucket.class;
46 }
47}