Merge lp:~ghugesss/xpad/debug_support into lp:xpad

Proposed by Sagar Ghuge
Status: Merged
Merged at revision: 715
Proposed branch: lp:~ghugesss/xpad/debug_support
Merge into: lp:xpad
Diff against target: 283 lines (+244/-1)
4 files modified
src/Makefile.am (+2/-1)
src/xpad-app.c (+4/-0)
src/xpad-debug.c (+171/-0)
src/xpad-debug.h (+67/-0)
To merge this branch: bzr merge lp:~ghugesss/xpad/debug_support
Reviewer Review Type Date Requested Status
Arthur Borsboom Pending
Review via email: mp+242746@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Arthur Borsboom (arthurborsboom) wrote :
Download full text (11.2 KiB)

Hi Sagar,

When I asked for the merge request I was actually referring to the bug
report of the improved headers.
Although it shouldn't matter to much in which order I merge the branches,
is the debugging branch already finished?

If so, I will merge this one first and then the header one.

Cheers,

On 25 November 2014 at 10:09, Sagar Ghuge <email address hidden> wrote:

> Sagar Ghuge has proposed merging lp:~ghugesss/xpad/debug_support into
> lp:xpad.
>
> Requested reviews:
> Arthur Borsboom (arthurborsboom)
> Related bugs:
> Bug #1389334 in Xpad: "Allowing Debug option in Xpad"
> https://bugs.launchpad.net/xpad/+bug/1389334
>
> For more details, see:
> https://code.launchpad.net/~ghugesss/xpad/debug_support/+merge/242746
> --
> You are requested to review the proposed merge of
> lp:~ghugesss/xpad/debug_support into lp:xpad.
>
> === modified file 'src/Makefile.am'
> --- src/Makefile.am 2014-10-02 22:14:44 +0000
> +++ src/Makefile.am 2014-11-25 09:08:40 +0000
> @@ -17,7 +17,8 @@
> xpad-text-view.c xpad-text-view.h \
> xpad-toolbar.c xpad-toolbar.h \
> xpad-tray.c xpad-tray.h \
> - xpad-undo.c xpad-undo.h
> + xpad-undo.c xpad-undo.h \
> + xpad-debug.c xpad-debug.h
>
> AM_CFLAGS = @GTK_CFLAGS@ @X_CFLAGS@ @DEBUG_CFLAGS@
> @GTK_SOURCE_VIEW_CFLAGS@ -DDATADIR=\"$(datadir)\"
> xpad_LDADD = @X_PRE_LIBS@ @X_LIBS@ @X_EXTRA_LIBS@ @GTK_LIBS@ @INTLLIBS@
> @BINRELOC_LIBS@ @GTK_SOURCE_VIEW_LIBS@
>
> === modified file 'src/xpad-app.c'
> --- src/xpad-app.c 2014-11-22 12:14:17 +0000
> +++ src/xpad-app.c 2014-11-25 09:08:40 +0000
> @@ -40,6 +40,7 @@
> #include "xpad-periodic.h"
> #include "xpad-session-manager.h"
> #include "xpad-tray.h"
> +#include "xpad-debug.h"
>
> /* Seems that some systems (sun-sparc-solaris2.8 at least), need the
> following three #defines.
> These were provided by Alan Mizrahi <email address hidden>.
> @@ -94,6 +95,9 @@
> gboolean first_time;
> gboolean have_gtk;
>
> + xpad_debug_init();
> + xpad_debug_message (DEBUG_APP, "Startup");
> +
> /* Set up support different languages */
> #ifdef ENABLE_NLS
> bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
>
> === added file 'src/xpad-debug.c'
> --- src/xpad-debug.c 1970-01-01 00:00:00 +0000
> +++ src/xpad-debug.c 2014-11-25 09:08:40 +0000
> @@ -0,0 +1,171 @@
> +/*
> + * xpad-debug.c
> + * This file is part of xpad
> + *
> + * Copyright (C) 2014 - 2015 Sagar Ghuge
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program 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 General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#i...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2014-10-02 22:14:44 +0000
3+++ src/Makefile.am 2014-11-25 09:08:40 +0000
4@@ -17,7 +17,8 @@
5 xpad-text-view.c xpad-text-view.h \
6 xpad-toolbar.c xpad-toolbar.h \
7 xpad-tray.c xpad-tray.h \
8- xpad-undo.c xpad-undo.h
9+ xpad-undo.c xpad-undo.h \
10+ xpad-debug.c xpad-debug.h
11
12 AM_CFLAGS = @GTK_CFLAGS@ @X_CFLAGS@ @DEBUG_CFLAGS@ @GTK_SOURCE_VIEW_CFLAGS@ -DDATADIR=\"$(datadir)\"
13 xpad_LDADD = @X_PRE_LIBS@ @X_LIBS@ @X_EXTRA_LIBS@ @GTK_LIBS@ @INTLLIBS@ @BINRELOC_LIBS@ @GTK_SOURCE_VIEW_LIBS@
14
15=== modified file 'src/xpad-app.c'
16--- src/xpad-app.c 2014-11-22 12:14:17 +0000
17+++ src/xpad-app.c 2014-11-25 09:08:40 +0000
18@@ -40,6 +40,7 @@
19 #include "xpad-periodic.h"
20 #include "xpad-session-manager.h"
21 #include "xpad-tray.h"
22+#include "xpad-debug.h"
23
24 /* Seems that some systems (sun-sparc-solaris2.8 at least), need the following three #defines.
25 These were provided by Alan Mizrahi <alan@cesma.usb.ve>.
26@@ -94,6 +95,9 @@
27 gboolean first_time;
28 gboolean have_gtk;
29
30+ xpad_debug_init();
31+ xpad_debug_message (DEBUG_APP, "Startup");
32+
33 /* Set up support different languages */
34 #ifdef ENABLE_NLS
35 bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
36
37=== added file 'src/xpad-debug.c'
38--- src/xpad-debug.c 1970-01-01 00:00:00 +0000
39+++ src/xpad-debug.c 2014-11-25 09:08:40 +0000
40@@ -0,0 +1,171 @@
41+/*
42+ * xpad-debug.c
43+ * This file is part of xpad
44+ *
45+ * Copyright (C) 2014 - 2015 Sagar Ghuge
46+ *
47+ * This program is free software; you can redistribute it and/or modify
48+ * it under the terms of the GNU General Public License as published by
49+ * the Free Software Foundation; either version 2 of the License, or
50+ * (at your option) any later version.
51+ *
52+ * This program is distributed in the hope that it will be useful,
53+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
54+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55+ * GNU General Public License for more details.
56+ *
57+ * You should have received a copy of the GNU General Public License
58+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
59+ */
60+
61+#ifdef HAVE_CONFIG_H
62+#include <config.h>
63+#endif
64+
65+#include <stdio.h>
66+#include "xpad-debug.h"
67+
68+#define ENABLE_PROFILING
69+
70+#ifdef ENABLE_PROFILING
71+static GTimer *timer = NULL;
72+static gdouble last = 0.0;
73+#endif
74+
75+static XpadDebugSection debug = XPAD_NO_DEBUG;
76+
77+#define DEBUG_IS_ENABLED(section_rval) (debug & (section_rval))
78+
79+/**
80+ * xpad_debug_init:
81+ *
82+ * Initializes the debugging subsystem of Xpad.
83+ *
84+ * The function checks for the existence of certain environment variables to
85+ * determine whether to enable output for a debug section. To enable output
86+ * for a specific debug section, set an environment variable of the same name;
87+ * e.g. to enable output for the %XPAD_DEBUG_APP section, set a
88+ * <code>XPAD_DEBUG_APP</code> environment variable. To enable output
89+ * for all debug sections, set the <code>XPAD_DEBUG</code> environment
90+ * variable.
91+ *
92+ * This function must be called before any of the other debug functions are
93+ * called. It must only be called once.
94+ */
95+void
96+xpad_debug_init (void)
97+{
98+ if (g_getenv ("XPAD_DEBUG") != NULL)
99+ {
100+ /* enable all debugging */
101+ debug = ~XPAD_NO_DEBUG;
102+ goto out;
103+ }
104+
105+ if (g_getenv ("XPAD_DEBUG_VIEW") != NULL)
106+ debug = debug | XPAD_DEBUG_VIEW;
107+ if (g_getenv ("XPAD_DEBUG_SEARCH") != NULL)
108+ debug = debug | XPAD_DEBUG_SEARCH;
109+ if (g_getenv ("XPAD_DEBUG_PREFS") != NULL)
110+ debug = debug | XPAD_DEBUG_PREFS;
111+ if (g_getenv ("XPAD_DEBUG_PAD") != NULL)
112+ debug = debug | XPAD_DEBUG_PAD;
113+ if (g_getenv ("XPAD_DEBUG_APP") != NULL)
114+ debug = debug | XPAD_DEBUG_APP;
115+ if (g_getenv ("XPAD_DEBUG_WINDOW") != NULL)
116+ debug = debug | XPAD_DEBUG_WINDOW;
117+out:
118+
119+#ifdef ENABLE_PROFILING
120+ if (debug != XPAD_NO_DEBUG)
121+ timer = g_timer_new ();
122+#endif
123+ return;
124+}
125+
126+/**
127+ * xpad_debug:
128+ * @section: Debug section.
129+ * @file: Name of the source file containing the call to xpad_debug().
130+ * @line: Line number within the file named by @file of the call to xpad_debug().
131+ * @function: Name of the function that is calling xpad_debug().
132+ *
133+ * If output for debug section @section is enabled, then logs the trace
134+ * information @file, @line, and @function.
135+ */
136+void xpad_debug (XpadDebugSection section,
137+ const gchar *file,
138+ gint line,
139+ const gchar *function)
140+{
141+ if (G_UNLIKELY (DEBUG_IS_ENABLED (section)))
142+ {
143+#ifdef ENABLE_PROFILING
144+ gdouble seconds;
145+
146+ g_return_if_fail (timer != NULL);
147+
148+ seconds = g_timer_elapsed (timer, NULL);
149+ g_print ("[%f (%f)] %s:%d (%s)\n",
150+ seconds, seconds - last, file, line, function);
151+ last = seconds;
152+#else
153+ g_print ("%s:%d (%s)\n", file, line, function);
154+#endif
155+
156+ fflush (stdout);
157+ }
158+}
159+
160+/**
161+ * xpad_debug_message:
162+ * @section: Debug section.
163+ * @file: Name of the source file containing the call to xpad_debug_message().
164+ * @line: Line number within the file named by @file of the call to xpad_debug_message().
165+ * @function: Name of the function that is calling xpad_debug_message().
166+ * @format: A g_vprintf() format string.
167+ * @...: The format string arguments.
168+ *
169+ * If output for debug section @section is enabled, then logs the trace
170+ * information @file, @line, and @function along with the message obtained by
171+ * formatting @format with the given format string arguments.
172+ */
173+void
174+xpad_debug_message (XpadDebugSection section,
175+ const gchar *file,
176+ gint line,
177+ const gchar *function,
178+ const gchar *format, ...)
179+{
180+ if (G_UNLIKELY (DEBUG_IS_ENABLED (section)))
181+ {
182+ va_list args;
183+ gchar *msg;
184+
185+#ifdef ENABLE_PROFILING
186+ gdouble seconds;
187+
188+ g_return_if_fail (timer != NULL);
189+
190+ seconds = g_timer_elapsed (timer, NULL);
191+#endif
192+
193+ g_return_if_fail (format != NULL);
194+
195+ va_start (args, format);
196+ msg = g_strdup_vprintf (format, args);
197+ va_end (args);
198+
199+#ifdef ENABLE_PROFILING
200+ g_print ("[%f (%f)] %s:%d (%s) %s\n",
201+ seconds, seconds - last, file, line, function, msg);
202+ last = seconds;
203+#else
204+ g_print ("%s:%d (%s) %s\n", file, line, function, msg);
205+#endif
206+
207+ fflush (stdout);
208+
209+ g_free (msg);
210+ }
211+}
212
213=== added file 'src/xpad-debug.h'
214--- src/xpad-debug.h 1970-01-01 00:00:00 +0000
215+++ src/xpad-debug.h 2014-11-25 09:08:40 +0000
216@@ -0,0 +1,67 @@
217+/*
218+ * xpad-debug.h
219+ * This file is part of xpad
220+ *
221+ * Copyright (C) 2014 - 2015 Sagar Ghuge
222+ *
223+ * This program is free software; you can redistribute it and/or modify
224+ * it under the terms of the GNU General Public License as published by
225+ * the Free Software Foundation; either version 2 of the License, or
226+ * (at your option) any later version.
227+ *
228+ * This program is distributed in the hope that it will be useful,
229+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
230+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
231+ * GNU General Public License for more details.
232+ *
233+ * You should have received a copy of the GNU General Public License
234+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
235+ */
236+
237+#ifndef __XPAD_DEBUG_H__
238+#define __XPAD_DEBUG_H__
239+
240+#include <glib.h>
241+
242+/**
243+ * XpadDebugSection:
244+ *
245+ * Enumeration of debug sections.
246+ *
247+ * Debugging output for a section is enabled by setting an environment variable
248+ * of the same name. For example, setting the <code>XPAD_DEBUG_APP</code>
249+ * environment variable enables all debugging output for the %XPAD_DEBUG_APP
250+ * section. Setting the special environment variable <code>XPAD_DEBUG</code>
251+ * enables output for all sections.
252+ */
253+typedef enum {
254+ XPAD_NO_DEBUG = 0,
255+ XPAD_DEBUG_VIEW = 1 << 0,
256+ XPAD_DEBUG_SEARCH = 1 << 1,
257+ XPAD_DEBUG_PREFS = 1 << 2,
258+ XPAD_DEBUG_PAD = 1 << 3,
259+ XPAD_DEBUG_APP = 1 << 4,
260+ XPAD_DEBUG_WINDOW = 1 << 5,
261+} XpadDebugSection;
262+
263+#define DEBUG_VIEW XPAD_DEBUG_VIEW, __FILE__, __LINE__, G_STRFUNC
264+#define DEBUG_SEARCH XPAD_DEBUG_SEARCH, __FILE__, __LINE__, G_STRFUNC
265+#define DEBUG_PREFS XPAD_DEBUG_PREFS, __FILE__, __LINE__, G_STRFUNC
266+#define DEBUG_PAD XPAD_DEBUG_PAD, __FILE__, __LINE__, G_STRFUNC
267+#define DEBUG_APP XPAD_DEBUG_APP, __FILE__, __LINE__, G_STRFUNC
268+#define DEBUG_WINDOW XPAD_DEBUG_WINDOW, __FILE__, __LINE__, G_STRFUNC
269+
270+void xpad_debug_init (void);
271+
272+void xpad_debug (XpadDebugSection section,
273+ const gchar *file,
274+ gint line,
275+ const gchar *function);
276+
277+void xpad_debug_message (XpadDebugSection section,
278+ const gchar *file,
279+ gint line,
280+ const gchar *function,
281+ const gchar *format, ...) G_GNUC_PRINTF(5, 6);
282+
283+#endif /* __XPAD_DEBUG_H__ */

Subscribers

People subscribed via source and target branches