Skip to content

Instantly share code, notes, and snippets.

@wsdookadr
Created October 24, 2011 21:15
Show Gist options
  • Save wsdookadr/1310342 to your computer and use it in GitHub Desktop.
Save wsdookadr/1310342 to your computer and use it in GitHub Desktop.
Devel::NYTProf 4.06 patch that adds a switch to exclude packages/namespaces from nytprofhtml output
--- /opt/Intra/lib/CPAN/bin/nytprofhtml 2011-10-17 15:27:51.000000000 +0000
+++ nytprofhtml_patched 2011-10-24 19:38:33.000000000 +0000
@@ -20,6 +20,8 @@
use List::Util qw(sum max);
use File::Copy;
use File::Path qw(rmtree);
+#use lib './pnytprof_lib';
+
# Handle --profself before loading Devel::NYTProf::Core
# (because it parses NYTPROF for options)
@@ -43,6 +45,8 @@
);
use Devel::NYTProf::Constants qw(NYTP_SCi_CALLING_SUB);
+my $excluded_filters = [ ];
+
my $json_any = eval { require JSON::Any; JSON::Any->import; JSON::Any->new }
or warn "Can't load JSON::Any module - HTML visualizations skipped.\n";
@@ -74,6 +78,7 @@
'minimal|m!'=> \my $opt_minimal,
'mergeevals!'=> \(my $opt_mergeevals = 1),
'profself!' => sub { }, # handled in BEGIN above
+ 'exclude-filters|ef' => \my $opt_exclude_filters,
) or do { exit usage(); };
@@ -82,13 +87,14 @@
sub usage {
print <<END;
usage: [perl] nytprofhtml [opts]
- --file <file>, -f <file> Read profile data from the specified file [default: nytprof.out]
- --out <dir>, -o <dir> Write report files to this directory [default: nytprof]
- --delete, -d Delete any old report files in <dir> first
- --lib <lib>, -l <lib> Add <lib> to the beginning of \@INC
- --minimal, -m Don't generate graphviz .dot files or block/sub-level reports
- --no-mergeevals Disable merging of string evals
- --help, -h Print this message
+ --file <file>, -f <file> Read profile data from the specified file [default: nytprof.out]
+ --out <dir>, -o <dir> Write report files to this directory [default: nytprof]
+ --delete, -d Delete any old report files in <dir> first
+ --lib <lib>, -l <lib> Add <lib> to the beginning of \@INC
+ --minimal, -m Don't generate graphviz .dot files or block/sub-level reports
+ --no-mergeevals Disable merging of string evals
+ --help, -h Print this message
+ --excluded-filters -ef <file> Read file with blacklist filters for packages or namespaces discarded from output
This script of part of the Devel::NYTProf distribution.
See http://search.cpan.org/dist/Devel-NYTProf/ for details and copyright.
@@ -96,6 +102,23 @@
return 1;
}
+if($opt_exclude_filters) {
+ if(!-e $opt_exclude_filters) {
+ $opt_exclude_filters = 'excluded_filters';
+ }
+
+ if(!-e $opt_exclude_filters) {
+ die 'excluded_filters file does not exist';
+ } else {
+ open my $fh,'<',$opt_exclude_filters;
+ while(my $filter=<$fh>) {
+ chomp $filter;
+ push @$excluded_filters,qr/$filter/;
+ };
+ };
+} else {
+ warn "no excludes";
+};
# handle handle output location
if (!-e $opt_out) {
@@ -677,7 +700,13 @@
$reporter->_output_additional('style.css', get_css());
# generate the files
-$reporter->report();
+$reporter->report({
+ (
+ $opt_exclude_filters
+ ? (exclude_filters => $excluded_filters)
+ : ()
+ )
+});
output_subs_index_page($reporter, "index-subs-excl.html", 'excl_time');
output_index_page($reporter, "index.html");
@@ -695,6 +724,7 @@
# output an html indexing page or subroutines
sub output_subs_index_page {
my ($r, $filename, $sortby) = @_;
+ warn "FILEEE: $filename";
my $profile = $reporter->{profile};
open my $fh, '>', "$opt_out/$filename"
--- /opt/Intra/lib/CPAN/lib/perl5/x86_64-linux-thread-multi/Devel/NYTProf/Reader.pm 2011-10-24 18:49:39.000000000 +0000
+++ pnytprof_lib/Devel/NYTProf/Reader.pm 2011-10-24 19:16:36.000000000 +0000
@@ -18,7 +18,7 @@
use Carp;
use Config;
-use List::Util qw(sum max);
+use List::Util qw(sum max first);
use Data::Dumper;
use Devel::NYTProf::Data;
@@ -156,7 +156,8 @@
print "Writing $level reports to $self->{output_dir} directory\n"
unless $opts->{quiet};
$self->_generate_report($profile, $level,
- show_progress => (not $opts->{quiet} and -t STDOUT)
+ show_progress => (not $opts->{quiet} and -t STDOUT),
+ exclude_filters => $opts->{exclude_filters}
);
$level_additional_sub->($profile, $level)
if $level_additional_sub;
@@ -216,6 +217,19 @@
my $progress;
foreach my $fi (@fis) {
+ my $pkg_name;
+ if($opts{exclude_filters}) {
+ #warn Dumper $opts{exclude_filters};
+ $pkg_name = $fi->filename;
+ $pkg_name =~ s/\/\//\//g;
+ $pkg_name =~ s/\//::/g;
+ $pkg_name =~ s/\.pm$//;
+ if(first { $pkg_name =~ $_ } @{$opts{exclude_filters}}) {
+ next;
+ };
+ };
+
+ #warn "NAAAME: ".$pkg_name;
if ($opts{show_progress}) {
local $| = 1;
@wsdookadr
Copy link
Author

This partially solves some problem I'm having on a project. Devel::NYTProf, this patch is for 4.06is pretty good but it generates almost 2G of binary data in 30m and when transformed with nytprofhtml it gets to 7G.
This patch is experimental, I haven't had enough time to go into how this affects the total reports of time taken(should look into that..)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment