summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoît Dejean <bdejean@src.gnome.org>2005-12-07 09:35:50 +0000
committerBenoît Dejean <bdejean@src.gnome.org>2005-12-07 09:35:50 +0000
commit79fc0e70c0ef8cfd54c12a049033e35b79aecc19 (patch)
treef4acbdf09ce82c7f63fc3f80486ee56455b4d087
parent532f5ceb4f39efb10c49095f512c2c793953c452 (diff)
downloadlibgtop-79fc0e70c0ef8cfd54c12a049033e35b79aecc19.tar.gz
Small improvements. Use g_array_sized_new instead of g_array_new with
* procmap.c: (glibtop_get_proc_map_s): Small improvements. Use g_array_sized_new instead of g_array_new with reserved_size = 100. Don't use g_array_append_val to avoid copying glibtop_map_entries. Use g_array_set_size(size + 1) instead. I've run a little python benchmark and this shows a little speedup. I hope this would be more sensible in gnome-system-monitor (glibtop_get_procmap is intensively used for the 'Writable Memory' column).
-rw-r--r--sysdeps/linux/ChangeLog15
-rw-r--r--sysdeps/linux/procmap.c40
2 files changed, 42 insertions, 13 deletions
diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog
index f1bb5b09..3c3d7e6a 100644
--- a/sysdeps/linux/ChangeLog
+++ b/sysdeps/linux/ChangeLog
@@ -1,3 +1,18 @@
+2005-12-07 Benoît Dejean <benoit@placenet.org>
+
+ * procmap.c: (glibtop_get_proc_map_s):
+
+ Small improvements.
+ Use g_array_sized_new instead of g_array_new with
+ reserved_size = 100.
+ Don't use g_array_append_val to avoid copying
+ glibtop_map_entries. Use g_array_set_size(size + 1) instead.
+
+ I've run a little python benchmark and this shows a little
+ speedup. I hope this would be more sensible in
+ gnome-system-monitor (glibtop_get_procmap is intensively used for
+ the 'Writable Memory' column).
+
2005-10-29 Benoît Dejean <benoit@placenet.org>
* glibtop_private.c: (read_boot_time):
diff --git a/sysdeps/linux/procmap.c b/sysdeps/linux/procmap.c
index e0088737..03a64c33 100644
--- a/sysdeps/linux/procmap.c
+++ b/sysdeps/linux/procmap.c
@@ -59,8 +59,15 @@ glibtop_map_entry *
glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
{
char procfilename[GLIBTOP_MAP_FILENAME_LEN+1];
- GArray *entry_list = g_array_new(FALSE, FALSE,
- sizeof(glibtop_map_entry));
+
+ /*
+ default size of 100 maybe inaccurate.
+ It's the average number of entry per process on my laptop
+ */
+
+ GArray *entry_list = g_array_sized_new(FALSE, FALSE,
+ sizeof(glibtop_map_entry),
+ 100);
FILE *maps;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
@@ -77,13 +84,14 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
{
unsigned long perm = 0;
int rv;
+ guint len;
unsigned short dev_major, dev_minor;
unsigned long start, end, offset, inode;
char flags[4];
char filename [GLIBTOP_MAP_FILENAME_LEN+1];
- glibtop_map_entry entry;
+ glibtop_map_entry *entry;
/* 8 arguments */
@@ -113,16 +121,22 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
else if (flags [3] == 'p')
perm |= GLIBTOP_MAP_PERM_PRIVATE;
- entry.flags = _glibtop_sysdeps_map_entry;
- entry.start = (guint64) start;
- entry.end = (guint64) end;
- entry.offset = (guint64) offset;
- entry.perm = (guint64) perm;
- entry.device = (guint64) MKDEV(dev_major, dev_minor);
- entry.inode = (guint64) inode;
- g_strlcpy (entry.filename, filename, sizeof entry.filename);
-
- g_array_append_val(entry_list, entry);
+ /*
+ avoid copying the entry, grow by 1 and point to the last
+ element.
+ */
+ len = entry_list->len;
+ g_array_set_size(entry_list, len + 1);
+ entry = &g_array_index(entry_list, glibtop_map_entry, len);
+
+ entry->flags = _glibtop_sysdeps_map_entry;
+ entry->start = (guint64) start;
+ entry->end = (guint64) end;
+ entry->offset = (guint64) offset;
+ entry->perm = (guint64) perm;
+ entry->device = (guint64) MKDEV(dev_major, dev_minor);
+ entry->inode = (guint64) inode;
+ g_strlcpy(entry->filename, filename, sizeof entry->filename);
}
fclose (maps);