Brian O'Connor | a468e90 | 2015-03-18 16:43:49 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Brian O'Connor | a468e90 | 2015-03-18 16:43:49 -0700 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.intentperf; |
| 17 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Command; |
| 19 | import org.apache.karaf.shell.api.action.Option; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Brian O'Connor | a468e90 | 2015-03-18 16:43:49 -0700 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.intentperf.IntentPerfCollector.Sample; |
| 23 | |
| 24 | import java.text.SimpleDateFormat; |
| 25 | import java.util.Date; |
| 26 | import java.util.List; |
| 27 | |
| 28 | /** |
| 29 | * Displays accumulated performance metrics. |
| 30 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 31 | @Service |
Brian O'Connor | a468e90 | 2015-03-18 16:43:49 -0700 | [diff] [blame] | 32 | @Command(scope = "onos", name = "intent-perf", |
| 33 | description = "Displays accumulated performance metrics") |
| 34 | public class IntentPerfListCommand extends AbstractShellCommand { |
| 35 | |
| 36 | @Option(name = "-s", aliases = "--summary", description = "Output just summary", |
| 37 | required = false, multiValued = false) |
| 38 | private boolean summary = false; |
| 39 | |
| 40 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 41 | protected void doExecute() { |
Brian O'Connor | a468e90 | 2015-03-18 16:43:49 -0700 | [diff] [blame] | 42 | if (summary) { |
| 43 | printSummary(); |
| 44 | } else { |
| 45 | printSamples(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | private void printSummary() { |
| 50 | IntentPerfCollector collector = get(IntentPerfCollector.class); |
| 51 | List<String> headers = collector.getSampleHeaders(); |
| 52 | Sample overall = collector.getOverall(); |
| 53 | double total = 0; |
| 54 | print("%12s: %14s", "Node ID", "Overall Rate"); |
| 55 | for (int i = 0; i < overall.data.length; i++) { |
| 56 | if (overall.data[i] >= 0) { |
| 57 | print("%12s: %14.2f", headers.get(i), overall.data[i]); |
| 58 | total += overall.data[i]; |
| 59 | } else { |
| 60 | print("%12s: %14s", headers.get(i), " "); |
| 61 | } |
| 62 | } |
| 63 | print("%12s: %14.2f", "total", total); |
| 64 | } |
| 65 | |
| 66 | private void printSamples() { |
| 67 | IntentPerfCollector collector = get(IntentPerfCollector.class); |
| 68 | List<String> headers = collector.getSampleHeaders(); |
| 69 | List<Sample> samples = collector.getSamples(); |
| 70 | |
| 71 | System.out.print(String.format("%10s ", "Time")); |
| 72 | for (String header : headers) { |
| 73 | System.out.print(String.format("%12s ", header)); |
| 74 | } |
| 75 | System.out.println(String.format("%12s", "Total")); |
| 76 | |
| 77 | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); |
| 78 | for (Sample sample : samples) { |
| 79 | double total = 0; |
| 80 | System.out.print(String.format("%10s ", sdf.format(new Date(sample.time)))); |
| 81 | for (int i = 0; i < sample.data.length; i++) { |
| 82 | if (sample.data[i] >= 0) { |
| 83 | System.out.print(String.format("%12.2f ", sample.data[i])); |
| 84 | total += sample.data[i]; |
| 85 | } else { |
| 86 | System.out.print(String.format("%12s ", " ")); |
| 87 | } |
| 88 | } |
| 89 | System.out.println(String.format("%12.2f", total)); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | } |