blob: 0c2e87d91a798c9365a2574e18a284a0eba38cf3 [file] [log] [blame]
Yi Konge5576ae2020-08-05 02:00:05 +08001//
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
Yi Konge3aab142021-03-02 13:58:25 +080019use anyhow::{bail, Result};
Yi Konge5576ae2020-08-05 02:00:05 +080020use std::env;
21
Yi Konge3aab142021-03-02 13:58:25 +080022const HELP_MSG: &str = r#"
23profcollectd background daemon.
Yi Konge5576ae2020-08-05 02:00:05 +080024usage: profcollectd [command]
Yi Konge3aab142021-03-02 13:58:25 +080025 nostart Start daemon but do not schedule profile collection.
26"#;
Yi Konge5576ae2020-08-05 02:00:05 +080027
Yi Konge3aab142021-03-02 13:58:25 +080028fn main() -> Result<()> {
29 libprofcollectd::init_logging();
30
Yi Konge5576ae2020-08-05 02:00:05 +080031 let args: Vec<String> = env::args().collect();
Yi Konge3aab142021-03-02 13:58:25 +080032 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)?;
Yi Konge5576ae2020-08-05 02:00:05 +080037 }
38
39 let action = &args[1];
40 match action.as_str() {
Yi Konge3aab142021-03-02 13:58:25 +080041 "nostart" => libprofcollectd::init_service(false)?,
42 "help" => println!("{}", &HELP_MSG),
43 arg => bail!("Unknown argument: {}\n{}", &arg, &HELP_MSG),
Yi Konge5576ae2020-08-05 02:00:05 +080044 }
Yi Konge3aab142021-03-02 13:58:25 +080045 Ok(())
Yi Konge5576ae2020-08-05 02:00:05 +080046}