Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

filetop: Fix TypeError by not mixing bytes and str. #942

Merged
merged 1 commit into from
Feb 14, 2017

Conversation

r4f4
Copy link
Contributor

@r4f4 r4f4 commented Feb 6, 2017

When executing the filetop command tool, the following message was
generated:

Traceback (most recent call last):
File "/usr/share/bcc/tools/filetop", line 190, in
name = name[:-3] + "..."
TypeError: can't concat bytes to str

Also, by decoding the bytes we print the strings without a leading "b'"
making the output more readable.

@4ast
Copy link
Member

4ast commented Feb 6, 2017

cc @brendangregg

@drzaeus77
Copy link
Collaborator

[buildbot, ok to test]

@drzaeus77
Copy link
Collaborator

[buildbot, test this please]

(Please ignore failures, I am doing some test runs of a new set of buildbots)

@brendangregg
Copy link
Member

brendangregg commented Feb 7, 2017

What's with the decode("utf-8")s? Other language character sets? Is there an easy example we can create to test?

If we need to do this on every process name and filename, that's going to be a big change to many tools, and litter the code with decode("utf-8")s. I'd hope there would be a way we could make it automatic for STDOUT, so we didn't need the explicit calls.

@drzaeus77
Copy link
Collaborator

I haven't found a way to elide the decode() for python2/3 compatibility, but at least decode() should take no arguments (see #886 for example).

@r4f4
Copy link
Contributor Author

r4f4 commented Feb 7, 2017

Yeah, if you just str() the bytes, they are printed as "b''". One option to get rid of some of those decodes is to save the values in the BPF class as strings instead of bytes. That way the decode has to be done only once for each attribute instead of every time you want to print them.

@drzaeus77
Copy link
Collaborator

@r4f4 Did you decide a way to go on this? Either encode before filling the table or remove the (redundant) "utf-8" parameter to shorten the code.

When executing the filetop command tool, the following message was
generated:

Traceback (most recent call last):
  File "/usr/share/bcc/tools/filetop", line 190, in <module>
    name = name[:-3] + "..."
TypeError: can't concat bytes to str

Also, by decoding the bytes we print the strings without a leading "b'"
making the output more readable.
@r4f4
Copy link
Contributor Author

r4f4 commented Feb 14, 2017

@drzaeus77 Just update the PR. I went with the .decode with no params to avoid breaking the BPF class internals.

@drzaeus77
Copy link
Collaborator

[buildbot, test this please]

@drzaeus77 drzaeus77 merged commit e105d53 into iovisor:master Feb 14, 2017
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.

None yet

4 participants