Add simple malloc statistics and metrics
Add some basic statistics for allocated memory based on mallinfo(), and use that to define two metrics: usedAfterOverview: bytes used after the overview is shown once leakedAfterOverview: additional bytes used when the overview is shown a second time. https://bugzilla.gnome.org/show_bug.cgi?id=618189
This commit is contained in:
@ -38,12 +38,14 @@
|
||||
#include <gjs/gjs.h>
|
||||
#include <girepository.h>
|
||||
#include <gmodule.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "display.h"
|
||||
|
||||
#include "shell-global-private.h"
|
||||
#include "shell-perf-log.h"
|
||||
#include "shell-wm.h"
|
||||
#include "st.h"
|
||||
|
||||
@ -232,6 +234,50 @@ settings_notify_cb (GtkSettings *settings,
|
||||
update_font_options (settings);
|
||||
}
|
||||
|
||||
static void
|
||||
malloc_statistics_callback (ShellPerfLog *perf_log,
|
||||
gpointer data)
|
||||
{
|
||||
struct mallinfo info = mallinfo ();
|
||||
|
||||
shell_perf_log_update_statistic_i (perf_log,
|
||||
"malloc.arenaSize",
|
||||
info.arena);
|
||||
shell_perf_log_update_statistic_i (perf_log,
|
||||
"malloc.mmapSize",
|
||||
info.hblkhd);
|
||||
shell_perf_log_update_statistic_i (perf_log,
|
||||
"malloc.usedSize",
|
||||
info.uordblks);
|
||||
}
|
||||
|
||||
static void
|
||||
add_statistics (GnomeShellPlugin *shell_plugin)
|
||||
{
|
||||
ShellPerfLog *perf_log = shell_perf_log_get_default ();
|
||||
|
||||
/* For probably historical reasons, mallinfo() defines the returned values,
|
||||
* even those in bytes as int, not size_t. We're determined not to use
|
||||
* more than 2G of malloc'ed memory, so are OK with that.
|
||||
*/
|
||||
shell_perf_log_define_statistic (perf_log,
|
||||
"malloc.arenaSize",
|
||||
"Amount of memory allocated by malloc() with brk(), in bytes",
|
||||
"i");
|
||||
shell_perf_log_define_statistic (perf_log,
|
||||
"malloc.mmapSize",
|
||||
"Amount of memory allocated by malloc() with mmap(), in bytes",
|
||||
"i");
|
||||
shell_perf_log_define_statistic (perf_log,
|
||||
"malloc.usedSize",
|
||||
"Amount of malloc'ed memory currently in use",
|
||||
"i");
|
||||
|
||||
shell_perf_log_add_statistics_callback (perf_log,
|
||||
malloc_statistics_callback,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
gnome_shell_plugin_start (MutterPlugin *plugin)
|
||||
{
|
||||
@ -280,6 +326,8 @@ gnome_shell_plugin_start (MutterPlugin *plugin)
|
||||
_shell_global_set_plugin (global, MUTTER_PLUGIN(shell_plugin));
|
||||
_shell_global_set_gjs_context (global, shell_plugin->gjs_context);
|
||||
|
||||
add_statistics (shell_plugin);
|
||||
|
||||
if (!gjs_context_eval (shell_plugin->gjs_context,
|
||||
"const Main = imports.ui.main; Main.start();",
|
||||
-1,
|
||||
|
Reference in New Issue
Block a user