Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Zonemaster
zonemaster-backend
Commits
4558525c
Commit
4558525c
authored
Sep 20, 2021
by
Gaël Berthaud-Müller
Committed by
Alexandre
Dec 21, 2021
Browse files
test more optimizations
parent
c1a23576
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/Zonemaster/Backend/TestAgent.pm
View file @
4558525c
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment