diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-04 11:42:29 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-04 11:42:29 +0000 |
commit | 1bd9700c82f575a3661e7c2fa06ecb504bd5d0b9 (patch) | |
tree | f6cad79367539270ee1b547b6d96afb4d6bebb29 /src/app.c | |
parent | 37d9aeeaf8901e77a78529b12e5ad088e9d28908 (diff) |
Support reading/writing to LWP file.
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 47 |
1 files changed, 34 insertions, 13 deletions
@@ -1099,13 +1099,14 @@ vg_events_server_cb (GIOChannel *source, return TRUE; } -static void +static gboolean _get_pid_cmd (GPid pid, char *cmd, int len) { glibtop_proc_state proc_state; glibtop_get_proc_state (&proc_state, (pid_t) pid); strncpy (cmd, proc_state.cmd, len); + return cmd[0] != '\0'; } static Block * @@ -1402,8 +1403,10 @@ lwp_read (GIOChannel *io, App *app) if (! readn (fd, &time, sizeof (time))) return FALSE; - if (pid != app->client.pid) + if (app->client.pid && pid != app->client.pid) return FALSE; + app->client.pid = pid; + app->client.type = LWP; /* new symbols */ if (! readn (fd, &count, sizeof (count))) @@ -1581,7 +1584,8 @@ lwp_read (GIOChannel *io, App *app) app_set_blocks (app, app->client.blocks); if (app->client.pid) { - _get_pid_cmd (app->client.pid, client, G_N_ELEMENTS (client)); + if (! _get_pid_cmd (app->client.pid, client, G_N_ELEMENTS (client))) + strcpy (client, "«unknown»"); _app_set_client_name (app, client); } app_update_status (app); @@ -1920,8 +1924,8 @@ execute_cmdline_lwp (App *app, char **argv, GError **error) else envp[n] = g_strconcat ("LD_PRELOAD=", preload, NULL); have_preload = TRUE; - } else if (strcmp (env[n], "LWP_SOCKET") == 0) { - envp[n] = g_strconcat ("LWP_SOCKET=", path, NULL); + } else if (strcmp (env[n], "LWP_PATH") == 0) { + envp[n] = g_strconcat ("LWP_PATH=unix:", path, NULL); have_socket = TRUE; } else envp[n] = g_strconcat (env[n], "=", g_getenv (env[n]), NULL); @@ -2047,15 +2051,32 @@ int main have_child = TRUE; if (client_argv != NULL) { gboolean have_allocators = FALSE; - GIOChannel *io = g_io_channel_new_file (client_argv[0], "r", NULL); - if (io != NULL) { - if (! vg_read (io, &app)) { - g_warning ("Failed to load allocations from '%s'", client_argv[0]); - } else { - call_graph_store_update_tree_model (app.client.call_graph); - have_allocators = TRUE; + if (g_file_test (client_argv[0], G_FILE_TEST_EXISTS && + ! g_file_test (client_argv[0], G_FILE_TEST_IS_EXECUTABLE))) { + if (have_allocators == FALSE){ + GIOChannel *io = g_io_channel_new_file (client_argv[0], + "r", NULL); + if (io != NULL) { + have_allocators = lwp_read (io, &app); + if (have_allocators) + while (lwp_read (io, &app)) + ; + g_io_channel_unref (io); + } } - g_io_channel_unref (io); + if (have_allocators == FALSE){ + GIOChannel *io = g_io_channel_new_file (client_argv[0], + "r", NULL); + if (io != NULL) { + have_allocators = vg_read (io, &app); + g_io_channel_unref (io); + } + } + if (have_allocators) + call_graph_store_update_tree_model (app.client.call_graph); + else + g_warning ("Failed to load allocations from '%s'", + client_argv[0]); } if (! have_allocators) { if (use_valgrind) |