blob: 928a8f8c0e4306d45af0fe8f138d495875c93d4a [file] [log] [blame]
Thomas Vachuska7648d662015-03-16 11:58:30 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.intentperf;
17
18import org.apache.karaf.shell.commands.Command;
19import org.apache.karaf.shell.commands.Option;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.intentperf.IntentPerfCollector.Sample;
22
23import java.text.SimpleDateFormat;
24import java.util.Date;
25import java.util.List;
26
27/**
28 * Displays accumulated performance metrics.
29 */
30@Command(scope = "onos", name = "intent-perf",
31 description = "Displays accumulated performance metrics")
32public class IntentPerfCommand extends AbstractShellCommand {
33
34 @Option(name = "-s", aliases = "--summary", description = "Output just summary",
35 required = false, multiValued = false)
36 private boolean summary = false;
37
38 @Override
39 protected void execute() {
40 if (summary) {
41 printSummary();
42 } else {
43 printSamples();
44 }
45 }
46
47 private void printSummary() {
48 IntentPerfCollector collector = get(IntentPerfCollector.class);
49 List<String> headers = collector.getSampleHeaders();
50 Sample overall = collector.getOverall();
51 double total = 0;
52 for (int i = 0; i < overall.data.length; i++) {
53 print("%12s: %12.2f", headers.get(i), overall.data[i]);
54 total += overall.data[i];
55 }
56 print("%12s: %12.2f", "total", total);
57 }
58
59 private void printSamples() {
60 IntentPerfCollector collector = get(IntentPerfCollector.class);
61 List<String> headers = collector.getSampleHeaders();
62 List<Sample> samples = collector.getSamples();
63
64 System.out.print(String.format("%10s ", "Time"));
65 for (String header : headers) {
66 System.out.print(String.format("%12s ", header));
67 }
68 System.out.println(String.format("%12s", "Total"));
69
70 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
71 for (Sample sample : samples) {
72 double total = 0;
73 System.out.print(String.format("%10s ", sdf.format(new Date(sample.time))));
74 for (int i = 0; i < sample.data.length; i++) {
75 if (sample.data[i] >= 0) {
76 System.out.print(String.format("%12.2f ", sample.data[i]));
77 total += sample.data[i];
78 } else {
79 System.out.print(String.format("%12s ", " "));
80 }
81 }
82 System.out.println(String.format("%12.2f", total));
83 }
84 }
85
86}