xref: /aosp_15_r20/system/extras/profcollectd/libprofcollectd/trace_provider/logging.rs (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1*288bf522SAndroid Build Coastguard Worker //
2*288bf522SAndroid Build Coastguard Worker // Copyright (C) 2021 The Android Open Source Project
3*288bf522SAndroid Build Coastguard Worker //
4*288bf522SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
5*288bf522SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
6*288bf522SAndroid Build Coastguard Worker // You may obtain a copy of the License at
7*288bf522SAndroid Build Coastguard Worker //
8*288bf522SAndroid Build Coastguard Worker //      http://www.apache.org/licenses/LICENSE-2.0
9*288bf522SAndroid Build Coastguard Worker //
10*288bf522SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
11*288bf522SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
12*288bf522SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*288bf522SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
14*288bf522SAndroid Build Coastguard Worker // limitations under the License.
15*288bf522SAndroid Build Coastguard Worker //
16*288bf522SAndroid Build Coastguard Worker 
17*288bf522SAndroid Build Coastguard Worker //! Logging trace provider for development and testing purposes.
18*288bf522SAndroid Build Coastguard Worker 
19*288bf522SAndroid Build Coastguard Worker use anyhow::Result;
20*288bf522SAndroid Build Coastguard Worker use std::path::Path;
21*288bf522SAndroid Build Coastguard Worker use std::time::Duration;
22*288bf522SAndroid Build Coastguard Worker use trace_provider::TraceProvider;
23*288bf522SAndroid Build Coastguard Worker 
24*288bf522SAndroid Build Coastguard Worker use crate::trace_provider;
25*288bf522SAndroid Build Coastguard Worker 
26*288bf522SAndroid Build Coastguard Worker static LOGGING_TRACEFILE_EXTENSION: &str = "loggingtrace";
27*288bf522SAndroid Build Coastguard Worker 
28*288bf522SAndroid Build Coastguard Worker pub struct LoggingTraceProvider {}
29*288bf522SAndroid Build Coastguard Worker 
30*288bf522SAndroid Build Coastguard Worker impl TraceProvider for LoggingTraceProvider {
get_name(&self) -> &'static str31*288bf522SAndroid Build Coastguard Worker     fn get_name(&self) -> &'static str {
32*288bf522SAndroid Build Coastguard Worker         "logging"
33*288bf522SAndroid Build Coastguard Worker     }
34*288bf522SAndroid Build Coastguard Worker 
is_ready(&self) -> bool35*288bf522SAndroid Build Coastguard Worker     fn is_ready(&self) -> bool {
36*288bf522SAndroid Build Coastguard Worker         true
37*288bf522SAndroid Build Coastguard Worker     }
38*288bf522SAndroid Build Coastguard Worker 
trace_system( &self, trace_dir: &Path, tag: &str, sampling_period: &Duration, _binary_filter: &str, )39*288bf522SAndroid Build Coastguard Worker     fn trace_system(
40*288bf522SAndroid Build Coastguard Worker         &self,
41*288bf522SAndroid Build Coastguard Worker         trace_dir: &Path,
42*288bf522SAndroid Build Coastguard Worker         tag: &str,
43*288bf522SAndroid Build Coastguard Worker         sampling_period: &Duration,
44*288bf522SAndroid Build Coastguard Worker         _binary_filter: &str,
45*288bf522SAndroid Build Coastguard Worker     ) {
46*288bf522SAndroid Build Coastguard Worker         let trace_file = trace_provider::get_path(trace_dir, tag, LOGGING_TRACEFILE_EXTENSION);
47*288bf522SAndroid Build Coastguard Worker 
48*288bf522SAndroid Build Coastguard Worker         log::info!(
49*288bf522SAndroid Build Coastguard Worker             "Trace event triggered, tag {}, sampling for {}ms, saving to {}",
50*288bf522SAndroid Build Coastguard Worker             tag,
51*288bf522SAndroid Build Coastguard Worker             sampling_period.as_millis(),
52*288bf522SAndroid Build Coastguard Worker             trace_file.display()
53*288bf522SAndroid Build Coastguard Worker         );
54*288bf522SAndroid Build Coastguard Worker     }
55*288bf522SAndroid Build Coastguard Worker 
trace_process( &self, trace_dir: &Path, tag: &str, sampling_period: &Duration, processes: &str, )56*288bf522SAndroid Build Coastguard Worker     fn trace_process(
57*288bf522SAndroid Build Coastguard Worker         &self,
58*288bf522SAndroid Build Coastguard Worker         trace_dir: &Path,
59*288bf522SAndroid Build Coastguard Worker         tag: &str,
60*288bf522SAndroid Build Coastguard Worker         sampling_period: &Duration,
61*288bf522SAndroid Build Coastguard Worker         processes: &str,
62*288bf522SAndroid Build Coastguard Worker     ) {
63*288bf522SAndroid Build Coastguard Worker         let trace_file = trace_provider::get_path(trace_dir, tag, LOGGING_TRACEFILE_EXTENSION);
64*288bf522SAndroid Build Coastguard Worker 
65*288bf522SAndroid Build Coastguard Worker         log::info!(
66*288bf522SAndroid Build Coastguard Worker             "Trace event triggered, tag {}, processes {}, sampling for {}ms, saving to {}",
67*288bf522SAndroid Build Coastguard Worker             tag,
68*288bf522SAndroid Build Coastguard Worker             processes,
69*288bf522SAndroid Build Coastguard Worker             sampling_period.as_millis(),
70*288bf522SAndroid Build Coastguard Worker             trace_file.display()
71*288bf522SAndroid Build Coastguard Worker         );
72*288bf522SAndroid Build Coastguard Worker     }
73*288bf522SAndroid Build Coastguard Worker 
process(&self, _trace_dir: &Path, _profile_dir: &Path, _binary_filter: &str) -> Result<()>74*288bf522SAndroid Build Coastguard Worker     fn process(&self, _trace_dir: &Path, _profile_dir: &Path, _binary_filter: &str) -> Result<()> {
75*288bf522SAndroid Build Coastguard Worker         log::info!("Process event triggered");
76*288bf522SAndroid Build Coastguard Worker         Ok(())
77*288bf522SAndroid Build Coastguard Worker     }
78*288bf522SAndroid Build Coastguard Worker 
set_log_file(&self, _filename: &Path)79*288bf522SAndroid Build Coastguard Worker     fn set_log_file(&self, _filename: &Path) {}
reset_log_file(&self)80*288bf522SAndroid Build Coastguard Worker     fn reset_log_file(&self) {}
81*288bf522SAndroid Build Coastguard Worker }
82*288bf522SAndroid Build Coastguard Worker 
83*288bf522SAndroid Build Coastguard Worker impl LoggingTraceProvider {
supported() -> bool84*288bf522SAndroid Build Coastguard Worker     pub fn supported() -> bool {
85*288bf522SAndroid Build Coastguard Worker         true
86*288bf522SAndroid Build Coastguard Worker     }
87*288bf522SAndroid Build Coastguard Worker }
88