Skip to content

python: improve python trace user experience#1891

Open
yihong0618 wants to merge 1 commit intonamhyung:masterfrom
yihong0618:imporve_py_trace
Open

python: improve python trace user experience#1891
yihong0618 wants to merge 1 commit intonamhyung:masterfrom
yihong0618:imporve_py_trace

Conversation

@yihong0618
Copy link
Copy Markdown
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>
@yskzalloc
Copy link
Copy Markdown
Contributor

Hi, @yihong0618,

I agree that it's convenient, but we need to consider this feature carefully.
We’ve had similar discussions before. For instance, let's assume there's an access control feature like SE Linuxor App Armor enabled.

If we allow the use of /bin/uftrace but not /bin/python3 in specific user, there's a corner case where uftrace could execute a Python script without a shebang.

Yes, you could still run the script with python g.py, but that would be specific user to allowed to using python executable.

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.

2 participants