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 is_ready(&self) -> bool35 fn is_ready(&self) -> bool { 36 true 37 } 38 trace_system( &self, trace_dir: &Path, tag: &str, sampling_period: &Duration, _binary_filter: &str, )39 fn trace_system( 40 &self, 41 trace_dir: &Path, 42 tag: &str, 43 sampling_period: &Duration, 44 _binary_filter: &str, 45 ) { 46 let trace_file = trace_provider::get_path(trace_dir, tag, LOGGING_TRACEFILE_EXTENSION); 47 48 log::info!( 49 "Trace event triggered, tag {}, sampling for {}ms, saving to {}", 50 tag, 51 sampling_period.as_millis(), 52 trace_file.display() 53 ); 54 } 55 trace_process( &self, trace_dir: &Path, tag: &str, sampling_period: &Duration, processes: &str, )56 fn trace_process( 57 &self, 58 trace_dir: &Path, 59 tag: &str, 60 sampling_period: &Duration, 61 processes: &str, 62 ) { 63 let trace_file = trace_provider::get_path(trace_dir, tag, LOGGING_TRACEFILE_EXTENSION); 64 65 log::info!( 66 "Trace event triggered, tag {}, processes {}, sampling for {}ms, saving to {}", 67 tag, 68 processes, 69 sampling_period.as_millis(), 70 trace_file.display() 71 ); 72 } 73 process(&self, _trace_dir: &Path, _profile_dir: &Path, _binary_filter: &str) -> Result<()>74 fn process(&self, _trace_dir: &Path, _profile_dir: &Path, _binary_filter: &str) -> Result<()> { 75 log::info!("Process event triggered"); 76 Ok(()) 77 } 78 set_log_file(&self, _filename: &Path)79 fn set_log_file(&self, _filename: &Path) {} reset_log_file(&self)80 fn reset_log_file(&self) {} 81 } 82 83 impl LoggingTraceProvider { supported() -> bool84 pub fn supported() -> bool { 85 true 86 } 87 } 88