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

55
LINES

< > BotCompany Repo | #1019486 // Process List [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 6517K of libraries. Click here for Pure Java version (9427L/48K).

1  
!7
2  
3  
sclass Process {
4  
  S processID, name, commandLine;
5  
  long residentSize;
6  
  double cpuUsage; // percent per core
7  
  
8  
  sS _fieldOrder = "processID name commandLine residentSize cpuUsage";
9  
}
10  
11  
cm ProcessList > DynObjectTable<Process> {
12  
  switchable bool showTiming;
13  
  switchable double interval = 3.0;
14  
  switchable double firstInterval = 1.0;
15  
  switchable bool sortBySize;
16  
  
17  
  start {
18  
    dontPersist();
19  
    itemToMap = func(Process p) -> Map { humanizeKeys(
20  
      applyFunctionToMapValue('cpuUsage, f iround_spacePercentSign,
21  
      applyFunctionToMapValue('residentSize, f str_toM,
22  
        objectToMap_honorFieldOrder(p)))) };
23  
    actualUpdate(); // to make sort keys work
24  
    dm_doEvery(firstInterval, interval, r actualUpdate);
25  
    dm_reloadOnFieldChange interval();
26  
    dm_reloadOnFieldChange sortBySize();
27  
  }
28  
  
29  
  visualize {
30  
    JComponent c = centerAndSouthWithMargins(jSection(
31  
      dm_liveValue(() -> nProcesses(count())), super.visualize()),
32  
      dm_calculatedRightAlignedLabel(() -> "Updated every " + (interval == 1 ? "second" : formatDouble(interval, 1) + " seconds")));
33  
    
34  
    addRowSorter_desc(table, sortBySize ? 3 : 4); // Resident Size / CPU
35  
    var cmp = alphaNumComparator_skipCommas();
36  
    rowSorter_setComparators(table, 3, cmp, 2, cmp, 4, cmp);
37  
    swing { ((DefaultRowSorter) table.getRowSorter()).sort(); }
38  
    
39  
    tablePopupMenuItem(table(), "Kill!", rThread { killProcess(selected().processID) });
40  
    
41  
    ret c;
42  
  }
43  
  
44  
  void actualUpdate enter {
45  
    L<OSProcess> list = timedIf(showTiming, func -> L<OSProcess> { oshi_listProcesses_withoutOpenFiles() });
46  
    setData(map(list, func(OSProcess p) -> Process {
47  
      nu(Process,
48  
        processID := str(p.getProcessID()),
49  
        name := p.getName(),
50  
        commandLine := p.getCommandLine(),
51  
        residentSize := p.getResidentSetSize(),
52  
        cpuUsage := oshi_calcProcessCPUUsage_v2(p))
53  
    }));
54  
  }
55  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019486
Snippet name: Process List [Dyn Module]
Eternal ID of this version: #1019486/56
Text MD5: 83abd089a4aa62a61fe11d0029f8c903
Transpilation MD5: 7da9130f746c07d1a1a606d101abc6aa
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-14 09:09:05
Source code size: 1946 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 481 / 173061
Version history: 55 change(s)
Referenced in: [show references]