mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
Make sure parser->symbols is non-NULL after read_table()
Otherwise, we would read the file over and over. Also get the process name from /proc/pid/cmdline, falling back to /proc/pid/status if there is nothing there.
This commit is contained in:
13
elfparser.c
13
elfparser.c
@ -433,6 +433,10 @@ read_table (ElfParser *parser,
|
|||||||
int sym_size = bin_record_get_size (parser->sym_format);
|
int sym_size = bin_record_get_size (parser->sym_format);
|
||||||
int i, n_symbols;
|
int i, n_symbols;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
g_print ("elf: Reading table for %s\n", parser->filename? parser->filename : "<unknown>");
|
||||||
|
#endif
|
||||||
|
|
||||||
parser->n_symbols = sym_table->size / sym_size;
|
parser->n_symbols = sym_table->size / sym_size;
|
||||||
parser->symbols = g_new (ElfSym, parser->n_symbols);
|
parser->symbols = g_new (ElfSym, parser->n_symbols);
|
||||||
|
|
||||||
@ -505,7 +509,12 @@ read_table (ElfParser *parser,
|
|||||||
|
|
||||||
parser->sym_strings = str_table->offset;
|
parser->sym_strings = str_table->offset;
|
||||||
parser->n_symbols = n_symbols;
|
parser->n_symbols = n_symbols;
|
||||||
parser->symbols = g_renew (ElfSym, parser->symbols, parser->n_symbols);
|
|
||||||
|
/* Allocate space for at least one symbol, so that parser->symbols will be
|
||||||
|
* non-NULL. If it ends up being NULL, we will be parsing the file over and
|
||||||
|
* over.
|
||||||
|
*/
|
||||||
|
parser->symbols = g_renew (ElfSym, parser->symbols, parser->n_symbols + 1);
|
||||||
|
|
||||||
qsort (parser->symbols, parser->n_symbols, sizeof (ElfSym), compare_sym);
|
qsort (parser->symbols, parser->n_symbols, sizeof (ElfSym), compare_sym);
|
||||||
}
|
}
|
||||||
@ -583,7 +592,7 @@ elf_parser_lookup_symbol (ElfParser *parser,
|
|||||||
if (!parser->symbols)
|
if (!parser->symbols)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
g_print ("reading symbols\n");
|
g_print ("reading symbols at %p\n", parser);
|
||||||
#endif
|
#endif
|
||||||
read_symbols (parser);
|
read_symbols (parser);
|
||||||
}
|
}
|
||||||
|
|||||||
30
tracker.c
30
tracker.c
@ -80,8 +80,20 @@ static void
|
|||||||
fake_new_process (tracker_t *tracker, pid_t pid)
|
fake_new_process (tracker_t *tracker, pid_t pid)
|
||||||
{
|
{
|
||||||
char **lines;
|
char **lines;
|
||||||
|
gboolean done = FALSE;
|
||||||
|
|
||||||
if ((lines = get_lines ("/proc/%d/status", pid)))
|
if ((lines = get_lines ("/proc/%d/cmdline", pid)))
|
||||||
|
{
|
||||||
|
if (lines[0] && strlen (lines[0]) > 0)
|
||||||
|
{
|
||||||
|
tracker_add_process (tracker, pid, lines[0]);
|
||||||
|
done = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev (lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!done && (lines = get_lines ("/proc/%d/status", pid)))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -89,14 +101,18 @@ fake_new_process (tracker_t *tracker, pid_t pid)
|
|||||||
{
|
{
|
||||||
if (strncmp ("Name:", lines[i], 5) == 0)
|
if (strncmp ("Name:", lines[i], 5) == 0)
|
||||||
{
|
{
|
||||||
tracker_add_process (
|
char *name = g_strstrip (strchr (lines[i], ':') + 1);
|
||||||
tracker, pid, g_strstrip (strchr (lines[i], ':') + 1));
|
|
||||||
|
|
||||||
break;
|
if (strlen (name) > 0)
|
||||||
}
|
{
|
||||||
}
|
tracker_add_process (tracker, pid, name);
|
||||||
|
done = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_strfreev (lines);
|
g_strfreev (lines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user