Skip to main content

openstack_cli_core/
lib.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//! # OpenStack CLI core functionality
15
16use comfy_table::ContentArrangement;
17use comfy_table::Table;
18use comfy_table::presets::UTF8_FULL_CONDENSED;
19
20pub mod cli;
21pub mod common;
22pub mod config;
23pub mod error;
24pub mod output;
25pub mod tracing_stats;
26
27use crate::tracing_stats::HttpRequestStats;
28
29/// Build a table of HTTP request timings
30pub fn build_http_requests_timing_table(data: &HttpRequestStats) -> Table {
31    let mut table = Table::new();
32    table
33        .load_preset(UTF8_FULL_CONDENSED)
34        .set_content_arrangement(ContentArrangement::Dynamic)
35        .set_header(Vec::from(["Url", "Method", "Duration (ms)"]));
36
37    let mut total_http_duration: u128 = 0;
38    for rec in data.summarize_by_url_method() {
39        total_http_duration += rec.2;
40        table.add_row(vec![rec.0, rec.1, rec.2.to_string()]);
41    }
42    table.add_row(vec!["Total", "", &total_http_duration.to_string()]);
43    table
44}