1 //
2 // Copyright (C) 2020 The Android Open Source Project
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
17 //! Command to control profcollectd behaviour.
18
19 use anyhow::{bail, Context, Result};
20 use std::env;
21
22 const HELP_MSG: &str = r#"
23 usage: profcollectctl [command]
24
25 Command to control profcollectd behaviour.
26
27 command:
28 trace Request an one-off system-wide trace.
29 process Convert traces to perf profiles.
30 report Create a report containing all profiles.
31 reset Clear all local data.
32 help Print this message.
33 "#;
34
main() -> Result<()>35 fn main() -> Result<()> {
36 libprofcollectd::init_logging();
37
38 let args: Vec<String> = env::args().collect();
39 if args.len() != 2 {
40 bail!("This program only takes one argument{}", &HELP_MSG);
41 }
42
43 let action = &args[1];
44 match action.as_str() {
45 "trace" => {
46 println!("Performing system-wide trace");
47 libprofcollectd::trace_system("manual").context("Failed to trace.")?;
48 }
49 "process" => {
50 println!("Processing traces");
51 libprofcollectd::process().context("Failed to process traces.")?;
52 }
53 "report" => {
54 println!("Creating profile report");
55 let path = libprofcollectd::report().context("Failed to create profile report.")?;
56 println!("Report created at: {}", &path);
57 }
58 "reset" => {
59 libprofcollectd::reset().context("Failed to reset.")?;
60 println!("Reset done.");
61 }
62 "help" => println!("{}", &HELP_MSG),
63 arg => bail!("Unknown argument: {}\n{}", &arg, &HELP_MSG),
64 }
65 Ok(())
66 }
67