Skip to content

Commit

Permalink
Fix to reduce newfstatat to "/etc/localtime" calls
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Aug 3, 2024
1 parent 7293ee5 commit fd51ab9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 1 addition & 4 deletions stats-lib-funcs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -62,7 +62,6 @@ sub jsonify

sub get_stats_empty
{
my $time = time();
return {
graphs =>
{ cpu => [{x => $time, y => 0}],
Expand All @@ -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});
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 15 additions & 1 deletion stats.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fd51ab9

Please sign in to comment.