Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions gst_client/gst_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ static GstdClientCmd cmds[] = {
"Enable/Disable debug threshold reset",
"debug_reset <reset>"},

{"stats_enable", gstd_client_cmd_socket,
"Enables/Disables stats collection",
"stats_enable <enable>"},

{"stats_get", gstd_client_cmd_socket,
"Gets stats collected",
"stats_get"},

{"stats_reset", gstd_client_cmd_socket,
"Resets stats inner state",
"stats_reset"},

{NULL}
};

Expand Down
52 changes: 52 additions & 0 deletions libgstc/c/libgstc.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
#define PIPELINE_SIGNAL_TIMEOUT_FORMAT "/pipelines/%s/elements/%s/signals/%s/timeout"
#define PIPELINE_SIGNAL_DISCONNECT_FORMAT "/pipelines/%s/elements/%s/signals/%s/disconnect"

#define STATS_ENABLE_FORMAT "stats_enable %s"
#define STATS_GET_FORMAT "stats_get"
#define STATS_RESET_FORMAT "stats_reset"
#define SEEK_FORMAT "seek %f %d %d %d %lld %d %lld"
#define FLUSH_STOP_FORMAT "flush_stop %s"
#define TIMEOUT_FORMAT "%lli"
Expand Down Expand Up @@ -1232,3 +1235,52 @@ gstc_pipeline_signal_disconnect (GstClient * client, const char *pipeline_name,
return ret;

}

GstcStatus
gstc_enable_stats (GstClient * client, const int enable)
{
GstcStatus ret;
char *request;
int asprintf_ret;
const char *enable_bool;

gstc_assert_and_ret_val (NULL != client, GSTC_NULL_ARGUMENT);

enable_bool = enable == 0 ? "false" : "true";
asprintf_ret = asprintf (&request, STATS_ENABLE_FORMAT, enable_bool);
if (PRINTF_ERROR == asprintf_ret) {
return GSTC_OOM;
}
ret = gstc_cmd_send (client, request);

free (request);

return ret;
}

GstcStatus
gstc_get_stats (GstClient * client, char **response)
{
GstcStatus ret;

gstc_assert_and_ret_val (NULL != client, GSTC_NULL_ARGUMENT);
gstc_assert_and_ret_val (NULL != response, GSTC_NULL_ARGUMENT);

ret =
gstc_cmd_send_get_response (client, STATS_GET_FORMAT, response,
client->timeout);

return ret;
}

GstcStatus
gstc_reset_stats (GstClient * client)
{
GstcStatus ret;

gstc_assert_and_ret_val (NULL != client, GSTC_NULL_ARGUMENT);

ret = gstc_cmd_send (client, STATS_RESET_FORMAT);

return ret;
}
46 changes: 41 additions & 5 deletions libgstc/c/libgstc.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ GstcStatus gstc_client_ping(GstClient *client);
* @threshold: the debug level takes a keyword and the debug level in the argument
* recieving 0 as a level is equivalent to disabling debug
* @colors: if non-zero ANSI color control escape sequences will be included in the debug output
* @reset: if non-zero the debug threshold will be cleared each time, otherwise threshold
* @reset: if non-zero the debug threshold will be cleared each time, otherwise threshold
* is appended to previous threshold.
*
* Controls amount of GStreamer Daemon debug logging. Typically the GStreamer Daemon debug log output is directed to the system log file.
Expand Down Expand Up @@ -398,7 +398,7 @@ GstcStatus gstc_element_get (GstClient *client, const char *pname,
*/
GstcStatus gstc_element_set(GstClient *client, const char *pname,
const char *element, const char *parameter, const char *format, ...);

/**
* gstc_element_properties_list:
* @client: The client returned by gstc_client_new()
Expand Down Expand Up @@ -530,7 +530,7 @@ GstcStatus gstc_pipeline_list_elements(GstClient *client, const char *pipeline_n
* @timeout: The amount of nanoseconds to wait for the event, or -1
* for unlimited
* @user_data: (allow none): A placeholder for custom data
*
*
* The callback signature of the function to be registered in
* gst_pipeline_bus_wait_async().
*
Expand All @@ -551,7 +551,7 @@ typedef GstcStatus
* @callback: The function to be called when the message (or timeout)
* is received on the bus.
* @user_data: (allow none): A placeholder for custom data
*
*
* Register a callback function to be called when a specific message
* is received on the bus or a timeout ocurred.
*
Expand All @@ -570,7 +570,7 @@ gstc_pipeline_bus_wait_async (GstClient *client,
* @message_name: The type of message to receive
* @timeout: The amount of nanoseconds to wait for the event, or -1
* for unlimited
*
*
* Block until a message of type @message_name is received in the bus
* or a timeout occurs.
*
Expand Down Expand Up @@ -666,6 +666,42 @@ GstcStatus gstc_pipeline_emit_action (GstClient *client,
const char *pipeline_name, const char *element,
const char *action);

/**
* gstc_enable_stats:
* @client: The client returned by gstc_client_new()
* @enable: If nonzero, then stats are enabled, if zero stats are disabled
*
* Enables or disables stats collection in the daemon
*
* Returns: GstcStatus indicating success, daemon unreachable, daemon
* timeout
*/
GstcStatus gstc_enable_stats (GstClient *client, const int enable);

/**
* gstc_get_stats:
* @client: The client returned by gstc_client_new()
* @response: Pointer to output string memory representing a stats value,
* this memory should be freed by the user.
*
* Attempts to get a stats value from gstd
*
* Returns: GstcStatus indicating success, daemon unreachable, daemon
* timeout
*/
GstcStatus gstc_get_stats (GstClient *client, char **response);

/**
* gstc_reset_stats:
* @client: The client returned by gstc_client_new()
*
* Resets the stats state of the current gstd session
*
* Returns: GstcStatus indicating success, daemon unreachable, daemon
* timeout
*/
GstcStatus gstc_reset_stats (GstClient *client);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions libgstd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ libgstd_@GSTD_API_VERSION@_la_SOURCES = \
gstd_signal_reader.c \
gstd_socket.c \
gstd_state.c \
gstd_stats.c \
gstd_tcp.c \
gstd_unix.c \
libgstd.c
Expand Down Expand Up @@ -134,5 +135,6 @@ noinst_HEADERS = \
gstd_signal_reader.h \
gstd_socket.h \
gstd_state.h \
gstd_stats.h \
gstd_tcp.h \
gstd_unix.h
61 changes: 61 additions & 0 deletions libgstd/gstd_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ static GstdReturnCode gstd_parser_debug_color (GstdSession *, gchar *, gchar *,
gchar **);
static GstdReturnCode gstd_parser_debug_reset (GstdSession *, gchar *, gchar *,
gchar **);
static GstdReturnCode gstd_parser_stats_enable (GstdSession *, gchar *,
gchar *, gchar **);
static GstdReturnCode gstd_parser_stats_get (GstdSession *, gchar *,
gchar *, gchar **);
static GstdReturnCode gstd_parser_stats_reset (GstdSession *, gchar *,
gchar *, gchar **);
static GstdReturnCode gstd_parser_pipeline_create_ref (GstdSession *, gchar *,
gchar *, gchar **);
static GstdReturnCode gstd_parser_pipeline_delete_ref (GstdSession *, gchar *,
Expand Down Expand Up @@ -159,6 +165,10 @@ static GstdCmd cmds[] = {
{"debug_color", gstd_parser_debug_color},
{"debug_reset", gstd_parser_debug_reset},

{"stats_enable", gstd_parser_stats_enable},
{"stats_get", gstd_parser_stats_get},
{"stats_reset", gstd_parser_stats_reset},

{"pipeline_create_ref", gstd_parser_pipeline_create_ref},
{"pipeline_delete_ref", gstd_parser_pipeline_delete_ref},
{"pipeline_play_ref", gstd_parser_pipeline_play_ref},
Expand Down Expand Up @@ -871,6 +881,57 @@ gstd_parser_debug_reset (GstdSession * session, gchar * action, gchar * reset,
return ret;
}

static GstdReturnCode
gstd_parser_stats_enable (GstdSession * session, gchar * action,
gchar * enabled, gchar ** response)
{
GstdReturnCode ret;
gchar *uri;

g_return_val_if_fail (GSTD_IS_SESSION (session), GSTD_NULL_ARGUMENT);
g_return_val_if_fail (response, GSTD_NULL_ARGUMENT);

check_argument (enabled, GSTD_BAD_COMMAND);

uri = g_strdup_printf ("/stats/enable %s", enabled);
ret = gstd_parser_parse_raw_cmd (session, (gchar *) "update", uri, response);

g_free (uri);

return ret;
}

static GstdReturnCode
gstd_parser_stats_get (GstdSession * session, gchar * action, gchar * args,
gchar ** response)
{
GstdReturnCode ret;
gchar *uri;

g_return_val_if_fail (GSTD_IS_SESSION (session), GSTD_NULL_ARGUMENT);

uri = g_strdup_printf ("/stats/stats");
ret = gstd_parser_parse_raw_cmd (session, (gchar *) "read", uri, response);
g_free (uri);

return ret;
}

static GstdReturnCode
gstd_parser_stats_reset (GstdSession * session, gchar * action, gchar * args,
gchar ** response)
{
GstdReturnCode ret;
gchar *uri;

g_return_val_if_fail (GSTD_IS_SESSION (session), GSTD_NULL_ARGUMENT);

uri = g_strdup_printf ("/stats/reset");
ret = gstd_parser_parse_raw_cmd (session, (gchar *) "read", uri, response);
g_free (uri);

return ret;
}

static GstdReturnCode
gstd_parser_signal_connect (GstdSession * session, gchar * action,
Expand Down
25 changes: 23 additions & 2 deletions libgstd/gstd_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum
PROP_PIPELINES = 1,
PROP_PID,
PROP_DEBUG,
PROP_STATS,
N_PROPERTIES // NOT A PROPERTY
};

Expand Down Expand Up @@ -120,6 +121,12 @@ gstd_session_class_init (GstdSessionClass * klass)
"The debug object containing debug information",
GSTD_TYPE_DEBUG, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

properties[PROP_STATS] =
g_param_spec_object ("stats",
"Stats",
"The stats object containing tracers information",
GSTD_TYPE_STATS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

g_object_class_install_properties (object_class, N_PROPERTIES, properties);

/* Initialize debug category with nice colors */
Expand Down Expand Up @@ -154,6 +161,9 @@ gstd_session_init (GstdSession * self)
self->debug =
GSTD_DEBUG (g_object_new (GSTD_TYPE_DEBUG, "name", "Debug", NULL));

self->stats =
GSTD_STATS (g_object_new (GSTD_TYPE_STATS, "name", "Stats", NULL));

self->pid = (GPid) getpid ();
}

Expand All @@ -176,7 +186,10 @@ gstd_session_get_property (GObject * object,
GST_DEBUG_OBJECT (self, "Returning debug object %p", self->debug);
g_value_set_object (value, self->debug);
break;

case PROP_STATS:
GST_DEBUG_OBJECT (self, "Returning stats object %p", self->stats);
g_value_set_object (value, self->stats);
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
Expand All @@ -199,7 +212,10 @@ gstd_session_set_property (GObject * object,
self->debug = g_value_dup_object (value);
GST_DEBUG_OBJECT (self, "Changing debug object to %p", self->debug);
break;

case PROP_STATS:
self->stats = g_value_dup_object (value);
GST_DEBUG_OBJECT (self, "Changing stats object to %p", self->stats);
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
Expand All @@ -224,6 +240,11 @@ gstd_session_dispose (GObject * object)
self->debug = NULL;
}

if (self->stats) {
g_object_unref (self->stats);
self->stats = NULL;
}

G_OBJECT_CLASS (gstd_session_parent_class)->dispose (object);
}

Expand Down
6 changes: 6 additions & 0 deletions libgstd/gstd_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
#include "gstd_pipeline.h"
#include "gstd_list.h"
#include "gstd_debug.h"
#include "gstd_stats.h"

G_BEGIN_DECLS
#define GSTD_TYPE_SESSION \
Expand Down Expand Up @@ -211,6 +212,11 @@ struct _GstdSession
* Object containing debug options
*/
GstdDebug *debug;

/*
* Object containing stats options
*/
GstdStats *stats;
};

struct _GstdSessionClass
Expand Down
Loading