Skip to content

JSON renderer - #46

Merged
joerick merged 6 commits into
joerick:masterfrom
iddan:json-renderer
Aug 10, 2018
Merged

joerick merged 6 commits into
joerick:masterfrom
iddan:json-renderer

Conversation

@iddan

@iddan iddan commented Aug 4, 2018 •

Copy link
Copy Markdown
Contributor

Issues #44

@joerick joerick left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks iddan - I think the general output format is the right approach.

Could you add at least one test that reads the output of this renderer and checks there are the expected functions there?

Comment thread pyinstrument/renderers.py Outdated
def _json_frame(frame):
return {
'function': frame.function,
'file_path': frame.file_path_short,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interests of creating a generally useful solution, I'd rather this was called file_path_short, in case we want to add file_path in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

Comment thread pyinstrument/renderers.py Outdated

return result

def _json_frame(frame):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a method on the JSONRenderer object?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem

Comment thread pyinstrument/renderers.py Outdated
preferred_recorder = 'time_aggregating'

def render(self, frame):
return json.dumps(_json_frame(frame))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be nice to add indent=2 to make the output prettier on the terminal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though about it: many outputs can generate big outputs so adding spacing chars would increase their size significantly. Maybe this should be another renderer / CLI option?
If you go the UNIX way you can always do: python -m pyinstrument script.py | python -m json.tool

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I don't agree. JSON is a really verbose format. All those repeated key names! All those numbers written out as strings.

The big advantage of JSON is human-readability - you can look at it and quickly understand it. To strip indentation is to lose that.

If size becomes a meaningful issue the right answer would be to remove frames with tiny durations, or use something like Protobuf.

(Re. piping through python -m json.tool - it's a good idea, but I don't think the burden of a good user experience should be on the user)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will add

@iddan

iddan commented Aug 4, 2018

Copy link
Copy Markdown
Contributor Author

Issued the comments

@iddan

iddan commented Aug 4, 2018

Copy link
Copy Markdown
Contributor Author

Here is the app expecting the result: https://python-flame-chart.netlify.com

@joerick

joerick commented Aug 10, 2018

Copy link
Copy Markdown
Owner

Just waiting on the indent=2 change and then I can merge this! :)

@iddan

iddan commented Aug 10, 2018

Copy link
Copy Markdown
Contributor Author

Done!

@joerick
joerick merged commit cd58af6 into joerick:master Aug 10, 2018
@joerick

joerick commented Aug 10, 2018

Copy link
Copy Markdown
Owner

Cheers @iddan !

@iddan

iddan commented Aug 11, 2018

Copy link
Copy Markdown
Contributor Author

Please let me know when it is released

@iddan
iddan deleted the json-renderer branch August 11, 2018 09:12
@joerick

joerick commented Aug 20, 2018

Copy link
Copy Markdown
Owner

Apologies for the delay - working on a few more changes and tests before the next release. In the meantime, you can install from the master branch directly - pip install https://github.com/joerick/pyinstrument/archive/master.zip

@joerick

joerick commented Aug 25, 2018

Copy link
Copy Markdown
Owner

Released as 2.2.1!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants