2 * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
4 * gst-stats.c: statistics tracing front end
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
33 static GRegex *raw_log = NULL;
34 static GRegex *ansi_log = NULL;
36 /* global statistics */
37 static GHashTable *threads = NULL;
38 static GPtrArray *elements = NULL;
39 static GPtrArray *pads = NULL;
40 static guint64 num_buffers = 0, num_events = 0, num_messages = 0, num_queries =
42 static guint num_elements = 0, num_bins = 0, num_pads = 0, num_ghostpads = 0;
43 static GstClockTime last_ts = G_GUINT64_CONSTANT (0);
44 static GstClockTime tproc = G_GUINT64_CONSTANT (0);
48 /* human readable pad name and details */
49 gchar *name, *type_name;
51 gboolean is_ghost_pad;
53 /* buffer statistics */
55 guint num_live, num_decode_only, num_discont, num_resync, num_corrupted,
56 num_marker, num_header, num_gap, num_droppable, num_delta;
57 guint min_size, max_size, avg_size;
58 /* first and last activity on the pad, expected next_ts */
59 GstClockTime first_ts, last_ts, next_ts;
60 /* in which thread does it operate */
68 /* human readable element name */
69 gchar *name, *type_name;
72 /* buffer statistics */
73 guint recv_buffers, sent_buffers;
74 guint64 recv_bytes, sent_bytes;
75 /* event, message statistics */
76 guint num_events, num_messages, num_queries;
77 /* first activity on the element */
78 GstClockTime first_ts, last_ts;
79 /* time spend in this element */
87 /* time spend in this thread */
94 free_element_stats (gpointer data)
96 g_slice_free (GstElementStats, data);
99 static inline GstElementStats *
100 get_element_stats (guint ix)
102 return (ix != G_MAXUINT) ? g_ptr_array_index (elements, ix) : NULL;
105 static inline GstPadStats *
106 get_pad_stats (guint ix)
108 return (ix != G_MAXUINT) ? g_ptr_array_index (pads, ix) : NULL;
112 free_pad_stats (gpointer data)
114 g_slice_free (GstPadStats, data);
117 static inline GstThreadStats *
118 get_thread_stats (guint id)
120 GstThreadStats *stats = g_hash_table_lookup (threads, GUINT_TO_POINTER (id));
122 if (G_UNLIKELY (!stats)) {
123 stats = g_slice_new0 (GstThreadStats);
124 g_hash_table_insert (threads, GUINT_TO_POINTER (id), stats);
130 new_pad_stats (GstStructure * s)
135 gboolean is_ghost_pad;
139 gst_structure_get (s,
140 "ix", G_TYPE_UINT, &ix,
141 "parent-ix", G_TYPE_UINT, &parent_ix,
142 "name", G_TYPE_STRING, &name,
143 "type", G_TYPE_STRING, &type,
144 "is-ghostpad", G_TYPE_BOOLEAN, &is_ghost_pad,
145 "pad-direction", GST_TYPE_PAD_DIRECTION, &dir,
146 "thread-id", G_TYPE_UINT, &thread_id, NULL);
148 stats = g_slice_new0 (GstPadStats);
153 stats->type_name = type;
155 stats->is_ghost_pad = is_ghost_pad;
157 stats->min_size = G_MAXUINT;
158 stats->first_ts = stats->last_ts = stats->next_ts = GST_CLOCK_TIME_NONE;
159 stats->thread_id = thread_id;
160 stats->parent_ix = parent_ix;
163 g_ptr_array_set_size (pads, ix + 1);
164 g_ptr_array_index (pads, ix) = stats;
168 new_element_stats (GstStructure * s)
170 GstElementStats *stats;
175 gst_structure_get (s,
176 "ix", G_TYPE_UINT, &ix,
177 "parent-ix", G_TYPE_UINT, &parent_ix,
178 "name", G_TYPE_STRING, &name,
179 "type", G_TYPE_STRING, &type, "is-bin", G_TYPE_BOOLEAN, &is_bin, NULL);
181 stats = g_slice_new0 (GstElementStats);
187 stats->type_name = type;
188 stats->is_bin = is_bin;
189 stats->first_ts = GST_CLOCK_TIME_NONE;
190 stats->parent_ix = parent_ix;
192 if (elements->len <= ix)
193 g_ptr_array_set_size (elements, ix + 1);
194 g_ptr_array_index (elements, ix) = stats;
198 free_thread_stats (gpointer data)
200 g_slice_free (GstThreadStats, data);
204 do_pad_stats (GstPadStats * stats, guint elem_ix, guint size, guint64 ts,
205 guint64 buffer_ts, guint64 buffer_dur, GstBufferFlags buffer_flags)
210 if (stats->parent_ix == G_MAXUINT) {
211 stats->parent_ix = elem_ix;
214 if (stats->thread_id) {
215 get_thread_stats (stats->thread_id);
219 avg_size = (((gulong) stats->avg_size * (gulong) stats->num_buffers) + size);
220 stats->num_buffers++;
221 stats->avg_size = (guint) (avg_size / stats->num_buffers);
222 if (size < stats->min_size)
223 stats->min_size = size;
224 else if (size > stats->max_size)
225 stats->max_size = size;
227 if (!GST_CLOCK_TIME_IS_VALID (stats->last_ts))
228 stats->first_ts = ts;
231 if (buffer_flags & GST_BUFFER_FLAG_LIVE)
233 if (buffer_flags & GST_BUFFER_FLAG_DECODE_ONLY)
234 stats->num_decode_only++;
235 if (buffer_flags & GST_BUFFER_FLAG_DISCONT)
236 stats->num_discont++;
237 if (buffer_flags & GST_BUFFER_FLAG_RESYNC)
239 if (buffer_flags & GST_BUFFER_FLAG_CORRUPTED)
240 stats->num_corrupted++;
241 if (buffer_flags & GST_BUFFER_FLAG_MARKER)
243 if (buffer_flags & GST_BUFFER_FLAG_HEADER)
245 if (buffer_flags & GST_BUFFER_FLAG_GAP)
247 if (buffer_flags & GST_BUFFER_FLAG_DROPPABLE)
248 stats->num_droppable++;
249 if (buffer_flags & GST_BUFFER_FLAG_DELTA_UNIT)
251 /* update timestamps */
252 if (GST_CLOCK_TIME_IS_VALID (buffer_ts) &&
253 GST_CLOCK_TIME_IS_VALID (buffer_dur)) {
254 stats->next_ts = buffer_ts + buffer_dur;
256 stats->next_ts = GST_CLOCK_TIME_NONE;
261 do_element_stats (GstElementStats * stats, GstElementStats * peer_stats,
262 guint size, guint64 ts)
264 stats->sent_buffers++;
265 peer_stats->recv_buffers++;
266 stats->sent_bytes += size;
267 peer_stats->recv_bytes += size;
269 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (stats->first_ts))) {
270 stats->first_ts = ts;
272 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (peer_stats->first_ts))) {
273 peer_stats->first_ts = ts + 1;
278 do_buffer_stats (GstStructure * s)
280 guint64 ts, buffer_ts, buffer_dur;
281 guint pad_ix, elem_ix, peer_elem_ix;
283 GstBufferFlags buffer_flags;
284 GstPadStats *pad_stats;
285 GstElementStats *elem_stats, *peer_elem_stats;
288 gst_structure_get (s, "ts", G_TYPE_UINT64, &ts,
289 "pad-ix", G_TYPE_UINT, &pad_ix,
290 "elem-ix", G_TYPE_UINT, &elem_ix,
291 "peer-elem-ix", G_TYPE_UINT, &peer_elem_ix,
292 "buffer-size", G_TYPE_UINT, &size,
293 "buffer-ts", G_TYPE_UINT64, &buffer_ts,
294 "buffer-duration", G_TYPE_UINT64, &buffer_dur,
295 "buffer-flags", GST_TYPE_BUFFER_FLAGS, &buffer_flags, NULL);
296 last_ts = MAX (last_ts, ts);
297 if (!(pad_stats = get_pad_stats (pad_ix))) {
298 GST_WARNING ("no pad stats found for ix=%u", pad_ix);
301 if (!(elem_stats = get_element_stats (elem_ix))) {
302 GST_WARNING ("no element stats found for ix=%u", elem_ix);
305 if (!(peer_elem_stats = get_element_stats (peer_elem_ix))) {
306 GST_WARNING ("no element stats found for ix=%u", peer_elem_ix);
309 do_pad_stats (pad_stats, elem_ix, size, ts, buffer_ts, buffer_dur,
311 if (pad_stats->dir == GST_PAD_SRC) {
313 do_element_stats (elem_stats, peer_elem_stats, size, ts);
316 do_element_stats (peer_elem_stats, elem_stats, size, ts);
321 do_event_stats (GstStructure * s)
324 guint pad_ix, elem_ix;
325 GstPadStats *pad_stats;
326 GstElementStats *elem_stats;
329 gst_structure_get (s, "ts", G_TYPE_UINT64, &ts,
330 "pad-ix", G_TYPE_UINT, &pad_ix, "elem-ix", G_TYPE_UINT, &elem_ix, NULL);
331 last_ts = MAX (last_ts, ts);
332 if (!(pad_stats = get_pad_stats (pad_ix))) {
333 GST_WARNING ("no pad stats found for ix=%u", pad_ix);
336 if (!(elem_stats = get_element_stats (elem_ix))) {
337 // e.g. reconfigure events are send over unparented pads
338 GST_INFO ("no element stats found for ix=%u", elem_ix);
341 elem_stats->num_events++;
345 do_message_stats (GstStructure * s)
349 GstElementStats *elem_stats;
352 gst_structure_get (s, "ts", G_TYPE_UINT64, &ts,
353 "elem-ix", G_TYPE_UINT, &elem_ix, NULL);
354 last_ts = MAX (last_ts, ts);
355 if (!(elem_stats = get_element_stats (elem_ix))) {
356 GST_WARNING ("no element stats found for ix=%u", elem_ix);
359 elem_stats->num_messages++;
363 do_query_stats (GstStructure * s)
367 GstElementStats *elem_stats;
370 gst_structure_get (s, "ts", G_TYPE_UINT64, &ts,
371 "elem-ix", G_TYPE_UINT, &elem_ix, NULL);
372 last_ts = MAX (last_ts, ts);
373 if (!(elem_stats = get_element_stats (elem_ix))) {
374 GST_WARNING ("no element stats found for ix=%u", elem_ix);
377 elem_stats->num_queries++;
381 do_rusage_stats (GstStructure * s)
385 GstThreadStats *thread_stats;
387 gst_structure_get (s, "ts", G_TYPE_UINT64, &ts,
388 "thread-id", G_TYPE_UINT, &thread_id,
389 "thread-time", G_TYPE_UINT64, &tthread,
390 "proc-time", G_TYPE_UINT64, &tproc, NULL);
391 thread_stats = get_thread_stats (thread_id);
392 thread_stats->tthread = tthread;
393 last_ts = MAX (last_ts, ts);
399 find_pad_stats_for_thread (gconstpointer value, gconstpointer user_data)
401 const GstPadStats *stats = (const GstPadStats *) value;
403 if ((stats->thread_id == GPOINTER_TO_UINT (user_data)) &&
404 (stats->num_buffers)) {
411 print_pad_stats (gpointer value, gpointer user_data)
413 GstPadStats *stats = (GstPadStats *) value;
415 if (stats->thread_id == GPOINTER_TO_UINT (user_data)) {
416 /* there seem to be some temporary pads */
417 if (stats->num_buffers) {
418 GstClockTimeDiff running =
419 GST_CLOCK_DIFF (stats->first_ts, stats->last_ts);
420 GstElementStats *elem_stats = get_element_stats (stats->parent_ix);
421 gchar fullname[30 + 1];
423 g_snprintf (fullname, 30, "%s.%s", elem_stats->name, stats->name);
426 (" %c %-30.30s: buffers %7u (live %5u,dec %5u,dis %5u,res %5u,"
427 "cor %5u,mar %5u,hdr %5u,gap %5u,drop %5u,dlt %5u),",
428 (stats->dir == GST_PAD_SRC) ? '>' : '<', fullname, stats->num_buffers,
429 stats->num_live, stats->num_decode_only, stats->num_discont,
430 stats->num_resync, stats->num_corrupted, stats->num_marker,
431 stats->num_header, stats->num_gap, stats->num_droppable,
433 if (stats->min_size == stats->max_size) {
434 printf (" size (min/avg/max) ......./%7u/.......,", stats->avg_size);
436 printf (" size (min/avg/max) %7u/%7u/%7u,",
437 stats->min_size, stats->avg_size, stats->max_size);
439 printf (" time %" GST_TIME_FORMAT ","
441 GST_TIME_ARGS (running),
442 ((gdouble) (stats->num_buffers * stats->avg_size) * GST_SECOND) /
443 ((gdouble) running));
449 print_thread_stats (gpointer key, gpointer value, gpointer user_data)
451 GSList *list = user_data;
452 GSList *node = g_slist_find_custom (list, key, find_pad_stats_for_thread);
453 GstThreadStats *stats = (GstThreadStats *) value;
456 /* skip stats if there are no pads for that thread (e.g. a pipeline) */
461 (guint) gst_util_uint64_scale (stats->tthread, G_GINT64_CONSTANT (100),
464 printf ("Thread %p Statistics:\n", key);
465 printf (" Time: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (stats->tthread));
466 printf (" Avg CPU load: %u %%\n", cpuload);
468 puts (" Pad Statistics:");
469 g_slist_foreach (node, print_pad_stats, key);
473 print_element_stats (gpointer value, gpointer user_data)
475 GstElementStats *stats = (GstElementStats *) value;
477 /* skip temporary elements */
478 if (stats->first_ts != GST_CLOCK_TIME_NONE) {
479 gchar fullname[45 + 1];
481 g_snprintf (fullname, 45, "%s:%s", stats->type_name, stats->name);
483 printf (" %-45s:", fullname);
484 if (stats->recv_buffers)
485 printf (" buffers in/out %7u", stats->recv_buffers);
487 printf (" buffers in/out %7s", "-");
488 if (stats->sent_buffers)
489 printf ("/%7u", stats->sent_buffers);
491 printf ("/%7s", "-");
492 if (stats->recv_bytes)
493 printf (" bytes in/out %12" G_GUINT64_FORMAT, stats->recv_bytes);
495 printf (" bytes in/out %12s", "-");
496 if (stats->sent_bytes)
497 printf ("/%12" G_GUINT64_FORMAT, stats->sent_bytes);
499 printf ("/%12s", "-");
500 printf (" first activity %" GST_TIME_FORMAT ", "
501 " ev/msg/qry sent %5u/%5u/%5u\n", GST_TIME_ARGS (stats->first_ts),
502 stats->num_events, stats->num_messages, stats->num_queries);
507 accum_element_stats (gpointer value, gpointer user_data)
509 GstElementStats *stats = (GstElementStats *) value;
511 if (stats->parent_ix != G_MAXUINT) {
512 GstElementStats *parent_stats = get_element_stats (stats->parent_ix);
514 parent_stats->num_events += stats->num_events;
515 parent_stats->num_messages += stats->num_messages;
516 parent_stats->num_queries += stats->num_queries;
517 if (!GST_CLOCK_TIME_IS_VALID (parent_stats->first_ts)) {
518 parent_stats->first_ts = stats->first_ts;
519 } else if (GST_CLOCK_TIME_IS_VALID (stats->first_ts)) {
520 parent_stats->first_ts = MIN (parent_stats->first_ts, stats->first_ts);
522 if (!GST_CLOCK_TIME_IS_VALID (parent_stats->last_ts)) {
523 parent_stats->last_ts = stats->last_ts;
524 } else if (GST_CLOCK_TIME_IS_VALID (stats->last_ts)) {
525 parent_stats->last_ts = MAX (parent_stats->last_ts, stats->last_ts);
533 sort_pad_stats_by_first_activity (gconstpointer ps1, gconstpointer ps2)
535 GstPadStats *s1 = (GstPadStats *) ps1;
536 GstPadStats *s2 = (GstPadStats *) ps2;
538 gint order = GST_CLOCK_DIFF (s2->first_ts, s1->first_ts);
541 order = s1->dir - s2->dir;
547 sort_pad_stats (gpointer value, gpointer user_data)
549 GSList **list = user_data;
552 g_slist_insert_sorted (*list, value, sort_pad_stats_by_first_activity);
556 sort_element_stats_by_first_activity (gconstpointer es1, gconstpointer es2)
558 return (GST_CLOCK_DIFF (((GstElementStats *) es2)->first_ts,
559 ((GstElementStats *) es1)->first_ts));
563 sort_bin_stats (gpointer value, gpointer user_data)
565 if (((GstElementStats *) value)->is_bin) {
566 GSList **list = user_data;
569 g_slist_insert_sorted (*list, value,
570 sort_element_stats_by_first_activity);
575 sort_element_stats (gpointer value, gpointer user_data)
577 if (!(((GstElementStats *) value)->is_bin)) {
578 GSList **list = user_data;
581 g_slist_insert_sorted (*list, value,
582 sort_element_stats_by_first_activity);
587 check_bin_parent (gpointer key, gpointer value, gpointer user_data)
589 GstElementStats *stats = (GstElementStats *) value;
591 return (stats->parent_ix == GPOINTER_TO_UINT (user_data));
595 process_leaf_bins (gpointer key, gpointer value, gpointer user_data)
597 GHashTable *accum_bins = user_data;
599 /* if we find no bin that has this bin as a parent ... */
600 if (!g_hash_table_find (accum_bins, check_bin_parent, key)) {
601 /* accumulate stats to the parent and remove */
602 accum_element_stats (value, NULL);
613 /* compile the parser regexps */
614 /* 0:00:00.004925027 31586 0x1c5c600 DEBUG GST_REGISTRY gstregistry.c:463:gst_registry_add_plugin:<registry0> adding plugin 0x1c79160 for filename "/usr/lib/gstreamer-1.0/libgstxxx.so" */
615 raw_log = g_regex_new (
626 /* 6: file:line:func: */
627 "([^:]+:[0-9]+:[^:]+:)"
628 /* 7: (obj)? log-text */
629 "(.*)$", 0, 0, NULL);
631 GST_WARNING ("failed to compile the 'raw' parser");
635 ansi_log = g_regex_new (
639 "\\\e\\\[[0-9;]+m *([0-9]+)\\\e\\\[00m +"
643 "(?:\\\e\\\[[0-9;]+m)?([A-Z]+) +\\\e\\\[00m +"
645 "\\\e\\\[[0-9;]+m +([a-zA-Z_-]+) +"
646 /* 6: file:line:func: */
647 "([^:]+:[0-9]+:[^:]+:)(?:\\\e\\\[00m)?"
648 /* 7: (obj)? log-text */
649 "(.*)$", 0, 0, NULL);
651 GST_WARNING ("failed to compile the 'ansi' parser");
655 elements = g_ptr_array_new_with_free_func (free_element_stats);
656 pads = g_ptr_array_new_with_free_func (free_pad_stats);
657 threads = g_hash_table_new_full (NULL, NULL, NULL, free_thread_stats);
666 g_ptr_array_free (pads, TRUE);
668 g_ptr_array_free (elements, TRUE);
670 g_hash_table_destroy (threads);
673 g_regex_unref (raw_log);
675 g_regex_unref (ansi_log);
681 guint num_threads = g_hash_table_size (threads);
682 guint64 total_cpuload = 0;
684 /* print overall stats */
685 puts ("\nOverall Statistics:");
686 printf ("Number of Threads: %u\n", num_threads);
687 printf ("Number of Elements: %u\n", num_elements - num_bins);
688 printf ("Number of Bins: %u\n", num_bins);
689 printf ("Number of Pads: %u\n", num_pads - num_ghostpads);
690 printf ("Number of GhostPads: %u\n", num_ghostpads);
691 printf ("Number of Buffers passed: %" G_GUINT64_FORMAT "\n", num_buffers);
692 printf ("Number of Events sent: %" G_GUINT64_FORMAT "\n", num_events);
693 printf ("Number of Message sent: %" G_GUINT64_FORMAT "\n", num_messages);
694 printf ("Number of Queries sent: %" G_GUINT64_FORMAT "\n", num_queries);
695 printf ("Time: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (last_ts));
697 total_cpuload = gst_util_uint64_scale (tproc,
698 G_GINT64_CONSTANT (100), last_ts);
699 printf ("Avg CPU load: %u %%\n", (guint) total_cpuload);
707 g_ptr_array_foreach (pads, sort_pad_stats, &list);
708 g_hash_table_foreach (threads, print_thread_stats, list);
717 puts ("Element Statistics:");
718 /* sort by first_activity */
719 g_ptr_array_foreach (elements, sort_element_stats, &list);
720 /* attribute element stats to bins */
721 g_slist_foreach (list, accum_element_stats, NULL);
722 g_slist_foreach (list, print_element_stats, NULL);
731 GHashTable *accum_bins = g_hash_table_new_full (NULL, NULL, NULL, NULL);
733 puts ("Bin Statistics:");
734 /* attribute bin stats to parent-bins */
735 for (i = 0; i < num_elements; i++) {
736 GstElementStats *stats = g_ptr_array_index (elements, i);
738 g_hash_table_insert (accum_bins, GUINT_TO_POINTER (i), stats);
741 while (g_hash_table_size (accum_bins)) {
742 g_hash_table_foreach_remove (accum_bins, process_leaf_bins, accum_bins);
744 g_hash_table_destroy (accum_bins);
745 /* sort by first_activity */
746 g_ptr_array_foreach (elements, sort_bin_stats, &list);
747 g_slist_foreach (list, print_element_stats, NULL);
754 collect_stats (const gchar * filename)
758 if ((log = fopen (filename, "rt"))) {
762 if (fgets (line, 5000, log)) {
763 GMatchInfo *match_info;
769 if (strchr (line, 27)) {
771 GST_INFO ("format is 'ansi'");
774 GST_INFO ("format is 'raw'");
779 while (!feof (log)) {
780 if (fgets (line, 5000, log)) {
781 if (g_regex_match (parser, line, 0, &match_info)) {
782 /* filter by level */
783 level = g_match_info_fetch (match_info, 4);
784 if (!strcmp (level, "TRACE")) {
785 data = g_match_info_fetch (match_info, 7);
786 if ((s = gst_structure_from_string (data, NULL))) {
787 const gchar *name = gst_structure_get_name (s);
789 // TODO(ensonic): add a function for each name-id quark
790 // these function will do the actual stats tracking
791 if (!strcmp (name, "new-pad")) {
793 } else if (!strcmp (name, "new-element")) {
794 new_element_stats (s);
795 } else if (!strcmp (name, "buffer")) {
797 } else if (!strcmp (name, "event")) {
799 } else if (!strcmp (name, "message")) {
800 do_message_stats (s);
801 } else if (!strcmp (name, "query")) {
803 } else if (!strcmp (name, "rusage")) {
806 GST_WARNING ("unknown log entry: '%s'", data);
808 gst_structure_free (s);
810 GST_WARNING ("unknown log entry: '%s'", data);
815 GST_WARNING ("foreign log entry: %s:%d:'%s'", filename, lnr,
819 g_match_info_free (match_info);
824 // TODO(ensonic): run wc -L on the log file
825 fprintf (stderr, "line too long");
831 GST_WARNING ("empty log");
837 main (gint argc, gchar * argv[])
839 gchar **filenames = NULL;
843 GOptionEntry options[] = {
844 GST_TOOLS_GOPTION_VERSION,
845 // TODO(ensonic): add a summary flag, if set read the whole thing, print
846 // stats once, and exit
847 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL}
853 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
854 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
855 textdomain (GETTEXT_PACKAGE);
858 g_set_prgname ("gst-stats-" GST_API_VERSION);
860 ctx = g_option_context_new ("FILE");
861 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
862 g_option_context_add_group (ctx, gst_init_get_option_group ());
863 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
864 g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
867 g_option_context_free (ctx);
869 gst_tools_print_version ();
871 if (filenames == NULL || *filenames == NULL) {
872 g_print ("Please give one filename to %s\n\n", g_get_prgname ());
875 num = g_strv_length (filenames);
876 if (num == 0 || num > 1) {
877 g_print ("Please give exactly one filename to %s (%d given).\n\n",
878 g_get_prgname (), num);
883 collect_stats (filenames[0]);
888 g_strfreev (filenames);