1 //
2 // Copyright (C) 2021 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 //! Logging trace provider for development and testing purposes.
18 
19 use anyhow::Result;
20 use std::path::Path;
21 use std::time::Duration;
22 use trace_provider::TraceProvider;
23 
24 use crate::trace_provider;
25 
26 static LOGGING_TRACEFILE_EXTENSION: &str = "loggingtrace";
27 
28 pub struct LoggingTraceProvider {}
29 
30 impl TraceProvider for LoggingTraceProvider {
get_name(&self) -> &'static str31     fn get_name(&self) -> &'static str {
32         "logging"
33     }
34 
trace(&self, trace_dir: &Path, tag: &str, sampling_period: &Duration)35     fn trace(&self, trace_dir: &Path, tag: &str, sampling_period: &Duration) {
36         let trace_file = trace_provider::get_path(trace_dir, tag, LOGGING_TRACEFILE_EXTENSION);
37 
38         log::info!(
39             "Trace event triggered, tag {}, sampling for {}ms, saving to {}",
40             tag,
41             sampling_period.as_millis(),
42             trace_file.display()
43         );
44     }
45 
process(&self, _trace_dir: &Path, _profile_dir: &Path) -> Result<()>46     fn process(&self, _trace_dir: &Path, _profile_dir: &Path) -> Result<()> {
47         log::info!("Process event triggered");
48         Ok(())
49     }
50 }
51 
52 impl LoggingTraceProvider {
supported() -> bool53     pub fn supported() -> bool {
54         true
55     }
56 }
57