mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
Make comm events reuse any existing process.
A comm event doesn't necessarily mean a new process was created. It may just mean that an existing process changed its command line.
This commit is contained in:
91
tracker.c
91
tracker.c
@ -291,6 +291,10 @@ tracker_append (tracker_t *tracker,
|
|||||||
|
|
||||||
memcpy (tracker->events + tracker->n_event_bytes, event, n_bytes);
|
memcpy (tracker->events + tracker->n_event_bytes, event, n_bytes);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
g_print (" (address %p)\n", tracker->events + tracker->n_event_bytes);
|
||||||
|
#endif
|
||||||
|
|
||||||
tracker->n_event_bytes += n_bytes;
|
tracker->n_event_bytes += n_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,6 +305,10 @@ tracker_add_process (tracker_t * tracker,
|
|||||||
{
|
{
|
||||||
new_process_t event;
|
new_process_t event;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
g_print ("Add new process %s %d to tracker ", command_line, pid);
|
||||||
|
#endif
|
||||||
|
|
||||||
event.header = MAKE_HEADER (NEW_PROCESS, pid);
|
event.header = MAKE_HEADER (NEW_PROCESS, pid);
|
||||||
COPY_STRING (event.command_line, command_line);
|
COPY_STRING (event.command_line, command_line);
|
||||||
|
|
||||||
@ -462,18 +470,28 @@ destroy_process (process_t *process)
|
|||||||
static void
|
static void
|
||||||
create_process (state_t *state, new_process_t *new_process)
|
create_process (state_t *state, new_process_t *new_process)
|
||||||
{
|
{
|
||||||
process_t *process = g_new0 (process_t, 1);
|
pid_t pid = GET_PID (new_process->header);
|
||||||
|
const char *comm = new_process->command_line;
|
||||||
|
|
||||||
process->pid = GET_PID (new_process->header);
|
process_t *process =
|
||||||
process->comm = g_strdup (new_process->command_line);
|
g_hash_table_lookup (state->processes_by_pid, GINT_TO_POINTER (pid));
|
||||||
process->maps = g_ptr_array_new ();
|
|
||||||
|
|
||||||
#if 0
|
if (process)
|
||||||
g_print ("new comm process %d\n", new_process->pid);
|
{
|
||||||
#endif
|
g_free (process->comm);
|
||||||
|
process->comm = g_strdup (comm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
process = g_new0 (process_t, 1);
|
||||||
|
|
||||||
g_hash_table_insert (
|
process->pid = pid;
|
||||||
state->processes_by_pid, GINT_TO_POINTER (process->pid), process);
|
process->comm = g_strdup (comm);
|
||||||
|
process->maps = g_ptr_array_new ();
|
||||||
|
|
||||||
|
g_hash_table_insert (
|
||||||
|
state->processes_by_pid, GINT_TO_POINTER (process->pid), process);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static map_t *
|
static map_t *
|
||||||
@ -490,52 +508,43 @@ copy_map (map_t *map)
|
|||||||
static void
|
static void
|
||||||
process_fork (state_t *state, fork_t *fork)
|
process_fork (state_t *state, fork_t *fork)
|
||||||
{
|
{
|
||||||
process_t *parent = g_hash_table_lookup (
|
pid_t ppid = GET_PID (fork->header);
|
||||||
state->processes_by_pid, GINT_TO_POINTER (GET_PID (fork->header)));
|
GPtrArray *maps;
|
||||||
|
|
||||||
if (GET_PID (fork->header) == fork->child_pid)
|
process_t *parent = g_hash_table_lookup (
|
||||||
|
state->processes_by_pid, GINT_TO_POINTER (ppid));
|
||||||
|
process_t *child;
|
||||||
|
|
||||||
|
if (ppid == fork->child_pid)
|
||||||
{
|
{
|
||||||
/* Just a new thread being spawned */
|
/* Just a new thread being spawned */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
child = g_new0 (process_t, 1);
|
||||||
|
if (parent)
|
||||||
|
child->comm = g_strdup (parent->comm);
|
||||||
|
else
|
||||||
|
child->comm = g_strdup_printf ("[pid %d]", fork->child_pid);
|
||||||
|
|
||||||
|
child->pid = fork->child_pid;
|
||||||
|
|
||||||
|
child->maps = g_ptr_array_new ();
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
process_t *process = g_new0 (process_t, 1);
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
#if 0
|
for (i = 0; i < parent->maps->len; ++i)
|
||||||
g_print ("new child %d\n", fork->child_pid);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
process->pid = fork->child_pid;
|
|
||||||
|
|
||||||
if (parent)
|
|
||||||
process->comm = g_strdup (parent->comm);
|
|
||||||
else
|
|
||||||
process->comm = g_strdup_printf ("<pid %d>", fork->child_pid);
|
|
||||||
|
|
||||||
process->maps = g_ptr_array_new ();
|
|
||||||
|
|
||||||
if (parent)
|
|
||||||
{
|
{
|
||||||
for (i = 0; i < parent->maps->len; ++i)
|
map_t *map = copy_map (parent->maps->pdata[i]);
|
||||||
{
|
|
||||||
map_t *map = copy_map (parent->maps->pdata[i]);
|
|
||||||
|
|
||||||
g_ptr_array_add (process->maps, map);
|
g_ptr_array_add (maps, map);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_insert (
|
|
||||||
state->processes_by_pid, GINT_TO_POINTER (process->pid), process);
|
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
else
|
g_hash_table_insert (
|
||||||
g_print ("no parent for %d\n", fork->child_pid);
|
state->processes_by_pid, GINT_TO_POINTER (child->pid), child);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user