coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

physmem: a new program to report memory information


From: Assaf Gordon
Subject: physmem: a new program to report memory information
Date: Thu, 30 Aug 2012 11:35:30 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4

Hello,

Related to the previous sort+memory envvar usage thread: 
http://thread.gmane.org/gmane.comp.gnu.coreutils.general/3028/focus=3090 .

Attached is a suggestion for a tiny command-line program "physmem", that 
similarly to "nproc", exposes the gnulib functions "physmem_total()" and 
"physmem_available()".

The code is closely modeled after nproc, and the "recommended" memory usage is 
calculated using sort's default_sort_size() .

The program works like this:
===
$ ./src/physmem --help
Usage: ./src/physmem [OPTION]...
Prints information about physical memory.

  -t, --total           print the total physical memory.
  -a, --available       print the available physical memory.
  -r, --recommended     print a safe recommended amount of useable memory.
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --si              like -h, but use powers of 1000 not 1024
      --help     display this help and exit
      --version  output version information and exit

Report physmem bugs to address@hidden
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report physmem translation bugs to <http://translationproject.org/team/>
For complete documentation, run: info coreutils 'physmem invocation'
===

The actual working code (at the bottom of physmem.c) is:
===
  switch(memory_report_type)
    {
    case total:
      memory = physmem_total();
      break;

    case available:
      memory = physmem_available();
      break;

    case recommended:
      memory = default_sort_size();
      break;
    }

  char buf[LONGEST_HUMAN_READABLE + 1];
  fputs (human_readable (memory, buf, human_output_opts,1,1),stdout);
  fputs("\n", stdout);
===

So it's very simple, and rely on existing coreutils code.

Please let me know if this is something you'd be willing to include in 
coreutils.

Thanks,
 -gordon

Attachment: 0001-physmem-A-new-program-to-report-mem-information.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]