Get the file name from inode number.
* glibtop_machine.h, open.c, procmap.c: Get the file name from inode number.
This commit is contained in:
@@ -32,12 +32,15 @@
|
||||
|
||||
#include "safeio.h"
|
||||
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||
(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
|
||||
(1L << GLIBTOP_PROC_MAP_SIZE);
|
||||
static const unsigned long _glibtop_sysdeps_map_entry =
|
||||
(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM);
|
||||
static const unsigned long _glibtop_sysdeps_map_device =
|
||||
(1L << GLIBTOP_MAP_ENTRY_DEVICE) + (1L << GLIBTOP_MAP_ENTRY_INODE);
|
||||
|
||||
|
||||
/* Init function. */
|
||||
@@ -53,8 +56,8 @@ glibtop_init_proc_map_s (glibtop *server)
|
||||
glibtop_map_entry *
|
||||
glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
{
|
||||
int fd, i, nmaps;
|
||||
prmap_t *maps;
|
||||
int fd, i, nmaps, pr_err, heap;
|
||||
prxmap_t *maps;
|
||||
|
||||
/* A few defines, to make it shorter down there */
|
||||
|
||||
@@ -64,6 +67,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
# define OFFSET pr_off
|
||||
#endif
|
||||
|
||||
struct ps_prochandle *Pr;
|
||||
glibtop_map_entry *entry;
|
||||
struct stat inode;
|
||||
char buffer[BUFSIZ];
|
||||
@@ -71,7 +75,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
memset (buf, 0, sizeof (glibtop_proc_map));
|
||||
|
||||
#ifdef HAVE_PROCFS_H
|
||||
sprintf(buffer, "/proc/%d/map", (int)pid);
|
||||
sprintf(buffer, "/proc/%d/xmap", (int)pid);
|
||||
#else
|
||||
sprintf(buffer, "/proc/%d", (int)pid);
|
||||
#endif
|
||||
@@ -91,7 +95,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
return NULL;
|
||||
}
|
||||
maps = alloca(inode.st_size);
|
||||
nmaps = inode.st_size / sizeof(prmap_t);
|
||||
nmaps = inode.st_size / sizeof(prxmap_t);
|
||||
if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size)
|
||||
{
|
||||
glibtop_warn_io_r(server, "pread (%s)", buffer);
|
||||
@@ -105,7 +109,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
s_close(fd);
|
||||
return NULL;
|
||||
}
|
||||
maps = alloca((nmaps + 1) * sizeof(prmap_t));
|
||||
maps = alloca((nmaps + 1) * sizeof(prxmap_t));
|
||||
if(ioctl(fd, PIOCMAP, maps) < 0)
|
||||
{
|
||||
glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer);
|
||||
@@ -113,7 +117,6 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
s_close(fd);
|
||||
if(!(entry = glibtop_malloc_r(server,
|
||||
nmaps * sizeof(glibtop_map_entry))))
|
||||
return NULL;
|
||||
@@ -122,10 +125,22 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
buf->total = nmaps * sizeof(glibtop_map_entry);
|
||||
|
||||
memset(entry, 0, nmaps * sizeof(glibtop_map_entry));
|
||||
for(i = 0; i < nmaps; ++i)
|
||||
|
||||
if(server->machine.objname && server->machine.pgrab &&
|
||||
server->machine.pfree)
|
||||
Pr = (server->machine.pgrab)(pid, 1, &pr_err);
|
||||
for(heap = 0,i = 0; i < nmaps; ++i)
|
||||
{
|
||||
int len;
|
||||
|
||||
entry[i].start = maps[i].pr_vaddr;
|
||||
entry[i].end = maps[i].pr_vaddr + maps[i].pr_size;
|
||||
if(maps[i].pr_dev != PRNODEV)
|
||||
{
|
||||
entry[i].device = maps[i].pr_dev;
|
||||
entry[i].inode = maps[i].pr_ino;
|
||||
entry[i].flags |= _glibtop_sysdeps_map_device;
|
||||
}
|
||||
entry[i].offset = maps[i].OFFSET;
|
||||
if(maps[i].pr_mflags & MA_READ)
|
||||
entry[i].perm |= GLIBTOP_MAP_PERM_READ;
|
||||
@@ -138,7 +153,36 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
else
|
||||
entry[i].perm |= GLIBTOP_MAP_PERM_PRIVATE;
|
||||
entry[i].flags = _glibtop_sysdeps_map_entry;
|
||||
if(maps[i].pr_mflags & MA_ANON)
|
||||
{
|
||||
if(!heap)
|
||||
{
|
||||
++heap;
|
||||
strcpy(entry[i].filename, "[ heap ]");
|
||||
}
|
||||
else
|
||||
if(i == nmaps - 1)
|
||||
strcpy(entry[i].filename, "[ stack ]");
|
||||
else
|
||||
strcpy(entry[i].filename, "[ anon ]");
|
||||
entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
|
||||
}
|
||||
else
|
||||
if(Pr)
|
||||
{
|
||||
server->machine.objname(Pr, maps[i].pr_vaddr, buffer,
|
||||
BUFSIZ);
|
||||
if((len = resolvepath(buffer, entry[i].filename,
|
||||
GLIBTOP_MAP_FILENAME_LEN)) > 0)
|
||||
{
|
||||
entry[i].filename[len] = 0;
|
||||
entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Pr)
|
||||
server->machine.pfree(Pr);
|
||||
buf->flags = _glibtop_sysdeps_proc_map;
|
||||
s_close(fd);
|
||||
return entry;
|
||||
}
|
||||
|
Reference in New Issue
Block a user