-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented gsttracy and added tracing to gst_wayland_display
- Loading branch information
Showing
7 changed files
with
195 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include "gsttracy.hpp" | ||
#include <cstring> | ||
#include <helpers/logger.hpp> | ||
#include <map> | ||
#include <optional> | ||
#include <string> | ||
#include <tracy/TracyC.h> | ||
|
||
GST_DEBUG_CATEGORY_STATIC(gst_tracy_debug); | ||
#define GST_CAT_DEFAULT gst_tracy_debug | ||
|
||
thread_local std::map<std::string, TracyCZoneCtx> zones; | ||
|
||
G_DEFINE_TYPE(GstTracyTracer, gst_tracy_tracer, GST_TYPE_TRACER); | ||
|
||
static void gst_tracy_tracer_class_init(GstTracyTracerClass *klass) { | ||
GObjectClass *oclass = G_OBJECT_CLASS(klass); | ||
|
||
GST_DEBUG_CATEGORY_INIT(gst_tracy_debug, "tracytracer", 0, "base tracy tracer"); | ||
} | ||
|
||
GstPad *get_source_pad(GstPad *pad) { | ||
while (pad) { | ||
if (GST_IS_GHOST_PAD(pad)) { | ||
pad = gst_ghost_pad_get_target(GST_GHOST_PAD(pad)); | ||
} else if (GST_OBJECT_PARENT(pad) && GST_IS_GHOST_PAD(GST_OBJECT_PARENT(pad))) { | ||
pad = GST_PAD_PEER(GST_OBJECT_PARENT(pad)); | ||
} else { | ||
break; | ||
} | ||
} | ||
return pad; | ||
} | ||
|
||
static GstElement *get_real_pad_parent(GstPad *pad) { | ||
GstObject *parent; | ||
|
||
if (!pad) | ||
return NULL; | ||
|
||
parent = GST_OBJECT_PARENT(pad); | ||
|
||
/* if parent of pad is a ghost-pad, then pad is a proxy_pad */ | ||
if (parent && GST_IS_GHOST_PAD(parent)) { | ||
pad = GST_PAD_CAST(parent); | ||
parent = GST_OBJECT_PARENT(pad); | ||
} | ||
return GST_ELEMENT_CAST(parent); | ||
} | ||
|
||
static std::optional<std::string> get_unique_name(GstPad *sender_pad) { | ||
if (GST_IS_GHOST_PAD(sender_pad)) | ||
return {}; | ||
|
||
GstPad *receiver_pad = GST_PAD_PEER(sender_pad); | ||
if (GST_IS_GHOST_PAD(receiver_pad)) | ||
return {}; | ||
|
||
receiver_pad = get_source_pad(receiver_pad); | ||
sender_pad = get_source_pad(sender_pad); | ||
GstElement *sender_element = get_real_pad_parent(sender_pad); | ||
GstElement *receiver_element = GST_PAD_PARENT(receiver_pad); | ||
|
||
return gst_element_get_name(sender_element) + std::string("->") + gst_element_get_name(receiver_element); | ||
} | ||
|
||
static void trace_pad_push_pre(GObject *self, GstClockTime ts, GstPad *sender_pad, GstBuffer *buffer) { | ||
if (auto unique_name = get_unique_name(sender_pad)) { | ||
TracyCZone(zone, true); | ||
TracyCZoneText(zone, unique_name->c_str(), unique_name->length()); | ||
zones[*unique_name] = zone; | ||
} | ||
} | ||
|
||
static void | ||
trace_pad_push_list_pre(GObject *self, G_GNUC_UNUSED GstClockTime ts, GstPad *sender_pad, GstBufferList *list) { | ||
if (auto unique_name = get_unique_name(sender_pad)) { | ||
TracyCZone(zone, true); | ||
TracyCZoneText(zone, unique_name->c_str(), unique_name->length()); | ||
zones[*unique_name] = zone; | ||
} | ||
} | ||
|
||
static void trace_pad_push_post(GObject *self, G_GNUC_UNUSED GstClockTime ts, GstPad *sender_pad, GstBuffer *buffer) { | ||
if (auto unique_name = get_unique_name(sender_pad)) { | ||
if (auto zone = zones.find(*unique_name); zone != zones.end()) { | ||
TracyCZoneEnd(zone->second); | ||
zones.erase(zone); | ||
} else { | ||
logs::log(logs::warning, "Zone not found for {}", *unique_name); | ||
} | ||
} | ||
} | ||
|
||
static void | ||
trace_pad_push_list_post(GObject *self, G_GNUC_UNUSED GstClockTime ts, GstPad *sender_pad, GstBufferList *list) { | ||
if (auto unique_name = get_unique_name(sender_pad)) { | ||
if (auto zone = zones.find(*unique_name); zone != zones.end()) { | ||
TracyCZoneEnd(zone->second); | ||
zones.erase(zone); | ||
} else { | ||
logs::log(logs::warning, "Zone not found for {}", *unique_name); | ||
} | ||
} | ||
} | ||
|
||
static void gst_tracy_tracer_init(GstTracyTracer *self) { | ||
GstTracer *tracer = GST_TRACER(self); | ||
|
||
gst_tracing_register_hook(tracer, "pad-push-pre", G_CALLBACK(trace_pad_push_pre)); | ||
gst_tracing_register_hook(tracer, "pad-push-list-pre", G_CALLBACK(trace_pad_push_list_pre)); | ||
gst_tracing_register_hook(tracer, "pad-push-post", G_CALLBACK(trace_pad_push_post)); | ||
gst_tracing_register_hook(tracer, "pad-push-list-post", G_CALLBACK(trace_pad_push_list_post)); | ||
} | ||
|
||
static gboolean plugin_init(GstPlugin *plugin) { | ||
if (!gst_tracer_register(plugin, "gsttracy", gst_tracy_tracer_get_type())) | ||
return FALSE; | ||
return TRUE; | ||
} | ||
|
||
#ifndef VERSION | ||
#define VERSION "0.0.FIXME" | ||
#endif | ||
#ifndef PACKAGE | ||
#define PACKAGE "FIXME_package" | ||
#endif | ||
#ifndef PACKAGE_NAME | ||
#define PACKAGE_NAME "FIXME_package_name" | ||
#endif | ||
#ifndef GST_PACKAGE_ORIGIN | ||
#define GST_PACKAGE_ORIGIN "http://FIXME.org/" | ||
#endif | ||
|
||
GST_PLUGIN_DEFINE(GST_VERSION_MAJOR, | ||
GST_VERSION_MINOR, | ||
gsttracy, | ||
"FIXME plugin description", | ||
plugin_init, | ||
VERSION, | ||
"LGPL", | ||
PACKAGE_NAME, | ||
GST_PACKAGE_ORIGIN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef WOLF_GSTTRACY_HPP | ||
#define WOLF_GSTTRACY_HPP | ||
|
||
#include <gst/gst.h> | ||
#include <gst/gsttracer.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define GST_TYPE_TRACY_TRACER (gst_tracy_tracer_get_type ()) | ||
G_DECLARE_DERIVABLE_TYPE (GstTracyTracer, gst_tracy_tracer, GST_TRACY, TRACER, GstTracer) | ||
|
||
struct _GstTracyTracerClass { | ||
GstTracerClass parent_class; | ||
}; | ||
|
||
GType gst_tracy_tracer_get_type(void); | ||
|
||
G_END_DECLS | ||
|
||
#endif // WOLF_GSTTRACY_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters