Commit 4558525c authored by Gaël Berthaud-Müller's avatar Gaël Berthaud-Müller Committed by Alexandre
Browse files

test more optimizations

parent c1a23576
......@@ -88,63 +88,77 @@ sub run {
# used for progress indicator
my ( $previous_module, $previous_method ) = ( '', '' );
#my $callback_duration = 0;
my @entries;
# Callback defined here so it closes over the setup above.
Zonemaster::Engine->logger->callback(
sub {
my ( $entry ) = @_;
# TODO: Make minimum level configurable
# if ( $entry->numeric_level >= $numeric{INFO} ) {
# $log->debug("Adding result entry in database: " . $entry->string);
# $self->{_db}->add_result_entry( $test_id, {
# timestamp => $entry->timestamp,
# module => $entry->module,
# testcase => $entry->testcase,
# tag => $entry->tag,
# level => $entry->level,
# args => $entry->args // {},
# });
# }
foreach my $trace ( reverse @{ $entry->trace } ) {
foreach my $module_method ( keys %{ $counter_for_progress_indicator{planned} } ) {
if ( index( $trace->[1], $module_method ) > -1 ) {
my $percent_progress = 0;
my ( $module ) = ( $module_method =~ /(.+::)[^:]+/ );
if ( $previous_module eq $module ) {
$counter_for_progress_indicator{executed}{$module_method}++;
}
elsif ( $previous_module ) {
foreach my $planned_module_method ( keys %{ $counter_for_progress_indicator{planned} } ) {
$counter_for_progress_indicator{executed}{$planned_module_method}++
if ( $counter_for_progress_indicator{planned}{$planned_module_method} eq
$previous_module );
}
}
$previous_module = $module;
if ( $previous_method ne $module_method ) {
$percent_progress = sprintf(
"%.0f",
99 * (
scalar( keys %{ $counter_for_progress_indicator{executed} } ) /
scalar( keys %{ $counter_for_progress_indicator{planned} } )
)
);
$self->{_db}->test_progress( $test_id, $percent_progress );
$previous_method = $module_method;
}
}
}
}
$counter{ uc $entry->level } += 1;
}
);
# Zonemaster::Engine->logger->callback(
# sub {
# my $start_time_1 = [ gettimeofday ];
# my ( $entry ) = @_;
# if ( $entry->numeric_level >= $numeric{INFO} ) {
# push @entries, $entry;
# }
# $callback_duration += tv_interval($start_time_1);
# }
# );
# Zonemaster::Engine->logger->callback(
# sub {
# my ( $entry ) = @_;
# # TODO: Make minimum level configurable
# # if ( $entry->numeric_level >= $numeric{INFO} ) {
# # $log->debug("Adding result entry in database: " . $entry->string);
# # $self->{_db}->add_result_entry( $test_id, {
# # timestamp => $entry->timestamp,
# # module => $entry->module,
# # testcase => $entry->testcase,
# # tag => $entry->tag,
# # level => $entry->level,
# # args => $entry->args // {},
# # });
# # }
# my $start_time_1 = [ gettimeofday ];
# foreach my $trace ( reverse @{ $entry->trace } ) {
# foreach my $module_method ( keys %{ $counter_for_progress_indicator{planned} } ) {
# if ( index( $trace->[1], $module_method ) > -1 ) {
# my $percent_progress = 0;
# my ( $module ) = ( $module_method =~ /(.+::)[^:]+/ );
# if ( $previous_module eq $module ) {
# $counter_for_progress_indicator{executed}{$module_method}++;
# }
# elsif ( $previous_module ) {
# foreach my $planned_module_method ( keys %{ $counter_for_progress_indicator{planned} } ) {
# $counter_for_progress_indicator{executed}{$planned_module_method}++
# if ( $counter_for_progress_indicator{planned}{$planned_module_method} eq
# $previous_module );
# }
# }
# $previous_module = $module;
# if ( $previous_method ne $module_method ) {
# $percent_progress = sprintf(
# "%.0f",
# 99 * (
# scalar( keys %{ $counter_for_progress_indicator{executed} } ) /
# scalar( keys %{ $counter_for_progress_indicator{planned} } )
# )
# );
# $self->{_db}->test_progress( $test_id, $percent_progress );
# $previous_method = $module_method;
# }
# }
# }
# }
# $counter{ uc $entry->level } += 1;
# $callback_duration += tv_interval($start_time_1);
# }
# );
if ( $params->{nameservers} && @{ $params->{nameservers} } > 0 ) {
$self->add_fake_delegation( $domain, $params->{nameservers} );
......@@ -188,12 +202,22 @@ sub run {
}
}
$progress = $self->{_db}->test_progress( $test_id, 100 );
#Zonemaster::Backend::Metrics::timing("zonemaster.testagent.log_callback_duration", $callback_duration * 1000);
my $start_time_2 = [ gettimeofday ];
my @entries = grep { $_->numeric_level >= $numeric{INFO} } @{ Zonemaster::Engine->logger->entries };
Zonemaster::Backend::Metrics::timing("zonemaster.testagent.log_callback_add_result_entry_grep_duration", tv_interval($start_time_2) * 1000);
$self->{_db}->add_result_entries( $test_id, \@entries);
my $callback_add_result_entry_duration = tv_interval($start_time_2);
Zonemaster::Backend::Metrics::timing("zonemaster.testagent.log_callback_add_result_entry_duration", $callback_add_result_entry_duration * 1000);
#$log->debug("Callback timing for $test_id: $callback_duration / $callback_add_result_entry_duration ");
$progress = $self->{_db}->test_progress( $test_id, 100 );
return;
} ## end sub run
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment