Skip to contentSkip to conversation

trace-cruncher: Improve error messages

PATCH New Yordan Karadzhov (VMware) 1 participant 6 messages Oct 1, 2021

lore
Share & tools
lore
#0 lore raw

cover trace-cruncher: Improve error messages

Various small fixes aiming to make the error messages, printed by trace-cruncher, more useful.

Yordan Karadzhov (VMware) (5):
trace-cruncher: Error on fail to destroy
trace-cruncher: Proper type name for the python objects
trace-cruncher: Correct misleading error message
trace-cruncher: Proper labeling of the libtracefs errors
trace-cruncher: Proper labeling of non libtracefs errors

 src/common.h         | 11 +++++++----
 src/ftracepy-utils.c | 26 ++++++++++++++------------
 src/ftracepy-utils.h |  2 +-
 3 files changed, 22 insertions(+), 17 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/5 trace-cruncher: Error on fail to destroy

Always print an error message in the case when the C object, being wrapped by the Python type failed to destroy.

---
 src/common.h         | 7 +++++--
 src/ftracepy-utils.c | 4 ++--
 src/ftracepy-utils.h | 2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)
src/common.h +5 -2
index abfda1f..697b327 100644
@@ -54,8 +54,9 @@ static inline void no_free(void *ptr)
 
 #define NO_FREE		no_free
 
-static inline void no_destroy(void *ptr)
+static inline int no_destroy(void *ptr)
 {
+	return 0;
 }
 
 #define NO_DESTROY	no_destroy
@@ -101,7 +102,9 @@ static int py_type##_init(py_type *self, PyObject *args, PyObject *kwargs)	\
 static void py_type##_dealloc(py_type *self)					\
 {										\
 	if (self->destroy)							\
-		obj_destroy(self->ptrObj);					\
+		if (obj_destroy(self->ptrObj) < 0)				\
+			printf("fracepy_error: object '%s' failed to destroy\n",\
+			       c_type);						\
 	ptr_free(self->ptrObj);							\
 	Py_TYPE(self)->tp_free(self);						\
 }										\
src/ftracepy-utils.c +2 -2
index ca7f914..e49132d 100644
@@ -1757,9 +1757,9 @@ PyObject *PyKprobe_probe(PyKprobe *self)
 	return PyUnicode_FromString(self->ptrObj->probe);
 }
 
-void ftracepy_kprobe_destroy(struct ftracepy_kprobe *kp)
+int ftracepy_kprobe_destroy(struct ftracepy_kprobe *kp)
 {
-	unregister_kprobe(kp->event);
+	return tracefs_kprobe_clear_probe(TC_SYS, kp-> event, true);
 }
 
 void ftracepy_kprobe_free(struct ftracepy_kprobe *kp)
src/ftracepy-utils.h +1 -1
index 9f4c4ba..a6133cf 100644
@@ -26,7 +26,7 @@ C_OBJECT_WRAPPER_DECLARE(tracefs_instance, PyTfsInstance)
 
 struct ftracepy_kprobe;
 
-void ftracepy_kprobe_destroy(struct ftracepy_kprobe *kp);
+int ftracepy_kprobe_destroy(struct ftracepy_kprobe *kp);
 
 void ftracepy_kprobe_free(struct ftracepy_kprobe *kp);
 
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/5 trace-cruncher: Proper type name for the python objects

In reply to Yordan Karadzhov (VMware)

This name gets printed as part of the error messages. It makes no sense to have it include the 'C' type since the developer that will see the error message will have no idea about the 'C' internals of the Python module.

---
 src/common.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/common.h +2 -2
index 697b327..b4c66b7 100644
@@ -63,7 +63,7 @@ static inline int no_destroy(void *ptr)
 
 #define STR(x) #x
 
-#define MAKE_TYPE_STR(x) STR(trace.x)
+#define MAKE_TYPE_STR(x) STR(ftracepy.x)
 
 #define MAKE_DIC_STR(x) STR(libtrace x object)
 
@@ -84,7 +84,7 @@ bool py_type##_Check(PyObject *obj);						\
 
 #define  C_OBJECT_WRAPPER(c_type, py_type, obj_destroy, ptr_free)		\
 static PyTypeObject py_type##Type = {						\
-	PyVarObject_HEAD_INIT(NULL, 0) MAKE_TYPE_STR(c_type)			\
+	PyVarObject_HEAD_INIT(NULL, 0) MAKE_TYPE_STR(py_type)			\
 };										\
 PyObject *py_type##_New(struct c_type *c_ptr)					\
 {										\
Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/5 trace-cruncher: Correct misleading error message

In reply to Yordan Karadzhov (VMware)

Indeed, the callback function can be included from a plugin, but this is an option. In the default case it will be searched in '__main__'.

---
 src/ftracepy-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/ftracepy-utils.c +1 -1
index e49132d..b0f5e0e 100644
@@ -2039,7 +2039,7 @@ static PyObject *get_callback_func(const char *plugin_name, const char * py_call
 	py_func = PyObject_GetAttrString(py_module, py_callback);
 	if (!py_func || !PyCallable_Check(py_func)) {
 		TfsError_fmt(NULL,
-			     "Failed to import callback from plugin \'%s\'",
+			     "Failed to import callback from \'%s\'",
 			     plugin_name);
 		return NULL;
 	}
Signature · 1 line
2.30.2
#4 lore raw

PATCH 4/5 trace-cruncher: Proper labeling of the libtracefs errors

In reply to Yordan Karadzhov (VMware)

'TEP_ERROR' is supposed to be used with errors coming from libtraceevent, not from libtracefs.

---
 src/ftracepy-utils.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/ftracepy-utils.c +4 -4
index b0f5e0e..1a8a136 100644
@@ -68,14 +68,14 @@ static void TfsError_fmt(struct tracefs_instance *instance,
 		vasprintf(&tc_err_log, fmt, args);
 		va_end(args);
 
-		PyErr_Format(TEP_ERROR, "%s\ntfs_error: %s",
+		PyErr_Format(TFS_ERROR, "%s\ntfs_error: %s",
 			     tc_err_log, tfs_err_log);
 
 		tfs_clear_error_log(instance);
 		free(tfs_err_log);
 		free(tc_err_log);
 	} else {
-		PyErr_FormatV(TEP_ERROR, fmt, args);
+		PyErr_FormatV(TFS_ERROR, fmt, args);
 		va_end(args);
 	}
 }
@@ -86,11 +86,11 @@ static void TfsError_setstr(struct tracefs_instance *instance,
 	char *tfs_err_log = tfs_error_log(instance, NULL);
 
 	if (tfs_err_log) {
-		PyErr_Format(TEP_ERROR, "%s\ntfs_error: %s", msg, tfs_err_log);
+		PyErr_Format(TFS_ERROR, "%s\ntfs_error: %s", msg, tfs_err_log);
 		tfs_clear_error_log(instance);
 		free(tfs_err_log);
 	} else {
-		PyErr_SetString(TEP_ERROR, msg);
+		PyErr_SetString(TFS_ERROR, msg);
 	}
 }
 
Signature · 1 line
2.30.2
#5 lore raw

PATCH 5/5 trace-cruncher: Proper labeling of non libtracefs errors

In reply to Yordan Karadzhov (VMware)

Those particular errors are internal for trace-cruncher and have nothing to do with libtracefs. The labels must indicate this.

---
 src/ftracepy-utils.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
src/ftracepy-utils.c +7 -5
index 1a8a136..d8115f6 100644
@@ -2031,14 +2031,15 @@ static PyObject *get_callback_func(const char *plugin_name, const char * py_call
 	py_name = PyUnicode_FromString(plugin_name);
 	py_module = PyImport_Import(py_name);
 	if (!py_module) {
-		TfsError_fmt(NULL, "Failed to import plugin \'%s\'",
+		PyErr_Format(TRACECRUNCHER_ERROR,
+			     "Failed to import plugin \'%s\'",
 			     plugin_name);
 		return NULL;
 	}
 
 	py_func = PyObject_GetAttrString(py_module, py_callback);
 	if (!py_func || !PyCallable_Check(py_func)) {
-		TfsError_fmt(NULL,
+		PyErr_Format(TRACECRUNCHER_ERROR,
 			     "Failed to import callback from \'%s\'",
 			     plugin_name);
 		return NULL;
@@ -2169,7 +2170,7 @@ PyObject *PyFtrace_trace_shell_process(PyObject *self, PyObject *args,
 
 	pid = fork();
 	if (pid < 0) {
-		TfsError_setstr(instance, "Failed to fork");
+		PyErr_SetString(TRACECRUNCHER_ERROR, "Failed to fork");
 		return NULL;
 	}
 
@@ -2215,7 +2216,8 @@ PyObject *PyFtrace_trace_process(PyObject *self, PyObject *args,
 		return NULL;
 
 	if (!PyList_CheckExact(py_argv)) {
-		TfsError_setstr(instance, "Failed to parse \'argv\' list");
+		PyErr_SetString(TRACECRUNCHER_ERROR,
+				"Failed to parse \'argv\' list");
 		return NULL;
 	}
 
@@ -2223,7 +2225,7 @@ PyObject *PyFtrace_trace_process(PyObject *self, PyObject *args,
 
 	pid = fork();
 	if (pid < 0) {
-		TfsError_setstr(instance, "Failed to fork");
+		PyErr_SetString(TRACECRUNCHER_ERROR, "Failed to fork");
 		return NULL;
 	}
 
Signature · 1 line
2.30.2