diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 2 | ||||
| -rw-r--r-- | src/alloc.c | 33 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 541697c5567..87a8f1c7814 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -9,6 +9,8 @@ (decode_coding_big5, decode_coding_charset, decode_coding) (encode_coding): Adjust users. + * alloc.c (Fmemory_info): New function. + 2014-07-09 Paul Eggert <eggert@cs.ucla.edu> * syntax.c (back_comment): Use more-natural location for label. diff --git a/src/alloc.c b/src/alloc.c index 6eb2e756ed1..c535e836397 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -49,6 +49,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <verify.h> #include <execinfo.h> /* For backtrace. */ +#ifdef HAVE_LINUX_SYSINFO +#include <sys/sysinfo.h> +#endif + #if (defined ENABLE_CHECKING \ && defined HAVE_VALGRIND_VALGRIND_H \ && !defined USE_VALGRIND) @@ -6865,7 +6869,33 @@ gc_sweep (void) check_string_bytes (!noninteractive); } - +DEFUN ("memory-info", Fmemory_info, Smemory_info, 0, 0, 0, + doc: /* Return a list of (TOTAL-RAM FREE-RAM TOTAL-SWAP FREE-SWAP). +All values are in Kbytes. If there is no swap space, last two +values are zero. If the system is not supported, return nil. */) + (void) +{ +#ifdef HAVE_LINUX_SYSINFO + struct sysinfo si; + uintmax_t units; + + if (sysinfo (&si)) + emacs_abort (); +#ifdef LINUX_SYSINFO_UNIT + units = si.mem_unit; +#else + units = 1; +#endif + return list4i ((uintmax_t) si.totalram * units / 1024, + (uintmax_t) si.freeram * units / 1024, + (uintmax_t) si.totalswap * units / 1024, + (uintmax_t) si.freeswap * units / 1024); +#else /* not HAVE_LINUX_SYSINFO */ + /* FIXME: add more systems. */ + return Qnil; +#endif /* HAVE_LINUX_SYSINFO */ +} + /* Debugging aids. */ DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, 0, @@ -7204,6 +7234,7 @@ The time is in seconds as a floating point value. */); defsubr (&Spurecopy); defsubr (&Sgarbage_collect); defsubr (&Smemory_limit); + defsubr (&Smemory_info); defsubr (&Smemory_use_counts); defsubr (&Ssuspicious_object); |
