python-flamegraph
python-flamegraph copied to clipboard
Add UnixFileType so things work more smoothly on Windows.
Instead of using argparse.FileType, this implements a subclass which ensures that newlines on Windows are '\n' instead of '\r\n'.
flamegraph.pl cannot parse the logs generated with carriage returns, so this PR prevents users on Windows from needing to do an extra step before running flamegraph.pl.
The implementation of the __call__
method was copy/pasted from Python's standard library.
I think a functionally equivalent change would be to define this function:
def file_for_writing(fname):
if fname == '-':
return stdout
else:
return open(fname, 'w', newline='\n')
and pass type=file_for_writing
for the --output
argument.
Just wanted to ping you on this--what do you think about it?
For what it's worth, I'm using this module on Windows, and when I run flamegraph.pl
with Strawberry Perl, it's fine with the Windows line endings.
@gunnihinn Gotchya. Thanks for the feedback. I can't remember what perl distribution I was using at the time, but I was probably using the one that ships with git (based on where perl
, it's the first one in my path). Unix line endings should still work with Strawberry Perl though, I would think.