atagen

matrix-rust-sdk

public
Star0
Watch0
ssh://brewery@pls.lobotomise.me:33/atagen/matrix-rust-sdk.git
xtask/src/log/mod.rsRust75 lines1.9 KB
1
mod overview;
2
mod sync;
3
mod timer;
4
5
use std::path::PathBuf;
6
7
use clap::{Args, Subcommand};
8
9
use crate::{Result, sh, workspace};
10
11
#[derive(Args)]
12
pub struct LogArgs {
13
    #[clap(subcommand)]
14
    cmd: LogCommand,
15
}
16
17
/// Analysis around logs (formatted by `matrix-sdk-ffi`).
18
#[derive(Subcommand)]
19
enum LogCommand {
20
    /// Overview the logs as a tree where each node is a target and each leaf is
21
    /// a log location with occurrences, spans and fields.
22
    Overview {
23
        /// The file containing the logs to analyse.
24
        #[clap(long)]
25
        log_file: PathBuf,
26
27
        /// The output file that will receive the HTML report.
28
        #[clap(long)]
29
        html_output_file: PathBuf,
30
    },
31
32
    /// Visualise the sync requests and responses with a table and a duration
33
    /// graph.
34
    Sync {
35
        /// The file containing the logs to analyse.
36
        #[clap(long)]
37
        log_file: PathBuf,
38
39
        /// The output file that will receive the HTML report.
40
        #[clap(long)]
41
        html_output_file: PathBuf,
42
    },
43
44
    /// Visualise the timers to detect bottlenecks.
45
    Timer {
46
        /// The file containing the logs to analyse.
47
        #[clap(long)]
48
        log_file: PathBuf,
49
50
        /// The output file that will receive the HTML report.
51
        #[clap(long)]
52
        html_output_file: PathBuf,
53
    },
54
}
55
56
impl LogArgs {
57
    pub fn run(self) -> Result<()> {
58
        let sh = sh();
59
        let _p = sh.push_dir(workspace::root_path()?);
60
61
        match self.cmd {
62
            LogCommand::Overview { log_file, html_output_file } => {
63
                overview::run(log_file, html_output_file)?
64
            }
65
            LogCommand::Sync { log_file, html_output_file } => {
66
                sync::run(log_file, html_output_file)?
67
            }
68
            LogCommand::Timer { log_file, html_output_file } => {
69
                timer::run(log_file, html_output_file)?
70
            }
71
        }
72
73
        Ok(())
74
    }
75
}