New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add fudge-usage-stat.pl to show usage of fudge implementations, verbs… #228
Open
ronaldxs
wants to merge
3
commits into
Raku:master
Choose a base branch
from
ronaldxs:fudge-usage-stat
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#!/usr/bin/env perl | ||
|
||
###################################################################### | ||
# fudge-useage-stat.pl | ||
# | ||
# Usage stats of fudge implementations, versions and verbs for roast. | ||
# | ||
###################################################################### | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use File::Find; | ||
use File::Spec::Functions qw(canonpath); | ||
use Text::Table; | ||
use Cwd qw(cwd); | ||
|
||
my $find_dir = @ARGV ? canonpath(shift) : '.'; | ||
|
||
if ( scalar(my @a = <$find_dir/S0[1-9]*>) < 10 ) { | ||
die <<"USAGE"; | ||
Usage: $0 [roast directory] | ||
|
||
Intended to run against directory with synopses but not many | ||
synopses in working directory (defaults to cwd). | ||
USAGE | ||
} | ||
|
||
my @fudge_impl; | ||
my %fudge_version; | ||
|
||
###################################################################### | ||
# Called by File::Find find with a file. If the file is a test file | ||
# grep it for fudges and extract the parsed fudges. | ||
###################################################################### | ||
sub wanted { | ||
return if ( | ||
$File::Find::dir eq $find_dir and /^fudge(all)?$/ or | ||
$File::Find::dir =~ m!^$find_dir?/(t|packages)(t/|$)! or | ||
-d $File::Find::name or | ||
# don't want to process fudged files | ||
# may want to consider less restrictive some day | ||
not /\.t$/ | ||
); | ||
|
||
open(my $test_fh, $_) or | ||
die "Could not open file to grep for fudges - $_: $!"; | ||
while (<$test_fh>) { | ||
next unless m&^ | ||
(?!\#!(/|\s*http://)) # don't match shell shebang | ||
\s*\#[?!] | ||
(?!DOES) # ignore DOES directives for now | ||
ξ | ||
|
||
if ( /^\s*#\?(v6\S*)/ ) { | ||
$fudge_version{ $1 }++; | ||
} | ||
elsif ( /^ \s*\#[?!] | ||
( # 1) implementation | ||
([^.\s]*) # 2) implementation - compiler | ||
(?:\.(\S*))? # 3) impl - backend or other components | ||
) | ||
\s+ | ||
(?:\d+\s*)? # optional count | ||
(\w+) # 4) verb | ||
/x ) { | ||
my $impl_fudge_i = { | ||
implementation => $1, | ||
compiler => $2, | ||
backend => $3, | ||
verb => $4 | ||
}; | ||
warn "Unknown compiler and implementation", | ||
" from $File::Find::name line $.: $1\n" | ||
if ( $2 !~ /^nie(zc|cz|z)a?|rakudo|mildew|kp6$/ ); | ||
push @fudge_impl, $impl_fudge_i; | ||
} | ||
else { | ||
warn 'Unrecognized fudge directive', | ||
" from $File::Find::name line $.: $_"; | ||
} | ||
} | ||
} | ||
|
||
###################################################################### | ||
# Count up fudge implementation usage from the @fudge_impl parsed | ||
# fudge implementation record list. | ||
###################################################################### | ||
sub print_count_table { | ||
my @keys = @_; | ||
my %count_by_key; | ||
|
||
$count_by_key{ "@{$_}{@keys}" } ++ foreach @fudge_impl; | ||
|
||
my $tb = Text::Table->new( | ||
@keys, "Count by occurrence" | ||
); | ||
|
||
$tb->load(map { | ||
[ (split), $count_by_key{ $_ } ] | ||
} sort { # sort by (composite) key | ||
my @a = split ' ', $a; | ||
my @b = split ' ', $b; | ||
|
||
for (my $i = 0; $i < @a; $i++) { | ||
my $cmp = ($a[ $i ] // '') cmp ($b[ $i ] // ''); | ||
return $cmp if $cmp; | ||
} | ||
return 0; | ||
} keys %count_by_key ); | ||
|
||
print $tb; | ||
} | ||
|
||
find (\&wanted, $find_dir); | ||
|
||
foreach my $k (qw(implementation compiler verb)) { | ||
print_count_table $k; | ||
print $/; | ||
} | ||
|
||
my $tb = Text::Table->new( 'version', 'Count by occurrence' ); | ||
$tb->load( | ||
map { [ $_, $fudge_version{ $_ } ] } sort keys %fudge_version | ||
); | ||
print $tb, $/; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we'll drift away from binding to synopses. Just 'tests' would be good enough.