-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
make subprocess child shows different process name #391
make subprocess child shows different process name #391
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #391 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 2276 2293 +17
=========================================
+ Hits 2276 2293 +17 ☔ View full report in Codecov by Sentry. |
|
0d71ee1
to
9def5f4
Compare
I'm having second thought about this. This is a quick and useful change, but it also has a small side effect - other people's code might rely on However, I agree having a different name is helpful, so let's add a variable like |
OK, I can try it in the c module. |
ecc6ff9
to
6a5037e
Compare
The C module part is fine, but do not pass the process name as a cmdline argument, that's totally unnecessary. Just use your original method to set it in Also, check the coding styles in the C code, especially spaces around |
Let's remove the optional command line argument to set process name, that seems a bit too much for me. In a real subprocess case, there's no way for the user to properly set it. If we don't need it internally, we don't need it. Also, it seems like you are converting the string back and forth, from Python string to C string then back. Why not simply keep it as a Python string? You can parse that as an object and you don't need to free/reallocate memory anymore, just reference change. By parsing it as an object, you can also use |
Finished it. The commandline way is indeed kind of fragile. |
src/viztracer/modules/snaptrace.c
Outdated
if (self->process_name) { | ||
Py_DECREF(self->process_name); | ||
} | ||
self->process_name = kw_process_name; | ||
Py_INCREF(self->process_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (self->process_name) { | |
Py_DECREF(self->process_name); | |
} | |
self->process_name = kw_process_name; | |
Py_INCREF(self->process_name); | |
Py_INCREF(kw_process_name); | |
Py_XSETREF(self->process_name, kw_process_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add a unicode check here - to make sure toe process name given is a string, otherwise raise an exception.
src/viztracer/viztracer.py
Outdated
@@ -43,7 +43,8 @@ def __init__(self, | |||
dump_raw: bool = False, | |||
sanitize_function_name: bool = False, | |||
output_file: str = "result.json", | |||
plugins: Sequence[Union[VizPluginBase, str]] = []) -> None: | |||
plugins: Sequence[Union[VizPluginBase, str]] = [], | |||
process_name: Optional[str] = None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put process_name
before output_file
-> there's no strict order here, but I always feel like output_file
and plugins
should be at the end of the list.
exit(-1); | ||
PyObject* process_name = NULL; | ||
if (self->process_name) { | ||
process_name = self->process_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are losing reference here. You need to increment the reference because you are decreasing it later.
Py_DECREF(current_process_method); | ||
Py_DECREF(current_process); | ||
if (self->process_name) { | ||
process_name = self->process_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New reference here as well
tests/test_multiprocess.py
Outdated
def test_code(self): | ||
self.template(["viztracer", "-o", "result.json", "cmdline_test.py"], | ||
expected_output_file="result.json", | ||
script=file_subprocess_code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also check the process name of the subprocess on this, as it's known - should be python
I believe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the current process_name is site-packages/viztracer/__main__.py
because sys.argv
is processed in VizUI.run()
, which is before the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a process with a name python
is almost as bad as MainProcess
. Let's set the process_name
in run_code
. Update self.init_kwargs
before create the VizTracer
instance. The subprocess would be distinguishable with the distinct names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If setting process_name
in run_code
. For module, the process_name
is module name. For run python file, the process_name
is python file name. For run code by -c
, the process_name is -c
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah "-c"
is a bit weird. Let's do another check for cmd_string
and if it's set, set the process name to "python -c"
.
The |
Seemed that coverage didn't support subprocess as concurrency libraries. Maybe we should patch the command line for subprocess in coverage run. |
A couple of suggestions with the tests and we can be done with this.
|
For test with |
Great work, thanks for the contribution. |
The previous name for cubprocess child is MainProcess, which make it not easy to distinguish MainProcess and subprocess child.
This PR changes the name of subprocess child.