Stephen Hemminger wrote:
>Turn on strict checking.
>Get rid of prototypes (prototypes are broken in Perl)
NAK, please check perldoc of sort().
The prototype there is needed by sort().
>Fix syntax of declaration.
Yeah, this is fine.
BTW, your $subject needs to be fixed too.
Turn on strict checking, and get rid of annoying use of prototype.
Fix syntax error in declaration
Use efficient sort algorithm by using schwartzian transform.
http://en.wikipedia.org/wiki/Schwartzian_transform
Signed-off-by: Stephen Hemminger <[email protected]>
--- a/scripts/checkstack.pl 2010-02-19 21:57:57.609178016 -0800
+++ b/scripts/checkstack.pl 2010-02-19 22:23:16.038241212 -0800
@@ -21,6 +21,8 @@
#
# TODO : Port to all architectures (one regex per arch)
+use strict;
+
# check for arch
#
# $re is used for two matches:
@@ -104,19 +106,11 @@ my (@stack, $re, $dre, $x, $xs);
}
}
-sub bysize($) {
- my ($asize, $bsize);
- ($asize = $a) =~ s/.*: *(.*)$/$1/;
- ($bsize = $b) =~ s/.*: *(.*)$/$1/;
- $bsize <=> $asize
-}
-
#
# main()
#
my $funcre = qr/^$x* <(.*)>:$/;
-my $func;
-my $file, $lastslash;
+my ($func, $file, $lastslash);
while (my $line = <STDIN>) {
if ($line =~ m/$funcre/) {
@@ -173,4 +167,7 @@ while (my $line = <STDIN>) {
}
}
-print sort bysize @stack;
+# Use Schwartzian transform to sort by last field (size)
+print map { $_->[0] }
+ sort { $b->[1] <=> $a->[1] }
+ map { [$_, /:\t*(\d+)$/] } @stack;
Stephen Hemminger wrote:
> Turn on strict checking, and get rid of annoying use of prototype.
> Fix syntax error in declaration
>
> Use efficient sort algorithm by using schwartzian transform.
> http://en.wikipedia.org/wiki/Schwartzian_transform
Yeah, the idea is good, this can also make it more perlish. ;)
But...
> -print sort bysize @stack;
> +# Use Schwartzian transform to sort by last field (size)
> +print map { $_->[0] }
> + sort { $b->[1] <=> $a->[1] }
> + map { [$_, /:\t*(\d+)$/] } @stack;
This regex here is not strictly the same as before.
Can we just keep the original regex? If not, what's wrong?
Thanks.
On Sat, 20 Feb 2010 15:35:06 +0800
Cong Wang <[email protected]> wrote:
> Stephen Hemminger wrote:
> > Turn on strict checking, and get rid of annoying use of prototype.
> > Fix syntax error in declaration
> >
> > Use efficient sort algorithm by using schwartzian transform.
> > http://en.wikipedia.org/wiki/Schwartzian_transform
>
>
> Yeah, the idea is good, this can also make it more perlish. ;)
>
> But...
>
>
> > -print sort bysize @stack;
> > +# Use Schwartzian transform to sort by last field (size)
> > +print map { $_->[0] }
> > + sort { $b->[1] <=> $a->[1] }
> > + map { [$_, /:\t*(\d+)$/] } @stack;
>
> This regex here is not strictly the same as before.
>
> Can we just keep the original regex? If not, what's wrong?
The original one had extra cruft:
1. The expression is anchored on right, so leading .* is meaningless
2. Putting tab directly makes it invisible when reading source (use \t)
3. Want to match on number, not just anything (that is why the \d)
On 2/22/2010 8:43, Stephen Hemminger wrote:
btw as a general comment on these guys
"make it more perl-ish" is not a good feature for me.
"make it more readable" would be.
these guys are not performance sensitive, lets make them as readable as possible, and not line noise.
On Mon, 2010-02-22 at 08:58 -0800, Arjan van de Ven wrote:
> On 2/22/2010 8:43, Stephen Hemminger wrote:
>
>
> btw as a general comment on these guys
>
> "make it more perl-ish" is not a good feature for me.
>
> "make it more readable" would be.
>
> these guys are not performance sensitive, lets make them as readable as possible, and not line noise.
>
Acked-by: Steven Rostedt
That is, I've purposely did not do "perlish" code in the perl scripts
that I wrote, and have consistently NACKed changes to make it so.
The perl scripts in the kernel need to be "C-ish" not "perl-ish", that
way the other 70% of the kernel programmers that do not do perl can
still understand these scripts.
-- Steve
Cleanup checkstack script:
* Turn on strict checking
* Fix resulting error message because the declaration syntax
was incorrect.
* Remove incorrect and misleading use of prototype
- prototype not required for this type of sort function
because $a and $b are being used in this contex
- if prototype was being used it should be for both arguments
* Use closure for sort function
Signed-off-by: Stephen Hemminger <[email protected]>
--- a/scripts/checkstack.pl 2010-02-22 10:15:08.120323236 -0800
+++ b/scripts/checkstack.pl 2010-02-22 10:17:49.878421919 -0800
@@ -21,6 +21,8 @@
#
# TODO : Port to all architectures (one regex per arch)
+use strict;
+
# check for arch
#
# $re is used for two matches:
@@ -104,19 +106,11 @@ my (@stack, $re, $dre, $x, $xs);
}
}
-sub bysize($) {
- my ($asize, $bsize);
- ($asize = $a) =~ s/.*: *(.*)$/$1/;
- ($bsize = $b) =~ s/.*: *(.*)$/$1/;
- $bsize <=> $asize
-}
-
#
# main()
#
my $funcre = qr/^$x* <(.*)>:$/;
-my $func;
-my $file, $lastslash;
+my ($func, $file, $lastslash);
while (my $line = <STDIN>) {
if ($line =~ m/$funcre/) {
@@ -173,4 +167,6 @@ while (my $line = <STDIN>) {
}
}
-print sort bysize @stack;
+# Sort output by size (last field)
+print sort { ($b =~ /:\t*(\d+)$/)[0] <=> ($a =~ /:\t*(\d+)$/)[0] } @stack;
+