diff --git a/libvips/include/vips/gate.h b/libvips/include/vips/gate.h index d499950d..7d2e1928 100644 --- a/libvips/include/vips/gate.h +++ b/libvips/include/vips/gate.h @@ -37,36 +37,6 @@ extern "C" { #include -#define VIPS_GATE_SIZE (10000) - -/* A set of timing records. i is the index of the next slot we fill. - */ -typedef struct _VipsThreadGateBlock { - struct _VipsThreadGateBlock *prev; - - gint64 time[VIPS_GATE_SIZE]; - int i; -} VipsThreadGateBlock; - -/* What we track for each gate-name. - */ -typedef struct _VipsThreadGate { - const char *name; - VipsThreadGateBlock *start; - VipsThreadGateBlock *stop; -} VipsThreadGate; - -/* One of these in per-thread private storage. - */ - -typedef struct _VipsThreadProfile { - /*< private >*/ - - const char *name; - GThread *thread; - GHashTable *gates; -} VipsThreadProfile; - #define VIPS_GATE_START( NAME ) \ G_STMT_START { \ if( vips__thread_profile ) \ diff --git a/libvips/iofuncs/gate.c b/libvips/iofuncs/gate.c index 55241f84..95d88762 100644 --- a/libvips/iofuncs/gate.c +++ b/libvips/iofuncs/gate.c @@ -42,6 +42,36 @@ #include #include +#define VIPS_GATE_SIZE (1000) + +/* A set of timing records. i is the index of the next slot we fill. + */ +typedef struct _VipsThreadGateBlock { + struct _VipsThreadGateBlock *prev; + + gint64 time[VIPS_GATE_SIZE]; + int i; +} VipsThreadGateBlock; + +/* What we track for each gate-name. + */ +typedef struct _VipsThreadGate { + const char *name; + VipsThreadGateBlock *start; + VipsThreadGateBlock *stop; +} VipsThreadGate; + +/* One of these in per-thread private storage. + */ + +typedef struct _VipsThreadProfile { + /*< private >*/ + + const char *name; + GThread *thread; + GHashTable *gates; +} VipsThreadProfile; + gboolean vips__thread_profile = FALSE; static GPrivate *vips_thread_profile_key = NULL; diff --git a/tools/vipsprofile.py b/tools/vipsprofile.py index 22d37ad5..483ce9f4 100755 --- a/tools/vipsprofile.py +++ b/tools/vipsprofile.py @@ -31,24 +31,25 @@ def read_times(rf): match = re.match('[0-9]+ ', rf.line) if not match: break - times.append([int(x) for x in re.split(' ', rf.line.rstrip())]) + times += [int(x) for x in re.split(' ', rf.line.rstrip())] rf.getnext() return times[::-1] class Event: - def __init__(self, thread_name, thread_addr, gate_name, start, end): + def __init__(self, thread_name, thread_addr, gate_name, start, stop): self.thread_name = thread_name self.thread_addr = thread_addr self.gate_name = gate_name self.start = start - self.end = end + self.stop = stop if re.match(': work', gate_name): self.work = True if re.match(': wait', gate_name): self.wait = True +events = [] with ReadFile('vips-profile.txt') as rf: while rf: match = re.match('thread: (.*) \(0x([0-9a-f]+)\)', rf.line) @@ -81,3 +82,11 @@ with ReadFile('vips-profile.txt') as rf: if len(start) != len(stop): print 'start and stop length mismatch' + + for a, b in zip(start, stop): + event = Event(thread_name, thread_addr, gate_name, a, b) + events.append(event) + +events.sort(lambda x, y: cmp(x.start, y.start)) + +print 'loaded %d events' % len(events)