Blame tests/benchmarks/tracerserialize.c

Packit a6ee4b
/* GStreamer
Packit a6ee4b
 * Copyright (C) 2016 Stefan Sauer <ensonic@users.sf.net>
Packit a6ee4b
 *
Packit a6ee4b
 * tracerserialize.c: benchmark for log serialisation
Packit a6ee4b
 *
Packit a6ee4b
 * This library is free software; you can redistribute it and/or
Packit a6ee4b
 * modify it under the terms of the GNU Library General Public
Packit a6ee4b
 * License as published by the Free Software Foundation; either
Packit a6ee4b
 * version 2 of the License, or (at your option) any later version.
Packit a6ee4b
 *
Packit a6ee4b
 * This library is distributed in the hope that it will be useful,
Packit a6ee4b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a6ee4b
 * MERCHANTABILITY or FITcreating %d capsNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a6ee4b
 * Library General Public License for more details.
Packit a6ee4b
 *
Packit a6ee4b
 * You should have received a copy of the GNU Library General Public
Packit a6ee4b
 * License along with this library; if not, write to the
Packit a6ee4b
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit a6ee4b
 * Boston, MA 02110-1301, USA.
Packit a6ee4b
 */
Packit a6ee4b
Packit a6ee4b
/* to check the sizes run:
Packit a6ee4b
 *
Packit a6ee4b
 * GST_DEBUG="default:7" GST_DEBUG_FILE=trace.log ./tracerserialize
Packit a6ee4b
 *
Packit a6ee4b
 * grep "log_gst_structure" trace.log >tracerserialize.gststructure.log
Packit a6ee4b
 * grep "log_g_variant" trace.log >tracerserialize.gvariant.log
Packit a6ee4b
 *
Packit a6ee4b
 */
Packit a6ee4b
Packit a6ee4b
#include <gst/gst.h>
Packit a6ee4b
Packit a6ee4b
#define NUM_LOOPS 100000
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
log_gst_structure (const gchar * name, const gchar * first, ...)
Packit a6ee4b
{
Packit a6ee4b
  va_list var_args;
Packit a6ee4b
  GstStructure *s;
Packit a6ee4b
  gchar *l;
Packit a6ee4b
Packit a6ee4b
  va_start (var_args, first);
Packit a6ee4b
  s = gst_structure_new_valist (name, first, var_args);
Packit a6ee4b
  l = gst_structure_to_string (s);
Packit a6ee4b
  GST_TRACE ("%s", l);
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_structure_free (s);
Packit a6ee4b
  va_end (var_args);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
log_gst_structure_tmpl (const gchar * format, ...)
Packit a6ee4b
{
Packit a6ee4b
  va_list var_args;
Packit a6ee4b
Packit a6ee4b
  va_start (var_args, format);
Packit a6ee4b
  if (G_LIKELY (GST_LEVEL_TRACE <= _gst_debug_min)) {
Packit a6ee4b
    gst_debug_log_valist (GST_CAT_DEFAULT, GST_LEVEL_TRACE, __FILE__,
Packit a6ee4b
        GST_FUNCTION, __LINE__, NULL, format, var_args);
Packit a6ee4b
  }
Packit a6ee4b
  va_end (var_args);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
log_g_variant (const gchar * format, ...)
Packit a6ee4b
{
Packit a6ee4b
  va_list var_args;
Packit a6ee4b
  GVariant *v;
Packit a6ee4b
  gchar *l;
Packit a6ee4b
Packit a6ee4b
  va_start (var_args, format);
Packit a6ee4b
  v = g_variant_new_va (format, NULL, &var_args);
Packit a6ee4b
  l = g_variant_print (v, FALSE);
Packit a6ee4b
  GST_TRACE ("%s", l);
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  g_variant_unref (v);
Packit a6ee4b
  va_end (var_args);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
gint
Packit a6ee4b
main (gint argc, gchar * argv[])
Packit a6ee4b
{
Packit a6ee4b
  GstClockTime start, end;
Packit a6ee4b
  gint i;
Packit a6ee4b
Packit a6ee4b
  gst_init (&argc, &argv);
Packit a6ee4b
Packit a6ee4b
  start = gst_util_get_timestamp ();
Packit a6ee4b
  for (i = 0; i < NUM_LOOPS; i++) {
Packit a6ee4b
    log_gst_structure ("name",
Packit a6ee4b
        "ts", G_TYPE_UINT64, (guint64) 0,
Packit a6ee4b
        "index", G_TYPE_UINT, 10,
Packit a6ee4b
        "test", G_TYPE_STRING, "hallo",
Packit a6ee4b
        "bool", G_TYPE_BOOLEAN, TRUE,
Packit a6ee4b
        "flag", GST_TYPE_PAD_DIRECTION, GST_PAD_SRC, NULL);
Packit a6ee4b
  }
Packit a6ee4b
  end = gst_util_get_timestamp ();
Packit a6ee4b
  g_print ("%" GST_TIME_FORMAT ": GstStructure\n", GST_TIME_ARGS (end - start));
Packit a6ee4b
Packit a6ee4b
  start = gst_util_get_timestamp ();
Packit a6ee4b
  for (i = 0; i < NUM_LOOPS; i++) {
Packit a6ee4b
    log_gst_structure_tmpl ("name, ts=(guint64)%" G_GUINT64_FORMAT
Packit a6ee4b
        ", index=(uint)%u, test=(string)%s, bool=(boolean)%s, flag=(GstPadDirection)%d;",
Packit a6ee4b
        (guint64) 0, 10, "hallo", (TRUE ? "true" : "false"), GST_PAD_SRC);
Packit a6ee4b
  }
Packit a6ee4b
  end = gst_util_get_timestamp ();
Packit a6ee4b
  g_print ("%" GST_TIME_FORMAT ": GstStructure template\n",
Packit a6ee4b
      GST_TIME_ARGS (end - start));
Packit a6ee4b
Packit a6ee4b
  start = gst_util_get_timestamp ();
Packit a6ee4b
  for (i = 0; i < NUM_LOOPS; i++) {
Packit a6ee4b
    log_g_variant ("(stusbu)", "name", (guint64) 0, 10, "hallo", TRUE,
Packit a6ee4b
        GST_PAD_SRC);
Packit a6ee4b
  }
Packit a6ee4b
  end = gst_util_get_timestamp ();
Packit a6ee4b
  g_print ("%" GST_TIME_FORMAT ": GVariant\n", GST_TIME_ARGS (end - start));
Packit a6ee4b
Packit a6ee4b
  return 0;
Packit a6ee4b
}