Doxygen Book
gsttensor_debug.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-only */
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37 
38 #include <string.h>
39 #include <nnstreamer_log.h>
40 #include <nnstreamer_util.h>
41 #include "gsttensor_debug.h"
42 #include "tensor_meta.h"
43 
47 #ifndef DBG
48 #define DBG (!self->silent)
49 #endif
50 
51 GST_DEBUG_CATEGORY_STATIC (gst_tensor_debug_debug);
52 #define GST_CAT_DEFAULT gst_tensor_debug_debug
53 
58 #define CAPS_STRING GST_TENSORS_CAP_MAKE(GST_TENSOR_FORMAT_ALL)
59 
63 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
64  GST_PAD_SINK,
65  GST_PAD_ALWAYS,
66  GST_STATIC_CAPS (CAPS_STRING));
67 
71 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
72  GST_PAD_SRC,
73  GST_PAD_ALWAYS,
74  GST_STATIC_CAPS (CAPS_STRING));
75 
79 enum
80 {
86 };
87 
88 #define C_FLAGS(v) ((guint) v)
89 
90 #define TENSOR_DEBUG_TYPE_OUTPUT_FLAGS (tensor_debug_output_flags_get_type())
91 
94 static GType
96 {
97  static GType type = G_TYPE_INVALID;
98 
99  if (type == G_TYPE_INVALID) {
100  static const GFlagsValue values[] = {
102  "Disable log output and write. Do not add other flags to have this flag effective.",
103  "disabled"},
105  "Console output with info. Cannot combine with other console flags",
106  "console-info"},
108  "Console output with warning. Cannot combine with other console flags",
109  "console-warn"},
111  "Console output with error. Cannot combine with other console flags",
112  "console-error"},
114  "Gstlog output with info. Cannot combine with other gstdbg flags",
115  "gstdebug-info"},
117  "Gstlog output with warning. Cannot combine with other gstdbg flags",
118  "gstdebug-warn"},
120  "Gstlog output with error. Cannot combine with other gstdbg flags",
121  "gstdebug-error"},
123  "Store at gsttensor_debug circular buffer so that it can be retrieved by the application later (NYI)",
124  "circularbuf"},
126  "Write to a file (NYI)", "filewrite"},
127  {0, NULL, NULL}
128  };
129  type = g_flags_register_static ("gtd_output", values);
130  }
131 
132  return type;
133 }
134 
135 #define DEFAULT_TENSOR_DEBUG_OUTPUT_FLAGS (TDBG_OUTPUT_CONSOLE_I)
136 
137 #define TENSOR_DEBUG_TYPE_CAPS (tensor_debug_cap_get_type())
138 
141 static GType
143 {
144  static GType type = G_TYPE_INVALID;
145  if (type == G_TYPE_INVALID) {
146  static GEnumValue values[] = {
147  {TDBG_CAP_DISABLED, "disabled", "Do not log stream capability"},
148  {TDBG_CAP_SHOW_UPDATE, "updates",
149  "Log stream capability if it is updated or initialized."},
150  {TDBG_CAP_SHOW_UPDATE_F, "updates-full",
151  "Log stream capability if the capability or dimensions of flexible/sparse tensors are updated. Logs dimension info of flexible/sparse tensors as well."},
152  {TDBG_CAP_SHOW_ALWAYS, "always",
153  "Always, log stream capability and tensor dimension information."},
154  {0, NULL, NULL}
155  };
156  type = g_enum_register_static ("gtd_cap", values);
157  }
158  return type;
159 }
160 
161 #define DEFAULT_TENSOR_DEBUG_CAP (TDBG_CAP_SHOW_UPDATE_F)
162 
163 #define TENSOR_DEBUG_TYPE_META_FLAGS (tensor_debug_meta_flags_get_type())
164 
167 static GType
169 {
170  static GType type = G_TYPE_INVALID;
171 
172  if (type == G_TYPE_INVALID) {
173  static const GFlagsValue values[] = {
175  "Do not log stream metadata.", "disabled"},
176  {C_FLAGS (TDBG_META_TIMESTAMP), "Log timestamp information", "timestamp"},
178  "Log tensor-query-server related information", "queryserver"},
179  {0, NULL, NULL}
180  };
181  type = g_flags_register_static ("gtd_meta", values);
182  }
183  return type;
184 }
185 
186 #define DEFAULT_TENSOR_DEBUG_META_FLAGS (TDBG_META_DISABLED)
187 
191 #define DEFAULT_SILENT TRUE
192 
193 #define gst_tensor_debug_parent_class parent_class
194 G_DEFINE_TYPE (GstTensorDebug, gst_tensor_debug, GST_TYPE_BASE_TRANSFORM);
195 
196 /* gobject vmethods */
197 static void gst_tensor_debug_set_property (GObject * object,
198  guint prop_id, const GValue * value, GParamSpec * pspec);
199 static void gst_tensor_debug_get_property (GObject * object,
200  guint prop_id, GValue * value, GParamSpec * pspec);
201 static void gst_tensor_debug_finalize (GObject * object);
202 
203 /* gstbasetransform vmethods */
204 static GstFlowReturn gst_tensor_debug_transform_ip (GstBaseTransform * trans,
205  GstBuffer * buffer);
206 static GstCaps *gst_tensor_debug_fixate_caps (GstBaseTransform * trans,
207  GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
208 static gboolean gst_tensor_debug_set_caps (GstBaseTransform * trans,
209  GstCaps * incaps, GstCaps * outcaps);
210 
214 static void
216 {
217  GObjectClass *object_class;
218  GstElementClass *element_class;
219  GstBaseTransformClass *trans_class;
220 
221  GST_DEBUG_CATEGORY_INIT (gst_tensor_debug_debug, "tensor_debug", 0,
222  "Element to provide debug information of other/tensors streams. If this is enabled, the pipeline performance and overhead may be deteriorated significantly.");
223 
224  trans_class = (GstBaseTransformClass *) klass;
225  object_class = (GObjectClass *) klass;
226  element_class = (GstElementClass *) klass;
227 
228  /* GObjectClass vmethods */
229  object_class->set_property = gst_tensor_debug_set_property;
230  object_class->get_property = gst_tensor_debug_get_property;
231  object_class->finalize = gst_tensor_debug_finalize;
232 
238  g_object_class_install_property (object_class, PROP_SILENT,
239  g_param_spec_boolean ("silent", "silent", "Produce verbose output",
240  DEFAULT_SILENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
241 
248  g_object_class_install_property (object_class, PROP_OUTPUT,
249  g_param_spec_flags ("output-method", "output",
250  "Output methods for debug/profile contents. Different methods can be enabled simultaneously.",
252  G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
253 
259  g_object_class_install_property (object_class, PROP_CAP,
260  g_param_spec_enum ("capability", "cap",
261  "The logging preference for stream capability (GSTCAP)",
263  G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
264 
270  g_object_class_install_property (object_class, PROP_META,
271  g_param_spec_flags ("metadata", "meta",
272  "The logging preference for stream metadata (GstMeta)",
274  G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
275 
276 
277  /* set pad template */
278  gst_element_class_add_pad_template (element_class,
279  gst_static_pad_template_get (&src_factory));
280  gst_element_class_add_pad_template (element_class,
281  gst_static_pad_template_get (&sink_factory));
282 
283  gst_element_class_set_static_metadata (element_class,
284  "TensorDebug",
285  "Filter/Tensor",
286  "Help debug or profile a tensor stream by logging the desired details of other/tensors. Users may log the details to console, files, or memory buffers.",
287  "MyungJoo Ham <myungjoo.ham@samsung.com>");
288 
289  /* GstBaseTransform vmethods */
290  trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_tensor_debug_transform_ip);
291 
292  trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_tensor_debug_fixate_caps);
293  trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_tensor_debug_set_caps);
294 
295  /* GstBaseTransform Property */
296  trans_class->passthrough_on_same_caps = TRUE;
298  trans_class->transform_ip_on_passthrough = TRUE;
307 }
308 
312 static void
314 {
316  self->silent = DEFAULT_SILENT;
317  self->output_mode = DEFAULT_TENSOR_DEBUG_OUTPUT_FLAGS;
318  self->cap_mode = DEFAULT_TENSOR_DEBUG_CAP;
319  self->meta_mode = DEFAULT_TENSOR_DEBUG_META_FLAGS;
320 
321 }
322 
326 static void
327 gst_tensor_debug_finalize (GObject * object)
328 {
329  G_OBJECT_CLASS (parent_class)->finalize (object);
330 }
331 
335 static void
336 gst_tensor_debug_set_property (GObject * object, guint prop_id,
337  const GValue * value, GParamSpec * pspec)
338 {
339  GstTensorDebug *self = GST_TENSOR_DEBUG (object);
340 
341  switch (prop_id) {
342  case PROP_SILENT:
343  self->silent = g_value_get_boolean (value);
344  silent_debug (self, "Set silent = %d", self->silent);
345  break;
346  case PROP_OUTPUT:
347  self->output_mode = g_value_get_flags (value);
348  silent_debug (self, "Set output = %x", self->output_mode);
349  break;
350  case PROP_CAP:
351  self->cap_mode = g_value_get_enum (value);
352  silent_debug (self, "Set cap = %x", self->cap_mode);
353  break;
354  case PROP_META:
355  self->meta_mode = g_value_get_flags (value);
356  silent_debug (self, "Set meta = %x", self->meta_mode);
357  break;
358  default:
359  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
360  break;
361  }
362 }
363 
367 static void
368 gst_tensor_debug_get_property (GObject * object, guint prop_id,
369  GValue * value, GParamSpec * pspec)
370 {
371  GstTensorDebug *self = GST_TENSOR_DEBUG (object);
372 
373  switch (prop_id) {
374  case PROP_SILENT:
375  g_value_set_boolean (value, self->silent);
376  break;
377  case PROP_OUTPUT:
378  g_value_set_flags (value, self->output_mode);
379  break;
380  case PROP_CAP:
381  g_value_set_enum (value, self->cap_mode);
382  break;
383  case PROP_META:
384  g_value_set_flags (value, self->meta_mode);
385  break;
386  default:
387  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
388  break;
389  }
390 }
391 
396 static void
397 _gst_tensor_debug_output (GstTensorDebug * self, GstBuffer * buffer)
398 {
399  UNUSED (self);
400  UNUSED (buffer);
402 }
403 
407 static GstFlowReturn
408 gst_tensor_debug_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
409 {
410  GstTensorDebug *self = GST_TENSOR_DEBUG (trans);
411 
412  _gst_tensor_debug_output (self, buffer);
413 
414  return GST_FLOW_OK;
415 }
416 
420 static GstCaps *
421 gst_tensor_debug_fixate_caps (GstBaseTransform * trans,
422  GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
423 {
424  UNUSED (trans);
425  UNUSED (direction);
426  UNUSED (caps);
427 
428  return gst_caps_fixate (othercaps);
429 }
430 
434 static gboolean
435 gst_tensor_debug_set_caps (GstBaseTransform * trans,
436  GstCaps * in_caps, GstCaps * out_caps)
437 {
438  UNUSED (trans);
439 
440  return gst_caps_can_intersect (in_caps, out_caps);
441 }
gst_tensor_debug_set_property
static void gst_tensor_debug_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
Setter for tensor_debug properties.
Definition: gsttensor_debug.c:336
TDBG_OUTPUT_CIRCULARBUF
@ TDBG_OUTPUT_CIRCULARBUF
Definition: gsttensor_debug.h:56
PROP_OUTPUT
@ PROP_OUTPUT
Definition: gsttensor_debug.c:83
gsttensor_debug.h
GStreamer plugin to help debug tensor streams.
tensor_debug_output_flags_get_type
static GType tensor_debug_output_flags_get_type(void)
Flags for output_mode of GstTensorDebug.
Definition: gsttensor_debug.c:95
CAPS_STRING
#define CAPS_STRING
Definition: gsttensor_debug.c:58
nnstreamer_log.h
Internal log util for NNStreamer plugins and native APIs.
TDBG_OUTPUT_FILEWRITE
@ TDBG_OUTPUT_FILEWRITE
Definition: gsttensor_debug.h:57
tensor_debug_cap_get_type
static GType tensor_debug_cap_get_type(void)
Enums for cap_mode of GstTensorDebug.
Definition: gsttensor_debug.c:142
tensor_meta.h
Internal tensor meta header for nnstreamer.
TDBG_CAP_DISABLED
@ TDBG_CAP_DISABLED
Definition: gsttensor_debug.h:65
gst_tensor_debug_set_caps
static gboolean gst_tensor_debug_set_caps(GstBaseTransform *trans, GstCaps *incaps, GstCaps *outcaps)
set caps. required vmethod of GstBaseTransform.
Definition: gsttensor_debug.c:435
TENSOR_DEBUG_TYPE_CAPS
#define TENSOR_DEBUG_TYPE_CAPS
Definition: gsttensor_debug.c:137
sink_factory
static GstStaticPadTemplate sink_factory
The capabilities of the inputs.
Definition: gsttensor_debug.c:63
gst_tensor_debug_fixate_caps
static GstCaps * gst_tensor_debug_fixate_caps(GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *othercaps)
fixate caps. required vmethod of GstBaseTransform.
Definition: gsttensor_debug.c:421
silent_debug
#define silent_debug(self,...)
Macro for debug message.
Definition: tensor_common.h:276
gst_tensor_debug_finalize
static void gst_tensor_debug_finalize(GObject *object)
Function to finalize instance.
Definition: gsttensor_debug.c:327
GST_TENSOR_DEBUG
#define GST_TENSOR_DEBUG(obj)
Definition: gsttensor_debug.h:31
_GstTensorDebug
Internal data structure for tensor_debug instances.
Definition: gsttensor_debug.h:84
gst_tensor_debug_class_init
static void gst_tensor_debug_class_init(GstTensorDebugClass *klass)
Initialize the tensor_debug's class.
Definition: gsttensor_debug.c:215
TDBG_OUTPUT_DISABLED
@ TDBG_OUTPUT_DISABLED
Definition: gsttensor_debug.h:49
DEFAULT_TENSOR_DEBUG_META_FLAGS
#define DEFAULT_TENSOR_DEBUG_META_FLAGS
Definition: gsttensor_debug.c:186
TDBG_META_DISABLED
@ TDBG_META_DISABLED
Definition: gsttensor_debug.h:76
TDBG_CAP_SHOW_UPDATE_F
@ TDBG_CAP_SHOW_UPDATE_F
Definition: gsttensor_debug.h:67
TDBG_OUTPUT_CONSOLE_W
@ TDBG_OUTPUT_CONSOLE_W
Definition: gsttensor_debug.h:51
TENSOR_DEBUG_TYPE_OUTPUT_FLAGS
#define TENSOR_DEBUG_TYPE_OUTPUT_FLAGS
Definition: gsttensor_debug.c:90
TDBG_OUTPUT_GSTDBG_E
@ TDBG_OUTPUT_GSTDBG_E
Definition: gsttensor_debug.h:55
TDBG_META_TIMESTAMP
@ TDBG_META_TIMESTAMP
Definition: gsttensor_debug.h:77
DEFAULT_TENSOR_DEBUG_CAP
#define DEFAULT_TENSOR_DEBUG_CAP
Definition: gsttensor_debug.c:161
TRUE
return TRUE
Definition: gsttensor_if.c:897
UNUSED
#define UNUSED(expr)
Definition: mqttcommon.h:19
TDBG_OUTPUT_GSTDBG_W
@ TDBG_OUTPUT_GSTDBG_W
Definition: gsttensor_debug.h:54
nnstreamer_util.h
Optional NNStreamer utility functions for sub-plugin writers and users.
C_FLAGS
#define C_FLAGS(v)
Definition: gsttensor_debug.c:88
TDBG_CAP_SHOW_ALWAYS
@ TDBG_CAP_SHOW_ALWAYS
Definition: gsttensor_debug.h:68
PROP_SILENT
@ PROP_SILENT
Definition: gsttensor_debug.c:82
_gst_tensor_debug_output
static void _gst_tensor_debug_output(GstTensorDebug *self, GstBuffer *buffer)
The core function that provides debug output based on the contents.
Definition: gsttensor_debug.c:397
TDBG_CAP_SHOW_UPDATE
@ TDBG_CAP_SHOW_UPDATE
Definition: gsttensor_debug.h:66
G_DEFINE_TYPE
G_DEFINE_TYPE(GstTensorDebug, gst_tensor_debug, GST_TYPE_BASE_TRANSFORM)
TDBG_OUTPUT_CONSOLE_E
@ TDBG_OUTPUT_CONSOLE_E
Definition: gsttensor_debug.h:52
_GstTensorDebugClass
GstTensorDebugClass data structure.
Definition: gsttensor_debug.h:101
src_factory
static GstStaticPadTemplate src_factory
The capabilities of the outputs.
Definition: gsttensor_debug.c:71
GST_DEBUG_CATEGORY_STATIC
GST_DEBUG_CATEGORY_STATIC(gst_tensor_debug_debug)
TDBG_OUTPUT_GSTDBG_I
@ TDBG_OUTPUT_GSTDBG_I
Definition: gsttensor_debug.h:53
TENSOR_DEBUG_TYPE_META_FLAGS
#define TENSOR_DEBUG_TYPE_META_FLAGS
Definition: gsttensor_debug.c:163
TDBG_META_QUERYSERVER
@ TDBG_META_QUERYSERVER
Definition: gsttensor_debug.h:78
DEFAULT_TENSOR_DEBUG_OUTPUT_FLAGS
#define DEFAULT_TENSOR_DEBUG_OUTPUT_FLAGS
Definition: gsttensor_debug.c:135
PROP_META
@ PROP_META
Definition: gsttensor_debug.c:85
gst_tensor_debug_get_property
static void gst_tensor_debug_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
Getter for tensor_debug properties.
Definition: gsttensor_debug.c:368
DEFAULT_SILENT
#define DEFAULT_SILENT
Flag to print minimized log.
Definition: gsttensor_debug.c:191
tensor_debug_meta_flags_get_type
static GType tensor_debug_meta_flags_get_type(void)
Flags for meta_mode of GstTensorDebug.
Definition: gsttensor_debug.c:168
type
svtc_1 type
Definition: gsttensor_if.c:843
PROP_0
@ PROP_0
Definition: gsttensor_debug.c:81
PROP_CAP
@ PROP_CAP
Definition: gsttensor_debug.c:84
gst_tensor_debug_init
static void gst_tensor_debug_init(GstTensorDebug *self)
Initialize tensor_debug element.
Definition: gsttensor_debug.c:313
gst_tensor_debug_transform_ip
static GstFlowReturn gst_tensor_debug_transform_ip(GstBaseTransform *trans, GstBuffer *buffer)
in-place transform
Definition: gsttensor_debug.c:408
TDBG_OUTPUT_CONSOLE_I
@ TDBG_OUTPUT_CONSOLE_I
Definition: gsttensor_debug.h:50