!7

sclass ModuleInfo {
  S name;
  long code, data;
}

module ModuleRAMSizes extends DynObjectTable<ModuleInfo> {
  start {
    itemToMap = func(ModuleInfo m) -> Map {
      litorderedmap(
        Name := m.name,
        "Code" := str_toK_questionMarkIfZero(m.code),
        "Data" := str_toK_questionMarkIfZero(m.data))
    };
    doEveryAndNow(60.0, r calcIt);
  }
  
  void calcIt {
    temp enter();
    new L<ModuleInfo> l;
    time "Calculate Module Sizes" {
      for (O mod : dm_listModules()) {
        long code = 0, data = 0;
        pcall-short { code = dm_moduleCodeSize(mod); }
        pcall-short { data = dm_moduleSize(mod); }
        l.add(nu(ModuleInfo,
          name := dm_moduleName(mod),
          +code,
          +data));
      }
    }
    setData(sortedByCalculatedFieldDesc(func(ModuleInfo m) { m.code+m.data }, l));
  }
}