mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-20 01:16:14 +00:00
Several corrections as per Daniel and Baron's feedback.
Still TODO: Attributes still have a single method that doubles as a getter and setter. The constructor for Diskstats is still weird -- A tad more stricter than it should be, if anything. ->print_rest is still rest, even though that's hardly memorable, mostly because of a lack of ideas on what to rename it. The main loop in the Menu is still a while (1). As a nice perk, it's nearly twice as fast now! It also adds a _very_ experimental --memory-for-speed argument, which turns on memoization for the current biggest bottleneck.
This commit is contained in:
@@ -48,50 +48,57 @@ sub group_by {
|
||||
# last sample.
|
||||
sub group_by_sample {
|
||||
my ( $self, %args ) = @_;
|
||||
my ( $header_cb, $rest_cb ) = $args{qw( header_cb rest_cb )};
|
||||
my ( $header_callback, $rest_callback ) = $args{qw( header_callback rest_callback )};
|
||||
|
||||
if (!$self->interactive) {
|
||||
$self->clear_state;
|
||||
}
|
||||
$self->clear_state() unless $self->interactive();
|
||||
|
||||
$self->parse_from(
|
||||
# ->can comes from UNIVERSAL. Returns a coderef to the method, if found.
|
||||
# undef otherwise.
|
||||
# Basically \&func, but always in runtime, and allows overriding
|
||||
# the method in child classes.
|
||||
sample_callback => $self->can("_sample_callback"),
|
||||
map( { ( $_ => $args{$_} ) } qw(filehandle filename data) ),
|
||||
filehandle => $args{filehandle},
|
||||
filename => $args{filename},
|
||||
data => $args{data},
|
||||
);
|
||||
|
||||
if (!$self->interactive) {
|
||||
$self->clear_state;
|
||||
}
|
||||
$self->clear_state() unless $self->interactive();
|
||||
return;
|
||||
}
|
||||
|
||||
sub _sample_callback {
|
||||
my ( $self, $ts, %args ) = @_;
|
||||
my $printed_a_line = 0;
|
||||
|
||||
if ( $self->has_stats ) {
|
||||
if ( $self->has_stats() ) {
|
||||
$self->{_iterations}++;
|
||||
}
|
||||
|
||||
my $elapsed =
|
||||
( $self->current_ts() || 0 ) -
|
||||
( $self->previous_ts() || 0 );
|
||||
my $elapsed = ($self->curr_ts() || 0)
|
||||
- ($self->prev_ts() || 0);
|
||||
|
||||
if ( $ts > 0 && $elapsed >= $self->sample_time() ) {
|
||||
|
||||
$self->print_deltas(
|
||||
max_device_length => 6,
|
||||
header_cb => sub {
|
||||
# When grouping by samples, we don't usually show the device names,
|
||||
# only a count of how many devices each sample has, which causes the
|
||||
# columns' width change depending on simple invisible. That's uncalled
|
||||
# for, so we hardcode the width here
|
||||
# (6 is what the shell version used).
|
||||
max_device_length => 6,
|
||||
header_callback => sub {
|
||||
my ( $self, $header, @args ) = @_;
|
||||
|
||||
if ( $self->{_print_header} ) {
|
||||
my $method = $args{header_cb} || "print_header";
|
||||
my $method = $args{header_callback} || "print_header";
|
||||
$self->$method( $header, @args );
|
||||
$self->{_print_header} = undef;
|
||||
}
|
||||
},
|
||||
rest_cb => sub {
|
||||
rest_callback => sub {
|
||||
my ( $self, $format, $cols, $stat ) = @_;
|
||||
my $method = $args{rest_cb} || "print_rest";
|
||||
my $method = $args{rest_callback} || "print_rest";
|
||||
$self->$method( $format, $cols, $stat );
|
||||
$printed_a_line = 1;
|
||||
}
|
||||
@@ -99,23 +106,24 @@ sub _sample_callback {
|
||||
}
|
||||
if ( $self->{_iterations} == 1 || $printed_a_line == 1 ) {
|
||||
$self->{_save_curr_as_prev} = 1;
|
||||
$self->_save_current_as_previous( $self->stats_for() );
|
||||
$self->_save_curr_as_prev( $self->stats_for() );
|
||||
$self->{_save_curr_as_prev} = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub delta_against {
|
||||
my ( $self, $dev ) = @_;
|
||||
return $self->previous_stats_for($dev);
|
||||
return $self->prev_stats_for($dev);
|
||||
}
|
||||
|
||||
sub delta_against_ts {
|
||||
my ( $self ) = @_;
|
||||
return $self->previous_ts();
|
||||
return $self->prev_ts();
|
||||
}
|
||||
|
||||
sub clear_state {
|
||||
my ( $self, @args ) = @_;
|
||||
my ( $self, @args ) = @_;
|
||||
$self->{_iterations} = 0;
|
||||
$self->{_save_curr_as_prev} = 0;
|
||||
$self->{_print_header} = 1;
|
||||
@@ -124,17 +132,20 @@ sub clear_state {
|
||||
|
||||
sub compute_devs_in_group {
|
||||
my ($self) = @_;
|
||||
my $stats = $self->stats_for();
|
||||
my $re = $self->device_regex();
|
||||
return scalar grep {
|
||||
# Got stats for that device, and we want to print it
|
||||
$self->stats_for($_) && $self->dev_ok($_)
|
||||
} $self->sorted_devs;
|
||||
# Got stats for that device, and it matches the devices re
|
||||
$stats->{$_} && $_ =~ $re
|
||||
} $self->ordered_devs;
|
||||
}
|
||||
|
||||
sub compute_dev {
|
||||
my ( $self, $dev ) = @_;
|
||||
return $self->compute_devs_in_group() > 1
|
||||
? "{" . $self->compute_devs_in_group() . "}"
|
||||
: ( $self->sorted_devs )[0];
|
||||
my ( $self, $devs ) = @_;
|
||||
$devs ||= $self->compute_devs_in_group();
|
||||
return $devs > 1
|
||||
? "{" . $devs . "}"
|
||||
: ( $self->ordered_devs )[0];
|
||||
}
|
||||
|
||||
# Terrible breach of encapsulation, but it'll have to do for the moment.
|
||||
@@ -143,7 +154,7 @@ sub _calc_stats_for_deltas {
|
||||
|
||||
my $delta_for;
|
||||
|
||||
for my $dev ( grep { $self->dev_ok($_) } $self->sorted_devs ) {
|
||||
foreach my $dev ( grep { $self->dev_ok($_) } $self->ordered_devs ) {
|
||||
my $curr = $self->stats_for($dev);
|
||||
my $against = $self->delta_against($dev);
|
||||
|
||||
@@ -154,24 +165,35 @@ sub _calc_stats_for_deltas {
|
||||
}
|
||||
}
|
||||
|
||||
my $in_progress = $delta_for->{ios_in_progress}; #$curr->{"ios_in_progress"};
|
||||
my $tot_in_progress = 0; #$against->{"sum_ios_in_progress"} || 0;
|
||||
|
||||
my $devs_in_group = $self->compute_devs_in_group() || 1;
|
||||
my $in_progress = $delta_for->{ios_in_progress};
|
||||
my $tot_in_progress = 0;
|
||||
my $devs_in_group = $self->compute_devs_in_group() || 1;
|
||||
|
||||
my %stats = (
|
||||
$self->_calc_read_stats( $delta_for, $elapsed, $devs_in_group ),
|
||||
$self->_calc_write_stats( $delta_for, $elapsed, $devs_in_group ),
|
||||
$self->_calc_read_stats(
|
||||
delta_for => $delta_for,
|
||||
elapsed => $elapsed,
|
||||
devs_in_group => $devs_in_group,
|
||||
),
|
||||
$self->_calc_write_stats(
|
||||
delta_for => $delta_for,
|
||||
elapsed => $elapsed,
|
||||
devs_in_group => $devs_in_group,
|
||||
),
|
||||
in_progress =>
|
||||
$self->compute_in_progress( $in_progress, $tot_in_progress ),
|
||||
$self->compute_in_progress( $in_progress, $tot_in_progress ),
|
||||
);
|
||||
|
||||
my %extras = $self->_calc_misc_stats( $delta_for, $elapsed, $devs_in_group, \%stats );
|
||||
while ( my ($k, $v) = each %extras ) {
|
||||
$stats{$k} = $v;
|
||||
}
|
||||
my %extras = $self->_calc_misc_stats(
|
||||
delta_for => $delta_for,
|
||||
elapsed => $elapsed,
|
||||
devs_in_group => $devs_in_group,
|
||||
stats => \%stats,
|
||||
);
|
||||
|
||||
$stats{dev} = $self->compute_dev( \%stats );
|
||||
@stats{ keys %extras } = values %extras;
|
||||
|
||||
$stats{dev} = $self->compute_dev( $devs_in_group );
|
||||
|
||||
return \%stats;
|
||||
}
|
||||
|
Reference in New Issue
Block a user