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

python: improve python trace user experience #1891

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yihong0618
Copy link
Contributor

Add a simple way to support trace python file without shebang and be an executable file.

Fixed: #1890

with this path we can trace python file just like

g.py like

import sys
import urllib.request

def open_file(name):
    try:
        return open(name)
    except:
        return urllib.request.urlopen(name)

def count_word(file_obj, word):
    n = 0
    content = str(file_obj.read())
    for ln in content.split('\n'):
        n += ln.count(word)
    return n

if __name__ == '__main__':
    url = 'https://github.com/namhyung/uftrace'
    word = 'uftrace'
    if len(sys.argv) > 1:
        url = sys.argv[1]
    if len(sys.argv) > 2:
        word = sys.argv[2]

    f = open_file(url)
    n = count_word(f, word)
    print(n)

then

uftrace g.py

Add a simple way to support trace python file without shebang and
be an executable file.

Fixed: namhyung#1890
Signed-off-by: Yi Hong <zouzou0208@gmail.com>
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.

feat: improve python trace user experience.
1 participant