Skip to content

[Stats] Interpret ru_maxrss differently by platform. #15621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Basic/Statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ getChildrenMaxResidentSetSize() {
struct rusage RU;
::getrusage(RUSAGE_CHILDREN, &RU);
int64_t M = static_cast<int64_t>(RU.ru_maxrss);
if (M < 0)
if (M < 0) {
M = std::numeric_limits<int64_t>::max();
} else {
#ifndef __APPLE__
// Apple systems report bytes; everything else appears to report KB.
M <<= 10;
#endif
}
return M;
#else
return 0;
Expand Down
18 changes: 18 additions & 0 deletions test/Misc/stats_dir_plausible_maxrss.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %empty-directory(%t)
// RUN: touch %t/main.swift
// RUN: %target-swiftc_driver -o %t/main -module-name main -stats-output-dir %t %t/main.swift
// RUN: %utils/process-stats-dir.py --set-csv-baseline %t/frontend.csv %t
// RUN: %FileCheck -input-file %t/frontend.csv %s

// This test checks that we're reporting some number that's "at least 10MB" and
// "not more than 999MB", because for a while we were incorrectly reporting KB
// as bytes on non-macOS, so claiming we took (say) "100KB". If we ever manage
// to get the swift frontend to use less than 10MB, celebrate! And change this
// test. Likewise (minus celebration) if compiling a function like the following
// ever takes more than 1GB.
//
// CHECK: {{"Driver.ChildrenMaxRSS" [1-9][0-9]{7,8}$}}

public func foo() {
print("hello")
}