summaryrefslogtreecommitdiffstats
path: root/src/debug
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/.cvsignore3
-rw-r--r--src/debug/Makefile_insert15
-rw-r--r--src/debug/event-tracker.h224
-rw-r--r--src/debug/event.h75
-rw-r--r--src/debug/gc-heap.h52
-rw-r--r--src/debug/heap.cpp65
-rw-r--r--src/debug/heap.h63
-rw-r--r--src/debug/logger.cpp204
-rw-r--r--src/debug/logger.h171
-rw-r--r--src/debug/makefile.in17
-rw-r--r--src/debug/simple-event.h51
-rw-r--r--src/debug/sysv-heap.cpp79
-rw-r--r--src/debug/sysv-heap.h47
13 files changed, 1066 insertions, 0 deletions
diff --git a/src/debug/.cvsignore b/src/debug/.cvsignore
new file mode 100644
index 000000000..38efca7bc
--- /dev/null
+++ b/src/debug/.cvsignore
@@ -0,0 +1,3 @@
+.deps
+.dirstamp
+makefile
diff --git a/src/debug/Makefile_insert b/src/debug/Makefile_insert
new file mode 100644
index 000000000..ec4e0ceea
--- /dev/null
+++ b/src/debug/Makefile_insert
@@ -0,0 +1,15 @@
+
+debug/all: debug/libinkdebug.a
+
+debug/clean:
+ rm -f debug/libinkdebug.a $(debug_libinkdebug_a_OBJECTS)
+
+debug_libinkdebug_a_SOURCES = \
+ debug/event.h \
+ debug/event-tracker.h \
+ debug/heap.cpp debug/heap.h \
+ debug/gc-heap.h \
+ debug/logger.cpp debug/logger.h \
+ debug/simple-event.h \
+ debug/sysv-heap.cpp debug/sysv-heap.h
+
diff --git a/src/debug/event-tracker.h b/src/debug/event-tracker.h
new file mode 100644
index 000000000..362175f94
--- /dev/null
+++ b/src/debug/event-tracker.h
@@ -0,0 +1,224 @@
+/*
+ * Inkscape::Debug::EventTracker - semi-automatically track event lifetimes
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_DEBUG_EVENT_TRACKER_H
+#define SEEN_INKSCAPE_DEBUG_EVENT_TRACKER_H
+
+#include "debug/logger.h"
+
+namespace Inkscape {
+
+namespace Debug {
+
+struct NoInitialEvent {};
+
+template <typename Event=NoInitialEvent> class EventTracker;
+
+class EventTrackerBase {
+public:
+ ~EventTrackerBase() {
+ if (_active) {
+ Logger::finish();
+ }
+ }
+
+ template <typename EventType>
+ inline void set() {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>();
+ _active = true;
+ }
+
+ template <typename EventType, typename A>
+ inline void set(A const &a) {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>(a);
+ _active = true;
+ }
+
+ template <typename EventType, typename A, typename B>
+ inline void set(A const &a, B const &b) {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>(a, b);
+ _active = true;
+ }
+
+ template <typename EventType, typename A, typename B, typename C>
+ inline void set(A const &a, B const &b, C const &c) {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>(a, b, c);
+ _active = true;
+ }
+
+ template <typename EventType, typename A, typename B,
+ typename C, typename D>
+ inline void set(A const &a, B const &b, C const &c, D const &d) {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>(a, b, c, d);
+ _active = true;
+ }
+
+ template <typename EventType, typename A, typename B, typename C,
+ typename D, typename E>
+ inline void set(A const &a, B const &b, C const &c, D const &d, E const &e)
+ {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>(a, b, c, d, e);
+ _active = true;
+ }
+
+ template <typename EventType, typename A, typename B, typename C,
+ typename D, typename E, typename F>
+ inline void set(A const &a, B const &b, C const &c,
+ D const &d, E const &e, F const &f)
+ {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>(a, b, c, d, e, f);
+ _active = true;
+ }
+
+ template <typename EventType, typename A, typename B, typename C,
+ typename D, typename E, typename F,
+ typename G>
+ inline void set(A const &a, B const &b, C const &c, D const &d,
+ E const &e, F const &f, G const &g)
+ {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>(a, b, c, d, e, f, g);
+ _active = true;
+ }
+
+ template <typename EventType, typename A, typename B, typename C,
+ typename D, typename E, typename F,
+ typename G, typename H>
+ inline void set(A const &a, B const &b, C const &c, D const &d,
+ E const &e, F const &f, G const &g, H const &h)
+ {
+ if (_active) {
+ Logger::finish();
+ }
+ Logger::start<EventType>(a, b, c, d, e, f, g, h);
+ _active = true;
+ }
+
+ void clear() {
+ if (_active) {
+ Logger::finish();
+ _active = false;
+ }
+ }
+
+protected:
+ EventTrackerBase(bool active) : _active(active) {}
+
+private:
+ EventTrackerBase(EventTrackerBase const &); // no copy
+ void operator=(EventTrackerBase const &); // no assign
+ bool _active;
+};
+
+template <typename EventType> class EventTracker : public EventTrackerBase {
+public:
+ EventTracker() : EventTrackerBase(true) { Logger::start<EventType>(); }
+
+ template <typename A>
+ EventTracker(A const &a) : EventTrackerBase(true) {
+ Logger::start<EventType>(a);
+ }
+
+ template <typename A, typename B>
+ EventTracker(A const &a, B const &b) : EventTrackerBase(true) {
+ Logger::start<EventType>(a, b);
+ }
+
+ template <typename A, typename B, typename C>
+ EventTracker(A const &a, B const &b, C const &c) : EventTrackerBase(true) {
+ Logger::start<EventType>(a, b, c);
+ }
+
+ template <typename A, typename B, typename C, typename D>
+ EventTracker(A const &a, B const &b, C const &c, D const &d)
+ : EventTrackerBase(true)
+ {
+ Logger::start<EventType>(a, b, c, d);
+ }
+
+ template <typename A, typename B, typename C, typename D, typename E>
+ EventTracker(A const &a, B const &b, C const &c, D const &d, E const &e)
+ : EventTrackerBase(true)
+ {
+ Logger::start<EventType>(a, b, c, d, e);
+ }
+
+ template <typename A, typename B, typename C, typename D,
+ typename E, typename F>
+ EventTracker(A const &a, B const &b, C const &c, D const &d,
+ E const &e, F const &f)
+ : EventTrackerBase(true)
+ {
+ Logger::start<EventType>(a, b, c, d, e, f);
+ }
+
+ template <typename A, typename B, typename C, typename D,
+ typename E, typename F, typename G>
+ EventTracker(A const &a, B const &b, C const &c, D const &d,
+ E const &e, F const &f, G const &g)
+ : EventTrackerBase(true)
+ {
+ Logger::start<EventType>(a, b, c, d, e, f, g);
+ }
+
+ template <typename A, typename B, typename C, typename D,
+ typename E, typename F, typename G, typename H>
+ EventTracker(A const &a, B const &b, C const &c, D const &d,
+ E const &e, F const &f, G const &g, H const &h)
+ : EventTrackerBase(true)
+ {
+ Logger::start<EventType>(a, b, c, d, e, f, g, h);
+ }
+};
+
+template <> class EventTracker<NoInitialEvent> : public EventTrackerBase {
+public:
+ EventTracker() : EventTrackerBase(false) {}
+};
+
+}
+
+}
+
+#endif
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/event.h b/src/debug/event.h
new file mode 100644
index 000000000..c3b3a83fb
--- /dev/null
+++ b/src/debug/event.h
@@ -0,0 +1,75 @@
+/*
+ * Inkscape::Debug::Event - event for debug tracing
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_DEBUG_EVENT_H
+#define SEEN_INKSCAPE_DEBUG_EVENT_H
+
+#include <utility>
+#include "util/shared-c-string-ptr.h"
+
+namespace Inkscape {
+
+namespace Debug {
+
+class Event {
+public:
+ virtual ~Event() {}
+
+ enum Category {
+ CORE=0,
+ XML,
+ SPOBJECT,
+ DOCUMENT,
+ REFCOUNT,
+ EXTENSION,
+ OTHER
+ };
+ enum { N_CATEGORIES=OTHER+1 };
+
+ struct PropertyPair {
+ public:
+ PropertyPair() {}
+ PropertyPair(Util::SharedCStringPtr n, Util::SharedCStringPtr v)
+ : name(n), value(v) {}
+ PropertyPair(char const *n, Util::SharedCStringPtr v)
+ : name(Util::SharedCStringPtr::copy(n)), value(v) {}
+ PropertyPair(Util::SharedCStringPtr n, char const *v)
+ : name(n), value(Util::SharedCStringPtr::copy(v)) {}
+ PropertyPair(char const *n, char const *v)
+ : name(Util::SharedCStringPtr::copy(n)),
+ value(Util::SharedCStringPtr::copy(v)) {}
+
+ Util::SharedCStringPtr name;
+ Util::SharedCStringPtr value;
+ };
+
+ static Category category() { return OTHER; }
+
+ virtual Util::SharedCStringPtr name() const=0;
+ virtual unsigned propertyCount() const=0;
+ virtual PropertyPair property(unsigned property) const=0;
+};
+
+}
+
+}
+
+#endif
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/gc-heap.h b/src/debug/gc-heap.h
new file mode 100644
index 000000000..b3042432e
--- /dev/null
+++ b/src/debug/gc-heap.h
@@ -0,0 +1,52 @@
+/*
+ * Inkscape::Debug::GCHeap - heap statistics for libgc heap
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2004 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_DEBUG_GC_HEAP_H
+#define SEEN_INKSCAPE_DEBUG_GC_HEAP_H
+
+#include "gc-core.h"
+#include "debug/heap.h"
+
+namespace Inkscape {
+namespace Debug {
+
+class GCHeap : public Debug::Heap {
+public:
+ int features() const {
+ return SIZE_AVAILABLE | USED_AVAILABLE | GARBAGE_COLLECTED;
+ }
+ Util::SharedCStringPtr name() const {
+ return Util::SharedCStringPtr::coerce("libgc");
+ }
+ Heap::Stats stats() const {
+ Stats stats;
+ stats.size = GC::Core::get_heap_size();
+ stats.bytes_used = stats.size - GC::Core::get_free_bytes();
+ return stats;
+ }
+ void force_collect() { GC::Core::gcollect(); }
+};
+
+}
+}
+
+#endif
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/heap.cpp b/src/debug/heap.cpp
new file mode 100644
index 000000000..c0452f26b
--- /dev/null
+++ b/src/debug/heap.cpp
@@ -0,0 +1,65 @@
+/*
+ * Inkscape::Debug::Heap - interface for gathering heap statistics
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "gc-alloc.h"
+#include "debug/gc-heap.h"
+#include "debug/sysv-heap.h"
+#include <vector>
+
+namespace Inkscape {
+namespace Debug {
+
+namespace {
+
+typedef std::vector<Heap *, GC::Alloc<Heap *, GC::MANUAL> > HeapCollection;
+
+HeapCollection &heaps() {
+ static bool is_initialized=false;
+ static HeapCollection heaps;
+ if (!is_initialized) {
+ heaps.push_back(new SysVHeap());
+ heaps.push_back(new GCHeap());
+ is_initialized = true;
+ }
+ return heaps;
+}
+
+}
+
+unsigned heap_count() {
+ return heaps().size();
+}
+
+Heap *get_heap(unsigned i) {
+ return heaps()[i];
+}
+
+void register_extra_heap(Heap &heap) {
+ heaps().push_back(&heap);
+}
+
+}
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/heap.h b/src/debug/heap.h
new file mode 100644
index 000000000..d07cf74a1
--- /dev/null
+++ b/src/debug/heap.h
@@ -0,0 +1,63 @@
+/*
+ * Inkscape::Debug::Heap - interface for gathering heap statistics
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_DEBUG_HEAP_H
+#define SEEN_INKSCAPE_DEBUG_HEAP_H
+
+#include <cstddef>
+#include "util/shared-c-string-ptr.h"
+
+namespace Inkscape {
+
+namespace Debug {
+
+class Heap {
+public:
+ virtual ~Heap() {}
+
+ struct Stats {
+ std::size_t size;
+ std::size_t bytes_used;
+ };
+
+ enum {
+ SIZE_AVAILABLE = ( 1 << 0 ),
+ USED_AVAILABLE = ( 1 << 1 ),
+ GARBAGE_COLLECTED = ( 1 << 2 )
+ };
+
+ virtual int features() const=0;
+
+ virtual Util::SharedCStringPtr name() const=0;
+ virtual Stats stats() const=0;
+ virtual void force_collect()=0;
+};
+
+unsigned heap_count();
+Heap *get_heap(unsigned i);
+
+void register_extra_heap(Heap &heap);
+
+}
+
+}
+
+#endif
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/logger.cpp b/src/debug/logger.cpp
new file mode 100644
index 000000000..a3c7b0430
--- /dev/null
+++ b/src/debug/logger.cpp
@@ -0,0 +1,204 @@
+/*
+ * Inkscape::Debug::Logger - debug logging facility
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <fstream>
+#include <vector>
+#include <glib/gmessages.h>
+#include "debug/logger.h"
+#include "debug/simple-event.h"
+#include "gc-alloc.h"
+
+namespace Inkscape {
+
+namespace Debug {
+
+bool Logger::_enabled=false;
+bool Logger::_category_mask[Event::N_CATEGORIES];
+
+namespace {
+
+static void write_escaped_value(std::ostream &os, Util::SharedCStringPtr value) {
+ for ( char const *current=value ; *current ; ++current ) {
+ switch (*current) {
+ case '&':
+ os << "&amp;";
+ break;
+ case '"':
+ os << "&quot;";
+ break;
+ case '\'':
+ os << "&apos;";
+ break;
+ case '<':
+ os << "&lt;";
+ break;
+ case '>':
+ os << "&gt;";
+ break;
+ default:
+ os.put(*current);
+ }
+ }
+}
+
+static void write_indent(std::ostream &os, unsigned depth) {
+ for ( unsigned i = 0 ; i < depth ; i++ ) {
+ os.write(" ", 2);
+ }
+}
+
+static std::ofstream log_stream;
+static bool empty_tag=false;
+typedef std::vector<Util::SharedCStringPtr, GC::Alloc<Util::SharedCStringPtr, GC::MANUAL> > TagStack;
+static TagStack &tag_stack() {
+ static TagStack stack;
+ return stack;
+}
+
+static void do_shutdown() {
+ Debug::Logger::shutdown();
+}
+
+static bool equal_range(char const *c_string,
+ char const *start, char const *end)
+{
+ return !std::strncmp(start, c_string, end - start) &&
+ !c_string[end - start];
+}
+
+static void set_category_mask(bool * const mask, char const *filter) {
+ if (!filter) {
+ for ( unsigned i = 0 ; i < Event::N_CATEGORIES ; i++ ) {
+ mask[i] = true;
+ }
+ return;
+ } else {
+ for ( unsigned i = 0 ; i < Event::N_CATEGORIES ; i++ ) {
+ mask[i] = false;
+ }
+ mask[Event::CORE] = true;
+ }
+
+ char const *start;
+ char const *end;
+ start = end = filter;
+ while (*end) {
+ while ( *end && *end != ',' ) { end++; }
+ if ( start != end ) {
+ if (equal_range("CORE", start, end)) {
+ mask[Event::CORE] = true;
+ } else if (equal_range("XML", start, end)) {
+ mask[Event::XML] = true;
+ } else if (equal_range("SPOBJECT", start, end)) {
+ mask[Event::SPOBJECT] = true;
+ } else if (equal_range("DOCUMENT", start, end)) {
+ mask[Event::DOCUMENT] = true;
+ } else if (equal_range("REFCOUNT", start, end)) {
+ mask[Event::REFCOUNT] = true;
+ } else if (equal_range("EXTENSION", start, end)) {
+ mask[Event::EXTENSION] = true;
+ } else {
+ g_warning("Unknown debugging category %*s", end - start, start);
+ }
+ }
+ if (*end) {
+ start = end = end + 1;
+ }
+ }
+}
+
+}
+
+void Logger::init() {
+ if (!_enabled) {
+ char const *log_filename=std::getenv("INKSCAPE_DEBUG_LOG");
+ if (log_filename) {
+ log_stream.open(log_filename);
+ if (log_stream.is_open()) {
+ char const *log_filter=std::getenv("INKSCAPE_DEBUG_FILTER");
+ set_category_mask(_category_mask, log_filter);
+ log_stream << "<?xml version=\"1.0\"?>\n";
+ log_stream.flush();
+ _enabled = true;
+ start<SimpleEvent<Event::CORE> >(Util::SharedCStringPtr::coerce("session"));
+ std::atexit(&do_shutdown);
+ }
+ }
+ }
+}
+
+void Logger::_start(Event const &event) {
+ Util::SharedCStringPtr name=event.name();
+
+ if (empty_tag) {
+ log_stream << ">\n";
+ }
+
+ write_indent(log_stream, tag_stack().size());
+
+ log_stream << "<" << name.cString();
+
+ unsigned property_count=event.propertyCount();
+ for ( unsigned i = 0 ; i < property_count ; i++ ) {
+ Event::PropertyPair property=event.property(i);
+ log_stream << " " << property.name.cString() << "=\"";
+ write_escaped_value(log_stream, property.value);
+ log_stream << "\"";
+ }
+
+ log_stream.flush();
+
+ tag_stack().push_back(name);
+ empty_tag = true;
+}
+
+void Logger::_skip() {
+ tag_stack().push_back(Util::SharedCStringPtr());
+}
+
+void Logger::_finish() {
+ if (tag_stack().back()) {
+ if (empty_tag) {
+ log_stream << "/>\n";
+ } else {
+ write_indent(log_stream, tag_stack().size() - 1);
+ log_stream << "</" << tag_stack().back().cString() << ">\n";
+ }
+ log_stream.flush();
+
+ empty_tag = false;
+ }
+
+ tag_stack().pop_back();
+}
+
+void Logger::shutdown() {
+ if (_enabled) {
+ while (!tag_stack().empty()) {
+ finish();
+ }
+ }
+}
+
+}
+
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/logger.h b/src/debug/logger.h
new file mode 100644
index 000000000..61f9c2764
--- /dev/null
+++ b/src/debug/logger.h
@@ -0,0 +1,171 @@
+/*
+ * Inkscape::Debug::Logger - debug logging facility
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_DEBUG_LOGGER_H
+#define SEEN_INKSCAPE_DEBUG_LOGGER_H
+
+#include "debug/event.h"
+
+namespace Inkscape {
+
+namespace Debug {
+
+class Logger {
+public:
+ static void init();
+
+ template <typename EventType>
+ inline static void start() {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType());
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ template <typename EventType, typename A>
+ inline static void start(A const &a) {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType(a));
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ template <typename EventType, typename A, typename B>
+ inline static void start(A const &a, B const &b) {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType(a, b));
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ template <typename EventType, typename A, typename B, typename C>
+ inline static void start(A const &a, B const &b, C const &c) {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType(a, b, c));
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ template <typename EventType, typename A, typename B,
+ typename C, typename D>
+ inline static void start(A const &a, B const &b, C const &c, D const &d) {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType(a, b, c, d));
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ template <typename EventType, typename A, typename B, typename C,
+ typename D, typename E>
+ inline static void start(A const &a, B const &b, C const &c,
+ D const &d, E const &e)
+ {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType(a, b, c, d, e));
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ template <typename EventType, typename A, typename B, typename C,
+ typename D, typename E, typename F>
+ inline static void start(A const &a, B const &b, C const &c,
+ D const &d, E const &e, F const &f)
+ {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType(a, b, c, d, e, f));
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ template <typename EventType, typename A, typename B, typename C,
+ typename D, typename E, typename F,
+ typename G>
+ inline static void start(A const &a, B const &b, C const &c, D const &d,
+ E const &e, F const &f, G const &g)
+ {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType(a, b, c, d, e, f, g));
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ template <typename EventType, typename A, typename B, typename C,
+ typename D, typename E, typename F,
+ typename G, typename H>
+ inline static void start(A const &a, B const &b, C const &c, D const &d,
+ E const &e, F const &f, G const &g, H const &h)
+ {
+ if (_enabled) {
+ if (_category_mask[EventType::category()]) {
+ _start(EventType(a, b, c, d, e, f, g, h));
+ } else {
+ _skip();
+ }
+ }
+ }
+
+ inline static void finish() {
+ if (_enabled) {
+ _finish();
+ }
+ }
+
+ static void shutdown();
+
+private:
+ static bool _enabled;
+
+ static void _start(Event const &event);
+ static void _skip();
+ static void _finish();
+
+ static bool _category_mask[Event::N_CATEGORIES];
+};
+
+}
+
+}
+
+#endif
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/makefile.in b/src/debug/makefile.in
new file mode 100644
index 000000000..89533f16d
--- /dev/null
+++ b/src/debug/makefile.in
@@ -0,0 +1,17 @@
+# Convenience stub makefile to call the real Makefile.
+
+@SET_MAKE@
+
+# Explicit so that it's the default rule.
+all:
+ cd .. && $(MAKE) debug/all
+
+clean %.a %.o:
+ cd .. && $(MAKE) debug/$@
+
+.PHONY: all clean
+
+OBJEXT = @OBJEXT@
+
+.SUFFIXES:
+.SUFFIXES: .a .$(OBJEXT)
diff --git a/src/debug/simple-event.h b/src/debug/simple-event.h
new file mode 100644
index 000000000..3a3adae3c
--- /dev/null
+++ b/src/debug/simple-event.h
@@ -0,0 +1,51 @@
+/*
+ * Inkscape::Debug::SimpleEvent - trivial implementation of Debug::Event
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_DEBUG_SIMPLE_EVENT_H
+#define SEEN_INKSCAPE_DEBUG_SIMPLE_EVENT_H
+
+#include "debug/event.h"
+
+namespace Inkscape {
+
+namespace Debug {
+
+template <Event::Category C=Event::OTHER>
+class SimpleEvent : public Event {
+public:
+ SimpleEvent(Util::SharedCStringPtr name) : _name(name) {}
+ SimpleEvent(char const *name) : _name(Util::SharedCStringPtr::copy(name)) {}
+
+ static Category category() { return C; }
+
+ Util::SharedCStringPtr name() const { return _name; }
+ unsigned propertyCount() const { return 0; }
+ PropertyPair property(unsigned property) const { return PropertyPair(); }
+
+private:
+ Util::SharedCStringPtr _name;
+};
+
+}
+
+}
+
+#endif
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/sysv-heap.cpp b/src/debug/sysv-heap.cpp
new file mode 100644
index 000000000..9ca6ea549
--- /dev/null
+++ b/src/debug/sysv-heap.cpp
@@ -0,0 +1,79 @@
+/*
+ * Inkscape::Debug::SysVHeap - malloc() statistics via System V interface
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+
+#include "debug/sysv-heap.h"
+
+namespace Inkscape {
+namespace Debug {
+
+int SysVHeap::features() const {
+#ifdef HAVE_MALLINFO
+ return SIZE_AVAILABLE | USED_AVAILABLE;
+#else
+ return 0;
+#endif
+}
+
+Heap::Stats SysVHeap::stats() const {
+ Stats stats = { 0, 0 };
+
+#ifdef HAVE_MALLINFO
+ struct mallinfo info=mallinfo();
+
+#ifdef HAVE_STRUCT_MALLINFO_USMBLKS
+ stats.size += info.usmblks;
+ stats.bytes_used += info.usmblks;
+#endif
+
+#ifdef HAVE_STRUCT_MALLINFO_FSMBLKS
+ stats.size += info.fsmblks;
+#endif
+
+#ifdef HAVE_STRUCT_MALLINFO_UORDBLKS
+ stats.size += info.uordblks;
+ stats.bytes_used += info.uordblks;
+#endif
+
+#ifdef HAVE_STRUCT_MALLINFO_FORDBLKS
+ stats.size += info.fordblks;
+#endif
+
+#ifdef HAVE_STRUCT_MALLINFO_HBLKHD
+ stats.size += info.hblkhd;
+ stats.bytes_used += info.hblkhd;
+#endif
+
+#endif
+
+ return stats;
+}
+
+}
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/debug/sysv-heap.h b/src/debug/sysv-heap.h
new file mode 100644
index 000000000..2ba24b2b5
--- /dev/null
+++ b/src/debug/sysv-heap.h
@@ -0,0 +1,47 @@
+/*
+ * Inkscape::Debug::SysVHeap - malloc() statistics via System V interface
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_DEBUG_SYSV_HEAP_H
+#define SEEN_INKSCAPE_DEBUG_SYSV_HEAP_H
+
+#include "debug/heap.h"
+
+namespace Inkscape {
+namespace Debug {
+
+class SysVHeap : public Heap {
+public:
+ SysVHeap() {}
+
+ int features() const;
+
+ Util::SharedCStringPtr name() const {
+ return Util::SharedCStringPtr::coerce("standard malloc()");
+ }
+ Stats stats() const;
+ void force_collect() {}
+};
+
+}
+}
+
+#endif
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :