* [PATCH 1/1] scripts: add a graph generator based on checkpatch reports
@ 2014-11-22 20:56 Fabian Frederick
2014-11-23 20:27 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Fabian Frederick @ 2014-11-22 20:56 UTC (permalink / raw)
To: linux-kernel; +Cc: Fabian Frederick, Joe Perches, Linus Torvalds, Andrew Morton
This script generates a graph based on errors/warnings/checks detected
by checkpatch -f recursively on each files of a directory.
Results are grouped by subfolders and pushed in gnuplot datasets.
By default checkstat.png is generated with an histogram.
This script should always be called from kernel source root.
eg scripts/checkstat.pl fs
Cc: Joe Perches <joe@perches.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
scripts/checkstat.pl | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
create mode 100755 scripts/checkstat.pl
diff --git a/scripts/checkstat.pl b/scripts/checkstat.pl
new file mode 100755
index 0000000..8b7d451
--- /dev/null
+++ b/scripts/checkstat.pl
@@ -0,0 +1,120 @@
+#!/usr/bin/perl
+# (c) 2014, Fabian Frederick (fabf@skynet.be)
+#
+# Based on scripts/checkpatch.pl
+#
+# This script generates a graph based on errors/warnings/checks detected
+# by checkpatch -f recursively on each files of a directory.
+# Results are grouped by subfolders.
+#
+
+use strict;
+use Getopt::Long;
+use File::Basename;
+use Chart::Gnuplot;
+
+my $P = $0;
+my $statdir = '.';
+my $files;
+my @cfiles = ();
+my %stat;
+my %stats;
+my $report;
+my $currentdir = '';
+
+my $checkpatch = "scripts/checkpatch.pl";
+my $output = "checkstat.png";
+my @dontcheck = qw/fs\/nls/;
+
+sub help {
+ my $text = << "EOM";
+Usage: $P [OPTION] [DIRECTORY]
+
+This script should always be called from kernel source root.
+
+Options:
+ --output name of generated png graph.
+EOM
+ my $std=shift;
+ if ($std == 1) {
+ print STDERR $text;
+ } else {
+ print $text;
+ }
+ exit;
+}
+
+GetOptions(
+ 'h|help' => \&help,
+ 'output=s' => \$output
+);
+
+if ($#ARGV >= 0) {
+ $statdir = @ARGV[0];
+}
+
+my $graphreport = Chart::Gnuplot->new(
+ output => $output,
+ yrange => [0, '*'],
+ imagesize => '3, 2',
+ xtics => {
+ rotate => '90 right',
+ },
+ bmargin => 15,
+ title => 'Linux Kernel: checkstat - Date: `date`'
+);
+
+$files = `find $statdir -name "*.c"`;
+@cfiles = split('\n', $files);
+
+#Execute checkpatch on each file and store results
+foreach my $file (@cfiles) {
+ print "checkpatch: $file: ";
+ $currentdir = dirname($file);
+
+ if (not grep(/^$currentdir$/, @dontcheck)){
+ $report = `$checkpatch -f --terse $file | tail -n 1`;
+
+ if ($currentdir ne $statdir) {
+ $currentdir =~ s/$statdir\///;
+ $currentdir =~ s/\/(.*)//;
+ $currentdir = $statdir."/".$currentdir;
+ }
+ print "adding to ".$currentdir." stats\n";
+ my $i = 0;
+
+ foreach my $stat_type ("errors", "warnings", "checks") {
+ $report =~ m/(\d+)\s$stat_type/;
+ $stat{$currentdir}[$i++] += $1;
+ $stats{$stat_type}{$currentdir} += $1;
+ }
+ } else {
+ print "File in dontcheck list ...\n";
+ }
+}
+
+my @columns=();
+my %colors=(
+ errors => 'red',
+ warnings => 'orange',
+ checks => 'green'
+);
+
+#Reorder and push data in datasets.
+foreach my $stat_type (keys %stats) {
+ my @xdir=();
+
+ foreach my $dir (sort keys %{$stats{$stat_type}}){
+ push @xdir, [$dir, $stats{$stat_type}{$dir}];
+ }
+ push @columns, Chart::Gnuplot::DataSet->new(
+ points => \@xdir,
+ title => $stat_type,
+ color => $colors{$stat_type},
+ fill => {density => 1},
+ style => "histograms",
+ );
+}
+
+$graphreport->plot2d(@columns);
+print("graph generated: $output\n");
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] scripts: add a graph generator based on checkpatch reports
2014-11-22 20:56 [PATCH 1/1] scripts: add a graph generator based on checkpatch reports Fabian Frederick
@ 2014-11-23 20:27 ` Joe Perches
2014-11-24 16:31 ` Fabian Frederick
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2014-11-23 20:27 UTC (permalink / raw)
To: Fabian Frederick; +Cc: linux-kernel, Linus Torvalds, Andrew Morton
On Sat, 2014-11-22 at 21:56 +0100, Fabian Frederick wrote:
> This script generates a graph based on errors/warnings/checks detected
> by checkpatch -f recursively on each files of a directory.
> Results are grouped by subfolders and pushed in gnuplot datasets.
Why is this useful?
Ingo's badly named script does something similar:
http://people.redhat.com/mingo/x86.git/code-quality
just without the plots.
btw: this line:
$files = `find $statdir -name "*.c"`;
should probably be
$files = `git ls-files -- "$statdir/*.[ch]"`;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] scripts: add a graph generator based on checkpatch reports
2014-11-23 20:27 ` Joe Perches
@ 2014-11-24 16:31 ` Fabian Frederick
0 siblings, 0 replies; 3+ messages in thread
From: Fabian Frederick @ 2014-11-24 16:31 UTC (permalink / raw)
To: Joe Perches; +Cc: Andrew Morton, linux-kernel, Linus Torvalds
> On 23 November 2014 at 21:27 Joe Perches <joe@perches.com> wrote:
>
>
> On Sat, 2014-11-22 at 21:56 +0100, Fabian Frederick wrote:
> > This script generates a graph based on errors/warnings/checks detected
> > by checkpatch -f recursively on each files of a directory.
> > Results are grouped by subfolders and pushed in gnuplot datasets.
>
> Why is this useful?
>
> Ingo's badly named script does something similar:
> http://people.redhat.com/mingo/x86.git/code-quality
>
> just without the plots.
>
> btw: this line:
>
> $files = `find $statdir -name "*.c"`;
>
> should probably be
>
> $files = `git ls-files -- "$statdir/*.[ch]"`;
>
This script was meant for reporting so it's just useful because of the
graphs and the fact it can do all in one operation.
Most of all, when someone does a talk and shows up some graph,
it would be both easier and valid to tell it's using scripts/checkstat
on kernel x.y rather than sparse operations someone won't
easily reproduce.
I don't think using directly git operations would be a good thing.
This script could be used directly downloading tar.gz without it.
(Of course Git could be bring nice options in future versions :)).
Regards,
Fabian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-11-24 16:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-22 20:56 [PATCH 1/1] scripts: add a graph generator based on checkpatch reports Fabian Frederick
2014-11-23 20:27 ` Joe Perches
2014-11-24 16:31 ` Fabian Frederick
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).