Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the devel-nytprof CPAN distribution.

Report information
The Basics
Id: 74565
Status: resolved
Priority: 0/
Queue: devel-nytprof

People
Owner: Nobody in particular
Requestors: davidp [...] preshweb.co.uk
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: (no value)
Fixed in: (no value)



Subject: Insists on creating output file when loaded even with start=no
I wanted to use Devel::NYTProf at runtime, enabling profiling only at certain points and controlling which file is written to. However, Devel::NYTProf insists on creating an output file when loading it, even if it's told not to start automatically, with e.g.: $ENV{NYTPROF} = "start:no"; require Devel::NYTProf; The workaround I had to use (in Dancer::Plugin::NYTProf) is to get a temporary filename via File::Temp and pass that to Devel::NYTProf, so it can create that file, then unlink the file straight afterwards (as it's not desired), then enable profiling to the the file it should actually write to at desired points at runtime with DB::enable_profile($filename). This works, but is obviously quite hackish. My expectation was that, if I'd told Devel::NYTProf *not* to start profiling until I manually started it, that it would not attempt to open a file for output until I told it to. It seems to me that it would make sense for opening an output file to be deferred until profiling is actually starting, to avoid this issue biting anyone else.
Try $ENV{NYTPROF} = "start=no"; :-)
Download (untitled) / with headers
text/plain 726b
On 2012-01-31 22:33:49, TIMB wrote: Show quoted text
> Try $ENV{NYTPROF} = "start=no"; :-)
Oh, bugger, sorry - I made that typo initially, and NYTProf correctly blew up because it was an invalid option. I then fixed it to "start=no", but it still created a file. The exact (nasty, hackish) workaround I had to use was: my $tempfh = File::Temp->new; my $file = $tempfh->filename; $tempfh = undef; # let the file get deleted $ENV{NYTPROF} = "start=no:file=$file"; require Devel::NYTProf; unlink $file; When I used just $ENV{NYTPROF} = "start=no", it still created the file (or, rather, tried to; I was testing running a script in a dir to which I'd removed write access, as that was how the problem first showed up).
Download (untitled) / with headers
text/plain 510b
Just to provide a more solid illustration: [davidp@supernova:~/tmp/nytproftest]$ ls -ld . dr-xr-xr-x 2 davidp davidp 4096 2012-01-31 23:37 . [davidp@supernova:~/tmp/nytproftest]$ cat testcase.pl #!/usr/bin/perl $ENV{NYTPROF} = "start=no"; require Devel::NYTProf; [davidp@supernova:~/tmp/nytproftest]$ perl testcase.pl NYTProf failed to open 'nytprof.out' for writing, error 13: Permission denied at /usr/local/lib/perl/5.10.0/Devel/NYTProf.pm line 45. Compilation failed in require at testcase.pl line 3.
Download (untitled) / with headers
text/plain 181b
Try this change to NYTProf.xs: - const char *mode = "wbx"; + const char *mode = (strnEQ(filename, "/dev/", 4) ? "wb" : "wbx"); and then use NYTPROF="start=no:file=/dev/null"
Download (untitled) / with headers
text/plain 497b
On 2012-02-02 09:08:36, TIMB wrote: Show quoted text
> Try this change to NYTProf.xs: > > - const char *mode = "wbx"; > + const char *mode = (strnEQ(filename, "/dev/", 4) ? "wb" : "wbx"); > > and then use NYTPROF="start=no:file=/dev/null"
I can confirm that the above change does indeed fix the problem for me - thanks! Personally, I'd check for /dev/null rather than just /dev/, though, in case someone is trying to tell Devel::NYTProf to write to e.g. /dev/shm to store the file temporarily in memory.
Subject: Re: [rt.cpan.org #74565] Insists on creating output file when loaded even with start=no
Date: Thu, 2 Feb 2012 19:38:28 +0000
To: David Precious via RT <bug-devel-nytprof [...] rt.cpan.org>
From: Tim Bunce <Tim.Bunce [...] pobox.com>
Download (untitled) / with headers
text/plain 428b
Show quoted text
> I can confirm that the above change does indeed fix the problem for me - > thanks!
Great. Show quoted text
> Personally, I'd check for /dev/null rather than just /dev/, though, in > case someone is trying to tell Devel::NYTProf to write to e.g. /dev/shm > to store the file temporarily in memory.
Loosing the exclusive flag in such a case seems a minor loss compared to the gain of being able to write to other /dev's like /dev/fd/42 Tim.
Fixed in r2208. Thanks.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.