mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
Move bin file cache to state object
This commit is contained in:
73
binfile.c
73
binfile.c
@ -258,9 +258,6 @@ get_debug_binaries (GList *files,
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static GHashTable *bin_files;
|
|
||||||
|
|
||||||
static char **
|
static char **
|
||||||
get_lines (const char *format, pid_t pid)
|
get_lines (const char *format, pid_t pid)
|
||||||
{
|
{
|
||||||
@ -331,59 +328,43 @@ get_vdso_bytes (size_t *length)
|
|||||||
BinFile *
|
BinFile *
|
||||||
bin_file_new (const char *filename)
|
bin_file_new (const char *filename)
|
||||||
{
|
{
|
||||||
/* FIXME: should be able to return an error */
|
ElfParser *elf = NULL;
|
||||||
BinFile *bf;
|
BinFile *bf;
|
||||||
|
|
||||||
if (!bin_files)
|
bf = g_new0 (BinFile, 1);
|
||||||
bin_files = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
|
|
||||||
bf = g_hash_table_lookup (bin_files, filename);
|
bf->inode_check = FALSE;
|
||||||
|
bf->filename = g_strdup (filename);
|
||||||
|
bf->undefined_name = g_strdup_printf ("In file %s", filename);
|
||||||
|
bf->ref_count = 1;
|
||||||
|
bf->elf_files = NULL;
|
||||||
|
|
||||||
if (bf)
|
if (strcmp (filename, "[vdso]") == 0)
|
||||||
{
|
{
|
||||||
bf->ref_count++;
|
const guint8 *vdso_bytes;
|
||||||
|
gsize length;
|
||||||
|
|
||||||
|
vdso_bytes = get_vdso_bytes (&length);
|
||||||
|
|
||||||
|
if (vdso_bytes)
|
||||||
|
elf = elf_parser_new_from_data (vdso_bytes, length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ElfParser *elf = NULL;
|
elf = elf_parser_new (filename, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
bf = g_new0 (BinFile, 1);
|
if (elf)
|
||||||
|
{
|
||||||
|
/* We need the text offset of the actual binary, not the
|
||||||
|
* (potential) debug binaries
|
||||||
|
*/
|
||||||
|
bf->text_offset = elf_parser_get_text_offset (elf);
|
||||||
|
|
||||||
bf->inode_check = FALSE;
|
bf->elf_files = get_debug_binaries (bf->elf_files, elf, filename);
|
||||||
bf->filename = g_strdup (filename);
|
bf->elf_files = g_list_append (bf->elf_files, elf);
|
||||||
bf->undefined_name = g_strdup_printf ("In file %s", filename);
|
|
||||||
bf->ref_count = 1;
|
|
||||||
bf->elf_files = NULL;
|
|
||||||
|
|
||||||
g_hash_table_insert (bin_files, bf->filename, bf);
|
bf->inode = read_inode (filename);
|
||||||
|
|
||||||
if (strcmp (filename, "[vdso]") == 0)
|
|
||||||
{
|
|
||||||
const guint8 *vdso_bytes;
|
|
||||||
gsize length;
|
|
||||||
|
|
||||||
vdso_bytes = get_vdso_bytes (&length);
|
|
||||||
|
|
||||||
if (vdso_bytes)
|
|
||||||
elf = elf_parser_new_from_data (vdso_bytes, length);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
elf = elf_parser_new (filename, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (elf)
|
|
||||||
{
|
|
||||||
/* We need the text offset of the actual binary, not the
|
|
||||||
* (potential) debug binaries
|
|
||||||
*/
|
|
||||||
bf->text_offset = elf_parser_get_text_offset (elf);
|
|
||||||
|
|
||||||
bf->elf_files = get_debug_binaries (bf->elf_files, elf, filename);
|
|
||||||
bf->elf_files = g_list_append (bf->elf_files, elf);
|
|
||||||
|
|
||||||
bf->inode = read_inode (filename);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bf;
|
return bf;
|
||||||
@ -394,8 +375,6 @@ bin_file_free (BinFile *bin_file)
|
|||||||
{
|
{
|
||||||
if (--bin_file->ref_count == 0)
|
if (--bin_file->ref_count == 0)
|
||||||
{
|
{
|
||||||
g_hash_table_remove (bin_files, bin_file->filename);
|
|
||||||
|
|
||||||
g_list_foreach (bin_file->elf_files, (GFunc)elf_parser_free, NULL);
|
g_list_foreach (bin_file->elf_files, (GFunc)elf_parser_free, NULL);
|
||||||
g_list_free (bin_file->elf_files);
|
g_list_free (bin_file->elf_files);
|
||||||
|
|
||||||
|
|||||||
21
tracker.c
21
tracker.c
@ -335,6 +335,7 @@ struct state_t
|
|||||||
GHashTable *processes_by_pid;
|
GHashTable *processes_by_pid;
|
||||||
GHashTable *unique_comms;
|
GHashTable *unique_comms;
|
||||||
GHashTable *unique_symbols;
|
GHashTable *unique_symbols;
|
||||||
|
GHashTable *bin_files;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -433,6 +434,9 @@ state_new (void)
|
|||||||
|
|
||||||
state->unique_symbols = g_hash_table_new (g_direct_hash, g_direct_equal);
|
state->unique_symbols = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
state->unique_comms = g_hash_table_new (g_str_hash, g_str_equal);
|
state->unique_comms = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
|
state->bin_files = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
|
g_free,
|
||||||
|
(GDestroyNotify)bin_file_free);
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@ -665,6 +669,21 @@ make_message (state_t *state, const char *format, ...)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BinFile *
|
||||||
|
state_get_bin_file (state_t *state, const char *filename)
|
||||||
|
{
|
||||||
|
BinFile *bf = g_hash_table_lookup (state->bin_files, filename);
|
||||||
|
|
||||||
|
if (!bf)
|
||||||
|
{
|
||||||
|
bf = bin_file_new (filename);
|
||||||
|
|
||||||
|
g_hash_table_insert (state->bin_files, g_strdup (filename), bf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bf;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
lookup_symbol (state_t *state,
|
lookup_symbol (state_t *state,
|
||||||
process_t *process,
|
process_t *process,
|
||||||
@ -695,7 +714,7 @@ lookup_symbol (state_t *state,
|
|||||||
address += map->offset;
|
address += map->offset;
|
||||||
|
|
||||||
if (!map->bin_file)
|
if (!map->bin_file)
|
||||||
map->bin_file = bin_file_new (map->filename);
|
map->bin_file = state_get_bin_file (state, map->filename);
|
||||||
|
|
||||||
if (map->inode && !bin_file_check_inode (map->bin_file, map->inode))
|
if (map->inode && !bin_file_check_inode (map->bin_file, map->inode))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user