diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-17 17:49:55 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-17 18:17:15 +0000 |
commit | f75cac946af9cc2ea87147f9a9b787f26263750d (patch) | |
tree | 113a1dd779700bfba0a23519a522789dd1d75bca | |
parent | e2dfba3be4d4103cee944be98848ab52506231bf (diff) |
Use zlib for reading.
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | src/app.c | 365 |
2 files changed, 184 insertions, 183 deletions
diff --git a/Makefile.am b/Makefile.am index 3af82a8..9ce9953 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,7 +41,7 @@ odin_SOURCES = src/odin.h \ src/minibfd/elfparser.h\ src/minibfd/elfparser.c odin_CFLAGS = @ODIN_CFLAGS@ @gtk_CFLAGS@ -DLIBDIR="\"$(odinlibdir)\"" -odin_LDADD = @gtk_LIBS@ +odin_LDADD = @gtk_LIBS@ -lz odin_DEPENDENCIES = lwp.so lwp_la_SOURCES = src/lwp-events.h \ @@ -26,6 +26,7 @@ #include <glibtop/procstate.h> #include <glibtop/close.h> #include <glib/gstdio.h> +#include <zlib.h> #include <string.h> #include <unistd.h> @@ -114,35 +115,18 @@ client_perm_alloc (Client *client, guint size) } static gboolean -readn (int fd, gpointer data, gsize len) +readn (gzFile *file, gpointer data, gint len) { - while (len) { - int ret = read (fd, data, len); - if (ret == 0) - return FALSE; - if (ret == -1) { - switch (errno) { - case EINTR: - case EAGAIN: - continue; - default: - return FALSE; - } - } - len -= ret; - data = (char *) data + ret; - } - - return TRUE; + return gzread (file, data, len) == len; } static gboolean -discardn (int fd, guint len) +discardn (gzFile *file, guint len) { char buf[1024]; do { guint n = len > G_N_ELEMENTS (buf) ? G_N_ELEMENTS (buf) : len; - if (! readn (fd, buf, n)) + if (! readn (file, buf, n)) return FALSE; len -= n; } while (len); @@ -151,22 +135,22 @@ discardn (int fd, guint len) } static gboolean -discard_string (int fd) +discard_string (gzFile *file) { gint len; - if (! readn (fd, &len, sizeof (len))) + if (! readn (file, &len, sizeof (len))) return FALSE; - return discardn (fd, len); + return discardn (file, len); } static gboolean -read_string (int fd, gchar **bp, guint *rem, gchar **str) +read_string (gzFile *file, gchar **bp, guint *rem, gchar **str) { gushort len; - if (! readn (fd, &len, sizeof (len))) + if (! readn (file, &len, sizeof (len))) return FALSE; if (len) { @@ -177,7 +161,7 @@ read_string (int fd, gchar **bp, guint *rem, gchar **str) *bp += len + 1; *rem -= len + 1; } - if (! readn (fd, *str, len)) + if (! readn (file, *str, len)) return FALSE; (*str)[len] = '\0'; } else @@ -197,21 +181,21 @@ _client_get_allocator (Client *client, gulong key) } static gboolean -discard_allocator_time (int fd) +discard_allocator_time (gzFile *file) { AllocatorTime At; - if (! readn (fd, &At.bytes, sizeof (At.bytes)) || - ! readn (fd, &At.freed, sizeof (At.freed)) || - ! readn (fd, &At.max_size, sizeof (At.max_size)) || - ! readn (fd, &At.n_allocs, sizeof (At.n_allocs)) || - ! readn (fd, &At.n_reallocs, sizeof (At.n_reallocs)) || - ! readn (fd, &At.n_frees, sizeof (At.n_frees)) || - ! readn (fd, &At.n_realloced_blocks, sizeof (At.n_realloced_blocks)) || - ! readn (fd, &At.peak_blocks, sizeof (At.peak_blocks)) || - ! readn (fd, &At.peak_bytes, sizeof (At.peak_bytes)) || - ! readn (fd, &At.size_allocs, sizeof (At.size_allocs)) || - ! readn (fd, &At.faults.tid, sizeof (At.faults.tid))) + if (! readn (file, &At.bytes, sizeof (At.bytes)) || + ! readn (file, &At.freed, sizeof (At.freed)) || + ! readn (file, &At.max_size, sizeof (At.max_size)) || + ! readn (file, &At.n_allocs, sizeof (At.n_allocs)) || + ! readn (file, &At.n_reallocs, sizeof (At.n_reallocs)) || + ! readn (file, &At.n_frees, sizeof (At.n_frees)) || + ! readn (file, &At.n_realloced_blocks, sizeof (At.n_realloced_blocks)) || + ! readn (file, &At.peak_blocks, sizeof (At.peak_blocks)) || + ! readn (file, &At.peak_bytes, sizeof (At.peak_bytes)) || + ! readn (file, &At.size_allocs, sizeof (At.size_allocs)) || + ! readn (file, &At.faults.tid, sizeof (At.faults.tid))) { return FALSE; } @@ -220,8 +204,8 @@ discard_allocator_time (int fd) if (At.faults.tid != 0) { ThreadFaults *f = &At.faults; - if (! readn (fd, &f->fault_cnt, sizeof (f->fault_cnt)) || - ! readn (fd, &f->n_faults, sizeof (f->n_faults))) + if (! readn (file, &f->fault_cnt, sizeof (f->fault_cnt)) || + ! readn (file, &f->n_faults, sizeof (f->n_faults))) { return FALSE; } @@ -229,14 +213,14 @@ discard_allocator_time (int fd) do { guint tid; - if (! readn (fd, &tid, sizeof (tid))) + if (! readn (file, &tid, sizeof (tid))) return FALSE; if (tid == 0) break; - if (! readn (fd, &f->fault_cnt, sizeof (f->fault_cnt)) || - ! readn (fd, &f->n_faults, sizeof (f->n_faults))) + if (! readn (file, &f->fault_cnt, sizeof (f->fault_cnt)) || + ! readn (file, &f->n_faults, sizeof (f->n_faults))) { return FALSE; } @@ -283,7 +267,7 @@ _client_add_allocator (Client *c, Allocator *A) } static Allocator * -read_allocator (App *app, int fd, guint time) +read_allocator (App *app, gzFile *file, guint time) { gulong key; Allocator *A; @@ -293,13 +277,13 @@ read_allocator (App *app, int fd, guint time) guint n; guint total; - if (! readn (fd, &key, sizeof (key))) + if (! readn (file, &key, sizeof (key))) return NULL; - if (! readn (fd, &magic, sizeof (magic)) || magic != 0xdeadbeef) + if (! readn (file, &magic, sizeof (magic)) || magic != 0xdeadbeef) return NULL; - if (! readn (fd, &last, sizeof (last))) + if (! readn (file, &last, sizeof (last))) return NULL; A = _client_get_allocator (&app->client, key); @@ -310,13 +294,13 @@ read_allocator (App *app, int fd, guint time) At = &A->time[0]; A->time_tail = NULL; - if (! readn (fd, &A->n_frames, sizeof (A->n_frames))) + if (! readn (file, &A->n_frames, sizeof (A->n_frames))) return NULL; A->frames = client_perm_alloc (&app->client, sizeof (Frame *) * A->n_frames); - if (! readn (fd, A->frames, A->n_frames * sizeof (gulong))) + if (! readn (file, A->frames, A->n_frames * sizeof (gulong))) return NULL; for (n = 0; n < A->n_frames; n++) { @@ -331,7 +315,7 @@ read_allocator (App *app, int fd, guint time) g_assert (A->time_tail->time < time); if (last <= A->time_tail->time) - return discard_allocator_time (fd) ? A : NULL; + return discard_allocator_time (file) ? A : NULL; At = client_perm_alloc (&app->client, sizeof (AllocatorTime)); A->time_tail->next = At; @@ -342,17 +326,17 @@ read_allocator (App *app, int fd, guint time) At->time = time; - if (! readn (fd, &At->bytes, sizeof (At->bytes)) || - ! readn (fd, &At->freed, sizeof (At->freed)) || - ! readn (fd, &At->max_size, sizeof (At->max_size)) || - ! readn (fd, &At->n_allocs, sizeof (At->n_allocs)) || - ! readn (fd, &At->n_reallocs, sizeof (At->n_reallocs)) || - ! readn (fd, &At->n_frees, sizeof (At->n_frees)) || - ! readn (fd, &At->n_realloced_blocks, sizeof (At->n_realloced_blocks)) || - ! readn (fd, &At->peak_blocks, sizeof (At->peak_blocks)) || - ! readn (fd, &At->peak_bytes, sizeof (At->peak_bytes)) || - ! readn (fd, &At->size_allocs, sizeof (At->size_allocs)) || - ! readn (fd, &At->faults.tid, sizeof (At->faults.tid))) + if (! readn (file, &At->bytes, sizeof (At->bytes)) || + ! readn (file, &At->freed, sizeof (At->freed)) || + ! readn (file, &At->max_size, sizeof (At->max_size)) || + ! readn (file, &At->n_allocs, sizeof (At->n_allocs)) || + ! readn (file, &At->n_reallocs, sizeof (At->n_reallocs)) || + ! readn (file, &At->n_frees, sizeof (At->n_frees)) || + ! readn (file, &At->n_realloced_blocks, sizeof (At->n_realloced_blocks)) || + ! readn (file, &At->peak_blocks, sizeof (At->peak_blocks)) || + ! readn (file, &At->peak_bytes, sizeof (At->peak_bytes)) || + ! readn (file, &At->size_allocs, sizeof (At->size_allocs)) || + ! readn (file, &At->faults.tid, sizeof (At->faults.tid))) { return NULL; } @@ -369,8 +353,8 @@ read_allocator (App *app, int fd, guint time) At->faults.next = NULL; if (At->faults.tid != 0) { ThreadFaults *f = &At->faults; - if (! readn (fd, &f->fault_cnt, sizeof (f->fault_cnt)) || - ! readn (fd, &f->n_faults, sizeof (f->n_faults))) + if (! readn (file, &f->fault_cnt, sizeof (f->fault_cnt)) || + ! readn (file, &f->n_faults, sizeof (f->n_faults))) { return NULL; } @@ -378,7 +362,7 @@ read_allocator (App *app, int fd, guint time) do { guint tid; - if (! readn (fd, &tid, sizeof (tid))) + if (! readn (file, &tid, sizeof (tid))) return NULL; if (tid == 0) @@ -388,8 +372,8 @@ read_allocator (App *app, int fd, guint time) f = f->next; f->tid = tid; - if (! readn (fd, &f->fault_cnt, sizeof (f->fault_cnt)) || - ! readn (fd, &f->n_faults, sizeof (f->n_faults))) + if (! readn (file, &f->fault_cnt, sizeof (f->fault_cnt)) || + ! readn (file, &f->n_faults, sizeof (f->n_faults))) { return NULL; } @@ -434,7 +418,7 @@ _client_block_alloc (Client *client) } static Block * -read_block (Client *client, int fd, Block *blocks) +read_block (Client *client, gzFile *file, Block *blocks) { Block *b; gulong addr; @@ -443,10 +427,10 @@ read_block (Client *client, int fd, Block *blocks) Allocator *A; guint age; - if (! readn (fd, &addr, sizeof (addr)) || - ! readn (fd, &size, sizeof (size)) || - ! readn (fd, &age, sizeof (age)) || - ! readn (fd, &allocator, sizeof (allocator))) + if (! readn (file, &addr, sizeof (addr)) || + ! readn (file, &size, sizeof (size)) || + ! readn (file, &age, sizeof (age)) || + ! readn (file, &allocator, sizeof (allocator))) { return NULL; } @@ -680,35 +664,32 @@ app_update_client (App *app, Client *client, guint time) static gboolean -vg_read (GIOChannel *io, App *app) +vg_read (gzFile *file, App *app) { guint count; gushort len; - int fd; Block *blocks; gchar client[1024]; gint pid, time, exitcode; Chunk *c; - fd = g_io_channel_unix_get_fd (io); - - if (! readn (fd, client, 4) || strcmp (client, "MF0")) + if (! readn (file, client, 4) || strcmp (client, "MF0")) return FALSE; - if (! readn (fd, &len, sizeof (len))) + if (! readn (file, &len, sizeof (len))) return FALSE; g_return_val_if_fail ((guint) len < G_N_ELEMENTS (client), FALSE); - if (! readn (fd, client, len)) + if (! readn (file, client, len)) return FALSE; client[len] = '\0'; _app_set_client_name (app, client); - if (! readn (fd, &pid, sizeof (pid))) + if (! readn (file, &pid, sizeof (pid))) return FALSE; - if (! readn (fd, &exitcode, sizeof (exitcode))) + if (! readn (file, &exitcode, sizeof (exitcode))) return FALSE; - if (! readn (fd, &time, sizeof (time))) + if (! readn (file, &time, sizeof (time))) return FALSE; if (app->client.pid && pid && pid != app->client.pid) @@ -716,75 +697,75 @@ vg_read (GIOChannel *io, App *app) app->client.pid = pid; /* frames */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { gchar buf[4096], *bp = buf; gulong eip; - gchar *function, *object, *file, *directory; + gchar *function, *object, *name, *directory; gint line; guint rem = G_N_ELEMENTS (buf); - if (! readn (fd, &eip, sizeof (eip))) + if (! readn (file, &eip, sizeof (eip))) return FALSE; if (frames_has_ip (&app->client.frames, eip)) { - if (! discard_string (fd) || - ! discard_string (fd) || - ! discard_string (fd) || - ! discard_string (fd) || - ! discardn (fd, sizeof (line))) + if (! discard_string (file) || + ! discard_string (file) || + ! discard_string (file) || + ! discard_string (file) || + ! discardn (file, sizeof (line))) { return FALSE; } continue; } - function = object = file = directory = NULL; - if (! read_string (fd, &bp, &rem, &function) || - ! read_string (fd, &bp, &rem, &object) || - ! read_string (fd, &bp, &rem, &file) || - ! read_string (fd, &bp, &rem, &directory)) + function = object = name = directory = NULL; + if (! read_string (file, &bp, &rem, &function) || + ! read_string (file, &bp, &rem, &object) || + ! read_string (file, &bp, &rem, &name) || + ! read_string (file, &bp, &rem, &directory)) { if (function < buf || function > bp) g_free (function); if (object < buf || object > bp) g_free (object); - if (file < buf || file > bp) - g_free (file); + if (name < buf || name > bp) + g_free (name); if (directory < buf || directory > bp) g_free (directory); return FALSE; } - if (! readn (fd, &line, sizeof (line))) + if (! readn (file, &line, sizeof (line))) return FALSE; frames_add (&app->client.frames, eip, - object, function, file, directory, + object, function, name, directory, line); if (function < buf || function > bp) g_free (function); if (object < buf || object > bp) g_free (object); - if (file < buf || file > bp) - g_free (file); + if (name < buf || name > bp) + g_free (name); if (directory < buf || directory > bp) g_free (directory); } /* allocators */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { - Allocator *A = read_allocator (app, fd, time); + Allocator *A = read_allocator (app, file, time); if (A == NULL) return FALSE; } /* blocks */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; app_set_blocks (app, NULL); @@ -799,7 +780,7 @@ vg_read (GIOChannel *io, App *app) blocks = NULL; while (count--) { - Block *new_blocks = read_block (&app->client, fd, blocks); + Block *new_blocks = read_block (&app->client, file, blocks); if (new_blocks == NULL) return FALSE; @@ -808,7 +789,7 @@ vg_read (GIOChannel *io, App *app) /* events */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { @@ -817,10 +798,10 @@ vg_read (GIOChannel *io, App *app) gulong allocator; - if (! readn (fd, &c, sizeof (c)) || - ! readn (fd, &ev.base.time, sizeof (ev.base.time)) || - ! readn (fd, &ev.base.tid, sizeof (ev.base.tid)) || - ! readn (fd, &allocator, sizeof (allocator))) + if (! readn (file, &c, sizeof (c)) || + ! readn (file, &ev.base.time, sizeof (ev.base.time)) || + ! readn (file, &ev.base.tid, sizeof (ev.base.tid)) || + ! readn (file, &allocator, sizeof (allocator))) { return FALSE; } @@ -832,8 +813,8 @@ vg_read (GIOChannel *io, App *app) ev.type = c; switch (ev.type) { case ALLOC: - if (! readn (fd, &ev.alloc.addr, sizeof (ev.alloc.addr)) || - ! readn (fd, &ev.alloc.size, sizeof (ev.alloc.size))) + if (! readn (file, &ev.alloc.addr, sizeof (ev.alloc.addr)) || + ! readn (file, &ev.alloc.size, sizeof (ev.alloc.size))) { return FALSE; } @@ -841,18 +822,18 @@ vg_read (GIOChannel *io, App *app) break; case REALLOC: - if (! readn (fd, &ev.realloc.old_addr, sizeof (ev.realloc.old_addr)) || - ! readn (fd, &ev.realloc.old_size, sizeof (ev.realloc.old_size)) || - ! readn (fd, &ev.realloc.new_addr, sizeof (ev.realloc.new_addr)) || - ! readn (fd, &ev.realloc.new_size, sizeof (ev.realloc.new_size))) + if (! readn (file, &ev.realloc.old_addr, sizeof (ev.realloc.old_addr)) || + ! readn (file, &ev.realloc.old_size, sizeof (ev.realloc.old_size)) || + ! readn (file, &ev.realloc.new_addr, sizeof (ev.realloc.new_addr)) || + ! readn (file, &ev.realloc.new_size, sizeof (ev.realloc.new_size))) { return FALSE; } break; case DEALLOC: - if (! readn (fd, &ev.dealloc.addr, sizeof (ev.dealloc.addr)) || - ! readn (fd, &ev.dealloc.size, sizeof (ev.dealloc.size))) + if (! readn (file, &ev.dealloc.addr, sizeof (ev.dealloc.addr)) || + ! readn (file, &ev.dealloc.size, sizeof (ev.dealloc.size))) { return FALSE; } @@ -1118,13 +1099,18 @@ vg_events_server_cb (GIOChannel *source, if (condition & G_IO_IN) { GTcpSocket *client = gnet_tcp_socket_server_accept (app->vg_events); + GIOChannel *io; + int fd; + gzFile *file; gdk_window_set_cursor (app->window->window, app->busy_cursor); gdk_flush (); - if (vg_read (gnet_tcp_socket_get_io_channel (client), app) && - app->client.pid == 0) - { + io = gnet_unix_socket_get_io_channel (client); + fd = g_io_channel_unix_get_fd (io); + file = gzdopen (dup (fd), "r"); + + if (vg_read (file, app) && app->client.pid == 0) { call_graph_store_update_tree_model (app->client.call_graph); } @@ -1448,52 +1434,52 @@ _client_reset (Client *client, App *app) } static gboolean G_GNUC_UNUSED -lwp_discard (int fd) +lwp_discard (gzFile *file) { gushort count; /* symbols */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { - if (! discardn (fd, sizeof (gulong)) || - ! discard_string (fd) || - ! discard_string (fd) || - ! discard_string (fd) || - ! discard_string (fd) || - ! discardn (fd, sizeof (guint))) + if (! discardn (file, sizeof (gulong)) || + ! discard_string (file) || + ! discard_string (file) || + ! discard_string (file) || + ! discard_string (file) || + ! discardn (file, sizeof (guint))) { return FALSE; } } /* allocators */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { guint n_frames; - if (! discardn (fd, sizeof (gulong))) + if (! discardn (file, sizeof (gulong))) return FALSE; - if (! readn (fd, &n_frames, sizeof (n_frames))) + if (! readn (file, &n_frames, sizeof (n_frames))) return FALSE; - if (! discardn (fd, n_frames * sizeof (gulong))) + if (! discardn (file, n_frames * sizeof (gulong))) return FALSE; } /* events */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { gboolean ok = TRUE; LWP_EventRecord ev; char c; - ok &= readn (fd, &c, 1); ev.type = c; - ok &= discardn (fd, sizeof (ev.time)); - ok &= discardn (fd, sizeof (ev.allocator)); + ok &= readn (file, &c, 1); ev.type = c; + ok &= discardn (file, sizeof (ev.time)); + ok &= discardn (file, sizeof (ev.allocator)); switch (ev.type) { case LWP_INIT: @@ -1503,25 +1489,25 @@ lwp_discard (int fd) break; case LWP_MALLOC: - ok &= discardn (fd, sizeof (ev.event.malloc.size)); - ok &= discardn (fd, sizeof (ev.event.malloc.addr)); + ok &= discardn (file, sizeof (ev.event.malloc.size)); + ok &= discardn (file, sizeof (ev.event.malloc.addr)); break; case LWP_MEMALIGN: - ok &= discardn (fd, sizeof (ev.event.memalign.align)); - ok &= discardn (fd, sizeof (ev.event.memalign.size)); - ok &= discardn (fd, sizeof (ev.event.memalign.addr)); + ok &= discardn (file, sizeof (ev.event.memalign.align)); + ok &= discardn (file, sizeof (ev.event.memalign.size)); + ok &= discardn (file, sizeof (ev.event.memalign.addr)); break; case LWP_REALLOC: - ok &= discardn (fd, sizeof (ev.event.realloc.size)); - ok &= discardn (fd, sizeof (ev.event.realloc.old_addr)); - ok &= discardn (fd, sizeof (ev.event.realloc.new_addr)); + ok &= discardn (file, sizeof (ev.event.realloc.size)); + ok &= discardn (file, sizeof (ev.event.realloc.old_addr)); + ok &= discardn (file, sizeof (ev.event.realloc.new_addr)); break; case LWP_FREE: - ok &= discardn (fd, sizeof (ev.event.free.addr)); + ok &= discardn (file, sizeof (ev.event.free.addr)); break; } @@ -1533,33 +1519,30 @@ lwp_discard (int fd) } static gboolean -lwp_read (GIOChannel *io, App *app) +lwp_read (gzFile *file, App *app) { - int fd; gushort count; pid_t pid; guint32 time; gchar client[1024]; - fd = g_io_channel_unix_get_fd (io); - - if (! readn (fd, client, 4) || strcmp (client, "LWP")) + if (! readn (file, client, 4) || strcmp (client, "LWP")) return FALSE; - if (! readn (fd, &pid, sizeof (pid))) + if (! readn (file, &pid, sizeof (pid))) return FALSE; - if (! readn (fd, &time, sizeof (time))) + if (! readn (file, &time, sizeof (time))) return FALSE; if (app->client.pid && pid != app->client.pid) - return FALSE; /* XXX lwp_discard (fd); */ + return FALSE; /* XXX lwp_discard (file); */ app->client.pid = pid; app->client.type = LWP; /* new objects */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { @@ -1569,8 +1552,8 @@ lwp_read (GIOChannel *io, App *app) guint key; gboolean ok = TRUE; - ok &= readn (fd, &key, sizeof (key)); - ok &= read_string (fd, &bp, &rem, &name); + ok &= readn (file, &key, sizeof (key)); + ok &= read_string (file, &bp, &rem, &name); if (ok) shared_object_add (&app->client.objects, key, name); @@ -1583,7 +1566,7 @@ lwp_read (GIOChannel *io, App *app) } /* new symbols */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { @@ -1592,9 +1575,9 @@ lwp_read (GIOChannel *io, App *app) guint key; gulong offset; - if (! readn (fd, &eip, sizeof (eip)) || - ! readn (fd, &key, sizeof (key)) || - ! readn (fd, &offset, sizeof (offset))) + if (! readn (file, &eip, sizeof (eip)) || + ! readn (file, &key, sizeof (key)) || + ! readn (file, &offset, sizeof (offset))) { return FALSE; } @@ -1613,7 +1596,7 @@ lwp_read (GIOChannel *io, App *app) shared_objects_lookup_symbols (&app->client.objects); /* new allocators */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { @@ -1621,7 +1604,7 @@ lwp_read (GIOChannel *io, App *app) Allocator *A; guint n; - if (! readn (fd, &key, sizeof (key))) + if (! readn (file, &key, sizeof (key))) return FALSE; /* construct bare allocator... */ @@ -1633,13 +1616,13 @@ lwp_read (GIOChannel *io, App *app) A->time_tail = &A->time[0]; memset (A->time_tail, 0, sizeof (AllocatorTime)); - if (! readn (fd, &A->n_frames, sizeof (A->n_frames))) + if (! readn (file, &A->n_frames, sizeof (A->n_frames))) return FALSE; A->frames = client_perm_alloc (&app->client, sizeof (Frame *) * A->n_frames); - if (! readn (fd, A->frames, A->n_frames * sizeof (gulong))) + if (! readn (file, A->frames, A->n_frames * sizeof (gulong))) return FALSE; for (n = 0; n < A->n_frames; n++) { @@ -1653,7 +1636,7 @@ lwp_read (GIOChannel *io, App *app) } /* new events */ - if (! readn (fd, &count, sizeof (count))) + if (! readn (file, &count, sizeof (count))) return FALSE; while (count--) { @@ -1661,9 +1644,9 @@ lwp_read (GIOChannel *io, App *app) char c; Allocator *A = NULL; - if (! readn (fd, &c, 1) || - ! readn (fd, &ev.time, sizeof (ev.time)) || - ! readn (fd, &ev.allocator, sizeof (ev.allocator))) + if (! readn (file, &c, 1) || + ! readn (file, &ev.time, sizeof (ev.time)) || + ! readn (file, &ev.allocator, sizeof (ev.allocator))) { return FALSE; } @@ -1689,8 +1672,8 @@ lwp_read (GIOChannel *io, App *app) break; case LWP_MALLOC: - readn (fd, &ev.event.malloc.size, sizeof (ev.event.malloc.size)); - readn (fd, &ev.event.malloc.addr, sizeof (ev.event.malloc.addr)); + readn (file, &ev.event.malloc.size, sizeof (ev.event.malloc.size)); + readn (file, &ev.event.malloc.addr, sizeof (ev.event.malloc.addr)); _client_new_block (&app->client, A, ev.event.malloc.addr, @@ -1700,9 +1683,9 @@ lwp_read (GIOChannel *io, App *app) break; case LWP_MEMALIGN: - readn (fd, &ev.event.memalign.align, sizeof (ev.event.memalign.align)); - readn (fd, &ev.event.memalign.size, sizeof (ev.event.memalign.size)); - readn (fd, &ev.event.memalign.addr, sizeof (ev.event.memalign.addr)); + readn (file, &ev.event.memalign.align, sizeof (ev.event.memalign.align)); + readn (file, &ev.event.memalign.size, sizeof (ev.event.memalign.size)); + readn (file, &ev.event.memalign.addr, sizeof (ev.event.memalign.addr)); _client_new_block (&app->client, A, ev.event.memalign.addr, @@ -1713,9 +1696,9 @@ lwp_read (GIOChannel *io, App *app) case LWP_REALLOC: - readn (fd, &ev.event.realloc.size, sizeof (ev.event.realloc.size)); - readn (fd, &ev.event.realloc.old_addr, sizeof (ev.event.realloc.old_addr)); - readn (fd, &ev.event.realloc.new_addr, sizeof (ev.event.realloc.new_addr)); + readn (file, &ev.event.realloc.size, sizeof (ev.event.realloc.size)); + readn (file, &ev.event.realloc.old_addr, sizeof (ev.event.realloc.old_addr)); + readn (file, &ev.event.realloc.new_addr, sizeof (ev.event.realloc.new_addr)); _client_move_block (&app->client, A, ev.event.realloc.old_addr, @@ -1726,7 +1709,7 @@ lwp_read (GIOChannel *io, App *app) break; case LWP_FREE: - readn (fd, &ev.event.free.addr, sizeof (ev.event.free.addr)); + readn (file, &ev.event.free.addr, sizeof (ev.event.free.addr)); if (ev.event.free.addr != NULL) _client_delete_block (&app->client, A, @@ -1757,11 +1740,19 @@ lwp_events_server_cb (GIOChannel *source, if (condition & G_IO_IN) { GUnixSocket *client = gnet_unix_socket_server_accept (app->lwp_events); + GIOChannel *io; + int fd; + gzFile *file; gdk_window_set_cursor (app->window->window, app->busy_cursor); gdk_flush (); - lwp_read (gnet_unix_socket_get_io_channel (client), app); + io = gnet_unix_socket_get_io_channel (client); + fd = g_io_channel_unix_get_fd (io); + file = gzdopen (dup (fd), "r"); + + lwp_read (file, app); + gzclose (file); if (! app->client.terminated) { gtk_tree_view_set_model (ensure_procmap (app), @@ -2286,11 +2277,17 @@ int main GIOChannel *io = g_io_channel_new_file (client_argv[0], "r", NULL); if (io != NULL) { - have_allocators = lwp_read (io, &app); + gzFile *file; + + file = gzdopen (dup (g_io_channel_unix_get_fd (io)), "r"); + + have_allocators = lwp_read (file, &app); if (have_allocators) do { while (gtk_events_pending ()) gtk_main_iteration (); - } while (lwp_read (io, &app)); + } while (lwp_read (file, &app)); + + gzclose (file); g_io_channel_unref (io); } } @@ -2298,7 +2295,11 @@ int main GIOChannel *io = g_io_channel_new_file (client_argv[0], "r", NULL); if (io != NULL) { - have_allocators = vg_read (io, &app); + gzFile *file; + + file = gzdopen (dup (g_io_channel_unix_get_fd (io)), "r"); + have_allocators = vg_read (file, &app); + gzclose (file); g_io_channel_unref (io); } } |