~khurshid-alam/libunity/glib-2.59.3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (C) 2011 Canonical, Ltd.
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 3.0 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3.0 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 */

#include <glib-object.h>

#include "unity-trace.h"

#ifdef ENABLE_LTTNG
#define TRACEPOINT_DEFINE
#include "lttng-component-provider.h"
#include "tp.c"
#endif

void
unity_trace_log_object_va (void        *obj,
                           const gchar *format,
                           va_list      args)
{
  GString   *tmp;

  if (!G_IS_OBJECT(obj)) {
    g_critical ("Failed to log '%s' for object. Not an object.", format);
    return;
  }

  tmp = g_string_sized_new (64);
  g_string_printf (tmp, "(%s@%p): ", g_type_name(G_OBJECT_TYPE(obj)), obj);
  g_string_append (tmp, format);
  g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, tmp->str, args);

  g_string_free (tmp, TRUE);
}

void
unity_trace_log_object_real (void   		 *obj,
                             const gchar *format,
                             ...)
{
  va_list args;
  va_start (args, format);
  unity_trace_log_object_va (obj, format, args);
  va_end (args);
}

void
unity_trace_tracepoint_va (const gchar *format, va_list args)
{
#ifdef ENABLE_LTTNG
  gchar *tmp = g_strdup_vprintf (format, args);
  tracepoint (libunity, message, tmp);
  g_free (tmp);
#endif
}