trace-cruncher: Add API to set tracing CPU affinity
PATCH v2 1/1 trace-cruncher: Add API to set tracing CPU affinity
From: "Steven Rostedt (VMware)" <[email protected]>
Add a set_affinity API that can let the user set what CPUs to enable tracing on.
Example:
import tracecruncher.ftracepy as ft
ft.set_affinity(cpus=["0-1","3"]);
The above will set the top level instance affinity to 0,1,3 (or 0xb)
To reset back to online CPUs:
ft.reset_affinity()
Where it will reset the top level instance back to all CPUS.
---
Changes since v1: https://lore.kernel.org/all/[email protected]/
- Added reset_affinity() to set the instance to all CPUs Note, I did not add a get_affinity() because that requires adding a get_affinity to libtracefs() first.
- Will now error if cpus is not PyUnicode or PyList.
- Fixed up one line description of set affinity.
examples/reset-affinity.py | 5 ++ examples/test-affinity.py | 5 ++ src/ftracepy-utils.c | 93 ++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 6 +++ src/ftracepy.c | 10 ++++ 5 files changed, 119 insertions(+) create mode 100755 examples/reset-affinity.py create mode 100755 examples/test-affinity.py
examples/reset-affinity.py new file +5 -0
@@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +import tracecruncher.ftracepy as ft + +ft.reset_affinity();
examples/test-affinity.py new file +5 -0
@@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +import tracecruncher.ftracepy as ft + +ft.set_affinity(cpus=["0-1","3"]);
src/ftracepy-utils.c +93 -0
99 lines not on this page · raw message
src/ftracepy-utils.h +6 -0
@@ -208,6 +208,12 @@ PyObject *PyFtrace_register_kretprobe(PyObject *self, PyObject *args,PyObject *PyFtrace_hist (PyObject *self,PyObject *args,PyObject *kwargs); +PyObject *PyFtrace_set_affinity (PyObject *self,PyObject *args, +PyObject *kwargs); + +PyObject *PyFtrace_reset_affinity (PyObject *self,PyObject *args, +PyObject *kwargs); +PyObject *PyFtrace_set_ftrace_loglevel (PyObject *self,PyObject *args,PyObject *kwargs);
src/ftracepy.c +10 -0
@@ -372,11 +372,21 @@ static PyMethodDef ftracepy_methods[] = {METH_VARARGS |METH_KEYWORDS ,"Define a kretprobe." }, + {"reset_affinity", + (PyCFunction ) PyFtrace_reset_affinity, +METH_VARARGS |METH_KEYWORDS , +"Set an instance tracing affinity to all CPUs" + }, {"hist", (PyCFunction ) PyFtrace_hist,METH_VARARGS |METH_KEYWORDS ,"Define a histogram." }, + {"set_affinity", + (PyCFunction ) PyFtrace_set_affinity, +METH_VARARGS |METH_KEYWORDS , +"Return tracing affinity of an instance." + }, {"set_ftrace_loglevel", (PyCFunction ) PyFtrace_set_ftrace_loglevel, METH_VARARGS | METH_KEYWORDS,
Signature · 1 line
2.31.1
Quoted 9 lines · On Mon, 17 Jan 2022 20:12:31 -0500 Steven Rostedt <[email protected]> wrote:
+++
b/src/ftracepy.csrc/ftracepy.c +4
-0@@ -372,11 +372,21 @@ static PyMethodDef ftracepy_methods[] = {METH_VARARGS |METH_KEYWORDS ,"Define a kretprobe." }, + {"reset_affinity", + (PyCFunction ) PyFtrace_reset_affinity, +METH_VARARGS |METH_KEYWORDS , +"Set an instance tracing affinity to all CPUs"
src/ftracepy.c static PyMethodDef ftracepy_methods[] = { · line 388
Quoted 10 lines
src/ftracepy.c +5
-0+ }, {"hist" , (PyCFunction ) PyFtrace_hist,METH_VARARGS |METH_KEYWORDS ,"Define a histogram." }, + {"set_affinity", + (PyCFunction ) PyFtrace_set_affinity, +METH_VARARGS |METH_KEYWORDS , +"Return tracing affinity of an instance."
Bah, that should have been:
"Set tracing affinity of an instance."
I wrote that while working on the "get_affinity" in libtracefs. :-p
v3 soon.
-- Steve
Quoted 4 lines
src/ftracepy.c +1
-0+ }, {"set_ftrace_loglevel" , (PyCFunction ) PyFtrace_set_ftrace_loglevel, METH_VARARGS | METH_KEYWORDS,