blob: 7c35918a58dab81f7a4a5422c6a084138adc3e89 [file] [log] [blame]
Brian O'Connora468e902015-03-18 16:43:49 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Brian O'Connora468e902015-03-18 16:43:49 -07003 *
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 IntentPerfListCommand 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 print("%12s: %14s", "Node ID", "Overall Rate");
53 for (int i = 0; i < overall.data.length; i++) {
54 if (overall.data[i] >= 0) {
55 print("%12s: %14.2f", headers.get(i), overall.data[i]);
56 total += overall.data[i];
57 } else {
58 print("%12s: %14s", headers.get(i), " ");
59 }
60 }
61 print("%12s: %14.2f", "total", total);
62 }
63
64 private void printSamples() {
65 IntentPerfCollector collector = get(IntentPerfCollector.class);
66 List<String> headers = collector.getSampleHeaders();
67 List<Sample> samples = collector.getSamples();
68
69 System.out.print(String.format("%10s ", "Time"));
70 for (String header : headers) {
71 System.out.print(String.format("%12s ", header));
72 }
73 System.out.println(String.format("%12s", "Total"));
74
75 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
76 for (Sample sample : samples) {
77 double total = 0;
78 System.out.print(String.format("%10s ", sdf.format(new Date(sample.time))));
79 for (int i = 0; i < sample.data.length; i++) {
80 if (sample.data[i] >= 0) {
81 System.out.print(String.format("%12.2f ", sample.data[i]));
82 total += sample.data[i];
83 } else {
84 System.out.print(String.format("%12s ", " "));
85 }
86 }
87 System.out.println(String.format("%12.2f", total));
88 }
89 }
90
91}