Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1025540 // Parse /proc/.../smaps Spike

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (3311L/21K).

1  
!7
2  
3  
p {
4  
  int processID = nempty(args) ? parseInt(first(args)) : processID_int();
5  
  S text = loadTextFile("/proc/" + processID + "/smaps");
6  
  
7  
  S range = null;
8  
  new TreeMap<S, Long> rssByRange;
9  
  for (S s : lines(text)) {
10  
    S addr = regexpFirstGroupIC("^([0-9a-f]{1,16})-", s);
11  
    if (addr != null) {
12  
      addr = lpad(addr, 16, '0');
13  
      //print("Have address: " + addr);
14  
      S cleanedAddr = longToHex(parseUnsignedHexLong(addr) & ~((1L << 42)-1));
15  
      //range = takeFirst(/*7*/6, addr);
16  
      range = takeFirst(6, cleanedAddr);
17  
      continue;
18  
    } // else print("Not range: " + s);
19  
    S[] p = parseColonProperty_array(s);
20  
    if (eqic(first(p), "rss")) {
21  
      long size = parseFirstLong(p[1]);
22  
      if (size != 0)
23  
        rssByRange.put(range, getOrCreate_long(rssByRange, range) + size);
24  
    }
25  
  }
26  
  //pnl(rssByRange);
27  
  for (unpair S _range, long size : mapToPairs(rssByRange)) {
28  
    print("Address range " + rpad(_range, 16, 'x') + ": " + toK(size) + " MB");
29  
  }
30  
  L<Long> offendingRanges = ll(
31  
    toLong(rssByRange.get("000004")),
32  
    toLong(rssByRange.get("000008")),
33  
    toLong(rssByRange.get("000010")),
34  
    toLong(rssByRange.get("00007c")));
35  
  
36  
  long total = longSum(values(rssByRange));
37  
  long guess = total-longMin(offendingRanges)*3;
38  
  print("Pessimisticly guessed process size: " + toK(guess) + " MB");
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, whxojlpjdney

No comments. add comment

Snippet ID: #1025540
Snippet name: Parse /proc/.../smaps Spike
Eternal ID of this version: #1025540/38
Text MD5: 9fa45b5f997202a03ee74418088e86f4
Transpilation MD5: 7bcd7d151c473e280fdb73a4e6bd035f
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-03 13:14:26
Source code size: 1374 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 379 / 1262
Version history: 37 change(s)
Referenced in: [show references]