Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_mem_tracker.c
          +++ new/usr/src/tools/smatch/src/smatch_mem_tracker.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
  16   16   */
  17   17  
  18   18  #include "smatch.h"
  19   19  #include <unistd.h>
  20   20  
  21   21  static int my_id;
  22   22  
  23   23  static unsigned long max_size;
  24   24  
  25      -static void match_end_func(struct symbol *sym)
       25 +unsigned long get_mem_kb(void)
  26   26  {
  27   27          FILE *file;
  28   28          char buf[1024];
  29   29          unsigned long size;
  30   30  
  31   31          file = fopen("/proc/self/statm", "r");
  32   32          if (!file)
  33      -                return;
       33 +                return 0;
  34   34          fread(buf, 1, sizeof(buf), file);
  35   35          fclose(file);
  36   36  
  37   37          size = strtoul(buf, NULL, 10);
  38   38          size = size * sysconf(_SC_PAGESIZE) / 1024;
  39      -        if (size > max_size)
  40      -                max_size = size;
       39 +        return size;
  41   40  }
  42   41  
       42 +static void match_end_func(struct symbol *sym)
       43 +{
       44 +        unsigned long size;
       45 +
       46 +        if (option_mem) {
       47 +                size = get_mem_kb();
       48 +                if (size > max_size)
       49 +                        max_size = size;
       50 +        }
       51 +}
       52 +
  43   53  unsigned long get_max_memory(void)
  44   54  {
  45   55          return max_size;
  46   56  }
  47   57  
  48   58  void register_mem_tracker(int id)
  49   59  {
  50   60          my_id = id;
  51   61  
  52   62          add_hook(&match_end_func, END_FUNC_HOOK);
  53   63  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX