From fd51ab996b9fb9bebb6b15e971362e3bb3ea8248 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sat, 3 Aug 2024 14:55:28 +0300 Subject: [PATCH] Fix to reduce newfstatat to "/etc/localtime" calls --- stats-lib-funcs.pl | 5 +---- stats.pl | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/stats-lib-funcs.pl b/stats-lib-funcs.pl index 971a872ac..ac7e95508 100644 --- a/stats-lib-funcs.pl +++ b/stats-lib-funcs.pl @@ -15,7 +15,7 @@ } # Import global variables -our ($config_directory, $var_directory, $current_theme); +our ($config_directory, $var_directory, $current_theme, $time); # Load theme language and settings our %text = load_language($current_theme); @@ -62,7 +62,6 @@ sub jsonify sub get_stats_empty { - my $time = time(); return { graphs => { cpu => [{x => $time, y => 0}], @@ -80,7 +79,6 @@ sub get_stats_now my %data; my $graphs = {}; my $gadd = sub { - my $time = time(); my ($k, $d) = @_; $graphs->{$k} = [] if (ref($graphs->{$k}) ne 'ARRAY'); push(@{$graphs->{$k}}, {x => $time, y => $d}); @@ -226,7 +224,6 @@ sub get_stats_history sub trim_stats_history { my ($graphs) = @_; - my $time = time(); my $get_default_graph = sub { my ($key, $time) = @_; my $default = get_stats_empty(); diff --git a/stats.pl b/stats.pl index a959f5c89..d820b0e49 100755 --- a/stats.pl +++ b/stats.pl @@ -11,7 +11,7 @@ use Net::WebSocket::Server; use utf8; -our ($current_theme, $json); +our ($current_theme, $json, $time); require($ENV{'THEME_ROOT'} . "/stats-lib.pl"); # Get port number @@ -38,12 +38,17 @@ # Current stats within a period my $stats_period; +# Register start time and update it on each tick +$time = time(); + # Start WebSocket server Net::WebSocket::Server->new( listen => $port, tick_period => 1, on_tick => sub { my ($serv) = @_; + # Update time + $time += 1; # If asked to stop running, then shut down the server if ($serv->{'disable'}) { $serv->shutdown(); @@ -110,6 +115,15 @@ if ($serv->{'ticked'}++ % 20 == 0) { save_stats_history($stats_period); undef($stats_period); + undef(%main::read_file_cache); + undef(%main::read_file_missing); + undef(%main::acl_hash_cache); + undef(%main::acl_array_cache); + undef(%main::has_command_cache); + undef(@main::list_languages_cache); + undef($main::got_list_usermods_cache); + undef(@main::list_usermods_cache); + undef(%main::foreign_installed_cache); } # If interval is set then sleep minus one # second becase tick_period is one second