Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

JSON renderer #46

Merged
merged 6 commits into from
Aug 10, 2018
Merged

JSON renderer #46

merged 6 commits into from
Aug 10, 2018

Conversation

iddan
Copy link
Contributor

@iddan iddan commented Aug 4, 2018

Issues #44

Copy link
Owner

@joerick joerick left a comment

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?

def _json_frame(frame):
return {
'function': frame.function,
'file_path': frame.file_path_short,
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Cool

@@ -128,6 +129,21 @@ def render_frame(self, frame):
result += '</div></div>'

return result

def _json_frame(frame):
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

No problem

preferred_recorder = 'time_aggregating'

def render(self, frame):
return json.dumps(_json_frame(frame))
Copy link
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
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
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
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
Copy link
Contributor Author

iddan commented Aug 4, 2018

Issued the comments

@iddan
Copy link
Contributor Author

iddan commented Aug 4, 2018

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

@joerick
Copy link
Owner

joerick commented Aug 10, 2018

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

@iddan
Copy link
Contributor Author

iddan commented Aug 10, 2018

Done!

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

joerick commented Aug 10, 2018

Cheers @iddan !

@iddan
Copy link
Contributor Author

iddan commented Aug 11, 2018

Please let me know when it is released

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

joerick commented Aug 20, 2018

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
Copy link
Owner

joerick commented Aug 25, 2018

Released as 2.2.1!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants