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 //! Daemon program to collect system traces.
18
19 use anyhow::{bail, Result};
20 use std::env;
21
22 const HELP_MSG: &str = r#"
23 profcollectd background daemon.
24 usage: profcollectd [command]
25 nostart Start daemon but do not schedule profile collection.
26 "#;
27
main() -> Result<()>28 fn main() -> Result<()> {
29 libprofcollectd::init_logging();
30
31 let args: Vec<String> = env::args().collect();
32 if args.len() > 2 {
33 bail!("This program only takes one or no argument{}", &HELP_MSG);
34 }
35 if args.len() == 1 {
36 libprofcollectd::init_service(true)?;
37 }
38
39 let action = &args[1];
40 match action.as_str() {
41 "nostart" => libprofcollectd::init_service(false)?,
42 "help" => println!("{}", &HELP_MSG),
43 arg => bail!("Unknown argument: {}\n{}", &arg, &HELP_MSG),
44 }
45 Ok(())
46 }
47