Don't warn about invalid lines, just debug them. Anchor TS pattern. Unset --sample-time unless --group-by sample.

This commit is contained in:
Daniel Nichter
2012-01-12 14:26:31 -07:00
parent 60e16254d3
commit 87d12c9802
3 changed files with 20 additions and 20 deletions

View File

@@ -1934,10 +1934,7 @@ sub parse_diskstats_line {
my ( $self, $line, $block_size ) = @_;
my @dev_stats = split ' ', $line;
if ( @dev_stats != 14 ) {
PTDEBUG && _d("Ignoring short diskstats line:", $line);
return;
}
return unless @dev_stats == 14;
my $read_bytes = $dev_stats[READ_SECTORS] * $block_size;
my $written_bytes = $dev_stats[WRITTEN_SECTORS] * $block_size;
@@ -2002,7 +1999,8 @@ sub _parse_and_load_diskstats {
$new_cur->{$dev} = $dev_stats;
$self->add_ordered_dev($dev);
}
elsif ( my ($new_ts) = $line =~ /TS\s+([0-9]+(?:\.[0-9]+)?)/ ) {
elsif ( my ($new_ts) = $line =~ /^TS\s+([0-9]+(?:\.[0-9]+)?)/ ) {
PTDEBUG && _d("Timestamp:", $line);
if ( $current_ts && %$new_cur ) {
$self->_handle_ts_line($current_ts, $new_cur, $sample_callback);
$new_cur = {};
@@ -2010,8 +2008,7 @@ sub _parse_and_load_diskstats {
$current_ts = $new_ts;
}
else {
chomp($line);
warn "Line $INPUT_LINE_NUMBER: [$line] isn't in the diskstats format";
PTDEBUG && _d("Ignoring unknown diskstats line:", $line);
}
}
@@ -2019,6 +2016,7 @@ sub _parse_and_load_diskstats {
$self->_handle_ts_line($current_ts, $new_cur, $sample_callback);
$new_cur = {};
}
return $INPUT_LINE_NUMBER;
}
@@ -3218,6 +3216,11 @@ sub main {
$o->get_specs();
$o->get_opts();
# --sample-time only applies to --group-by sample.
if ( $o->get('group-by') !~ m/sample/i ) {
$o->set('sample-time', undef);
}
if ( !$o->get('help') ) {
if ( !$o->get('columns') ) {
$o->save_error("A regex pattern for --devices must be specified");

View File

@@ -461,10 +461,7 @@ sub parse_diskstats_line {
# Since we assume that device names can't have spaces.
my @dev_stats = split ' ', $line;
if ( @dev_stats != 14 ) {
PTDEBUG && _d("Ignoring short diskstats line:", $line);
return;
}
return unless @dev_stats == 14;
my $read_bytes = $dev_stats[READ_SECTORS] * $block_size;
my $written_bytes = $dev_stats[WRITTEN_SECTORS] * $block_size;
@@ -567,7 +564,8 @@ sub _parse_and_load_diskstats {
$new_cur->{$dev} = $dev_stats;
$self->add_ordered_dev($dev);
}
elsif ( my ($new_ts) = $line =~ /TS\s+([0-9]+(?:\.[0-9]+)?)/ ) {
elsif ( my ($new_ts) = $line =~ /^TS\s+([0-9]+(?:\.[0-9]+)?)/ ) {
PTDEBUG && _d("Timestamp:", $line);
if ( $current_ts && %$new_cur ) {
$self->_handle_ts_line($current_ts, $new_cur, $sample_callback);
$new_cur = {};
@@ -575,8 +573,7 @@ sub _parse_and_load_diskstats {
$current_ts = $new_ts;
}
else {
chomp($line);
warn "Line $INPUT_LINE_NUMBER: [$line] isn't in the diskstats format";
PTDEBUG && _d("Ignoring unknown diskstats line:", $line);
}
}
@@ -584,7 +581,7 @@ sub _parse_and_load_diskstats {
$self->_handle_ts_line($current_ts, $new_cur, $sample_callback);
$new_cur = {};
}
# Seems like this could be useful.
return $INPUT_LINE_NUMBER;
}

View File

@@ -215,7 +215,7 @@ $obj->set_column_regex(qr/./);
is(
$header,
q{%5s %-10s busy},
""
"Header"
);
($header, $rows, $cols) = $obj->design_print_formats(
@@ -226,7 +226,7 @@ is(
is(
$header,
$all_columns_format,
""
"All columns format"
);
throws_ok( sub { $obj->design_print_formats( columns => {} ) },
@@ -335,10 +335,10 @@ my $output = output(
stderr => 1,
);
like(
is(
$output,
qr/isn't in the diskstats format/,
"->parse_from and friends fail on malformed data"
"",
"Doesn't die parsing unknown line"
);
# ############################################################################