Skip to content

Commit 5db2682

Browse files
authored
Merge pull request #15621 from graydon/stats-maxrss-kilobytes-are-not-bytes
[Stats] Interpret ru_maxrss differently by platform.
2 parents 0874ea4 + 4b76ac0 commit 5db2682

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Basic/Statistic.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ getChildrenMaxResidentSetSize() {
4545
struct rusage RU;
4646
::getrusage(RUSAGE_CHILDREN, &RU);
4747
int64_t M = static_cast<int64_t>(RU.ru_maxrss);
48-
if (M < 0)
48+
if (M < 0) {
4949
M = std::numeric_limits<int64_t>::max();
50+
} else {
51+
#ifndef __APPLE__
52+
// Apple systems report bytes; everything else appears to report KB.
53+
M <<= 10;
54+
#endif
55+
}
5056
return M;
5157
#else
5258
return 0;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: touch %t/main.swift
3+
// RUN: %target-swiftc_driver -o %t/main -module-name main -stats-output-dir %t %t/main.swift
4+
// RUN: %utils/process-stats-dir.py --set-csv-baseline %t/frontend.csv %t
5+
// RUN: %FileCheck -input-file %t/frontend.csv %s
6+
7+
// This test checks that we're reporting some number that's "at least 10MB" and
8+
// "not more than 999MB", because for a while we were incorrectly reporting KB
9+
// as bytes on non-macOS, so claiming we took (say) "100KB". If we ever manage
10+
// to get the swift frontend to use less than 10MB, celebrate! And change this
11+
// test. Likewise (minus celebration) if compiling a function like the following
12+
// ever takes more than 1GB.
13+
//
14+
// CHECK: {{"Driver.ChildrenMaxRSS" [1-9][0-9]{7,8}$}}
15+
16+
public func foo() {
17+
print("hello")
18+
}

0 commit comments

Comments
 (0)