python-flamegraph icon indicating copy to clipboard operation
python-flamegraph copied to clipboard

Add UnixFileType so things work more smoothly on Windows.

Open codypiersall opened this issue 6 years ago • 3 comments

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.

codypiersall avatar Aug 04 '18 03:08 codypiersall

Just wanted to ping you on this--what do you think about it?

codypiersall avatar Mar 10 '19 17:03 codypiersall

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 avatar Mar 11 '19 14:03 gunnihinn

@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.

codypiersall avatar Mar 11 '19 15:03 codypiersall