Skip to content

Commit 4a7ff2d

Browse files
authored
Merge pull request #171 from jtpio/enable-pss
Use `pss` if available
2 parents 1a5daf7 + 52fa6e1 commit 4a7ff2d

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ causes "lag"/pauses in the UI. To workaround this you can disable Prometheus met
105105

106106
## Resources Displayed
107107

108-
Currently the server extension only reports memory usage (just RSS) and CPU usage. Other metrics will be
109-
added in the future as needed.
108+
Currently the server extension only reports memory usage and CPU usage. Other metrics will be added in the future as needed.
109+
110+
Memory usage will show the PSS whenever possible (Linux only feature), and default to RSS otherwise.
110111

111112
The notebook extension currently doesn't show CPU usage, only memory usage.
112113

jupyter_resource_usage/api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,30 @@ async def get(self):
4242

4343
# Get memory information
4444
rss = 0
45+
pss = None
4546
for p in all_processes:
4647
try:
47-
rss += p.memory_info().rss
48+
info = p.memory_full_info()
49+
if hasattr(info, "pss"):
50+
pss = (pss or 0) + info.pss
51+
rss += info.rss
4852
except (psutil.NoSuchProcess, psutil.AccessDenied) as e:
4953
pass
5054

5155
if callable(config.mem_limit):
52-
mem_limit = config.mem_limit(rss=rss)
56+
mem_limit = config.mem_limit(rss=rss, pss=pss)
5357
else: # mem_limit is an Int
5458
mem_limit = config.mem_limit
5559

56-
limits = {"memory": {"rss": mem_limit}}
60+
limits = {"memory": {"rss": mem_limit, "pss": mem_limit}}
5761
if config.mem_limit and config.mem_warning_threshold != 0:
5862
limits["memory"]["warn"] = (mem_limit - rss) < (
5963
mem_limit * config.mem_warning_threshold
6064
)
6165

6266
metrics = {"rss": rss, "limits": limits}
67+
if pss is not None:
68+
metrics["pss"] = pss
6369

6470
# Optionally get CPU information
6571
if config.track_cpu_percent:

jupyter_resource_usage/static/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ define([
5353
$.getJSON({
5454
url: utils.get_body_data('baseUrl') + 'api/metrics/v1',
5555
success: function (data) {
56-
totalMemoryUsage = humanFileSize(data['rss']);
56+
value = data['pss'] || data['rss'];
57+
totalMemoryUsage = humanFileSize(value);
5758

5859
var limits = data['limits'];
5960
var display = totalMemoryUsage;
6061

6162
if (limits['memory']) {
62-
if (limits['memory']['rss']) {
63-
maxMemoryUsage = humanFileSize(limits['memory']['rss']);
63+
limit = limits['memory']['pss'] ?? limits['memory']['rss'];
64+
if (limit) {
65+
maxMemoryUsage = humanFileSize(limit);
6466
display += " / " + maxMemoryUsage
6567
}
6668
if (limits['memory']['warn']) {

packages/labextension/src/memoryUsage.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,9 @@ export namespace MemoryUsage {
180180
this._units = 'B';
181181
this._warn = false;
182182
} else {
183-
const numBytes = value.rss;
184-
const memoryLimit = value.limits.memory
185-
? value.limits.memory.rss
186-
: null;
183+
const numBytes = value.pss ?? value.rss;
184+
const memoryLimits = value.limits.memory;
185+
const memoryLimit = memoryLimits?.pss ?? memoryLimits?.rss ?? null;
187186
const [currentMemory, units] = convertToLargestUnit(numBytes);
188187
const usageWarning = value.limits.memory
189188
? value.limits.memory.warn
@@ -260,9 +259,11 @@ namespace Private {
260259
*/
261260
export interface IMetricRequestResult {
262261
rss: number;
262+
pss?: number;
263263
limits: {
264264
memory?: {
265265
rss: number;
266+
pss?: number;
266267
warn: boolean;
267268
};
268269
};

0 commit comments

Comments
 (0)