Skip to content

Commit

Permalink
[Agent] remove redundant clone operation
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoziv authored and TomatoMr committed Sep 25, 2023
1 parent bc622aa commit b331b16
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion agent/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl RefCountable for SysStatusBroker {
CounterValue::Unsigned(self.config.load().sys_free_memory_limit as u64),
));

match get_file_and_size_sum(self.log_dir.clone()) {
match get_file_and_size_sum(&self.log_dir) {
Ok(file_and_size_sum) => {
metrics.push((
"log_file_size_sum",
Expand Down
13 changes: 5 additions & 8 deletions agent/src/trident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ pub struct DomainNameListener {
}

impl DomainNameListener {
const INTERVAL: u64 = 5;
const INTERVAL: Duration = Duration::from_secs(5);

fn new(
stats_collector: Arc<stats::Collector>,
Expand All @@ -979,14 +979,11 @@ impl DomainNameListener {
agent_id_tx: Arc<broadcast::Sender<AgentId>>,
) -> DomainNameListener {
Self {
stats_collector: stats_collector.clone(),
stats_collector,
session,

domain_names: domain_names.clone(),
ips: ips.clone(),

domain_names,
ips,
sidecar_mode,

thread_handler: None,
stopped: Arc::new(AtomicBool::new(false)),
agent_id_tx,
Expand Down Expand Up @@ -1035,7 +1032,7 @@ impl DomainNameListener {
.name("domain-name-listener".to_owned())
.spawn(move || {
while !stopped.swap(false, Ordering::Relaxed) {
thread::sleep(Duration::from_secs(Self::INTERVAL));
thread::sleep(Self::INTERVAL);

let mut changed = false;
for i in 0..domain_names.len() {
Expand Down
4 changes: 2 additions & 2 deletions agent/src/utils/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ impl Guard {
let config = config.load();
let tap_mode = config.tap_mode;
let cpu_limit = config.max_cpus;
match get_file_and_size_sum(log_dir.clone()) {
match get_file_and_size_sum(&log_dir) {
Ok(file_and_size_sum) => {
let log_file_size = config.log_file_size; // Log file size limit (unit: M)
let file_sizes_sum = file_and_size_sum.file_sizes_sum.clone(); // Total size of current log files (unit: B)
let file_sizes_sum = file_and_size_sum.file_sizes_sum; // Total size of current log files (unit: B)
debug!(
"current log files' size: {}B, log_file_size_limit: {}B",
file_sizes_sum,
Expand Down
4 changes: 2 additions & 2 deletions agent/src/utils/process/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ impl Ord for FileInfo {
}

/// 获取指定路径下的所有文件的信息及文件大小总和(单位:B)
pub fn get_file_and_size_sum(dir: String) -> io::Result<FileAndSizeSum> {
pub fn get_file_and_size_sum(dir: &String) -> io::Result<FileAndSizeSum> {
let mut file_and_size_sum = FileAndSizeSum::new();
let mut file_infos = Vec::new();
let dir = Path::new(dir.as_str());
let dir = Path::new(dir);
for item in fs::read_dir(dir)? {
let file = match item {
Ok(f) => f,
Expand Down

0 comments on commit b331b16

Please sign in to comment.