77 Commits

Author SHA1 Message Date
Slava Pestov
9ac70ce728 Basic: Use getrusage() to read memory usage
On macOS 26, malloc_zone_statistics() always returns
a malloc_statistics_t with the max_size_in_use field
set to zero. This was an intentional change, so let's
remove calls to this API.

Instead, use the proc_pid_rusage() API and return the
ri_lifetime_max_phys_footprint field of rusage_info_v4.

Finally, remove the llvm::sys::Process::GetMallocUsage()
call on other platforms altogether. It returns the
current value and not the max value, so its misleading.
2025-11-11 20:02:20 -05:00
Anthony Latsis
e7b2bc0d08 Basic: Adjust condition for include after macro removal in upstream LLVM
`HAVE_SYS_RESOURCE_H` was removed in
https://github.com/llvm/llvm-project/pull/123288, so this header is no
longer included at this particular location on rebranch, which breaks
the Linux build, where it is not transitively included either.

Use the same condition as in the use site
(`getChildrenMaxResidentSetSize`) instead.

Also, don't wrap `HAVE_GETRUSAGE` in `defined()` in case it does get
defined to 0.
2025-05-28 23:02:15 +01:00
Ryan Mansfield
1001f9eb41 Add -print-zero-stats option and use it in ensure_no_astgen.swift
to verify ExportedSourceFileRequest == 0.

In release mode only non-zero stats are printed by default now.

Fix diagnostic when compiler is built without statistics support.
2024-10-15 23:11:15 -04:00
Slava Pestov
aee5852b29 Basic: Fix statistics output in noassert build
Fixes rdar://136679357
2024-09-26 13:17:15 -04:00
Slava Pestov
5025964c2e Basic: Don't print zero counters 2024-09-23 18:04:25 -04:00
Slava Pestov
c77fae3a2d Basic: Add -fine-grained-timers flag
By default, -stats-output-dir does not collect per-request timers and
counters, because of overhead.
2024-09-23 18:04:25 -04:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Pavel Yaskevich
bbe531c4ac [Basic] MaxMallocUsage statistic should cover all zones
Also for some reason passing `malloc_default_zone()` no longer
works, statistics return `0` use.
2023-09-08 16:25:36 -07:00
Hamish Knight
ffde684143 [Stats] Force the printing of 0 counters
This matches the behavior of `printAlwaysOnStatsAndTimers`,
which we use in a release build. This fixes the
diverging behavior, and ensures process-stats-dir
can handle comparing deltas between runs where
one of the runs had a 0 counter.
2023-05-22 14:55:17 +01:00
Evan Wilde
8112cda531 Updated F_Text and F_Append
These enum cases were also updated to OF_Text and OF_Append.
2021-06-23 14:29:52 -07:00
Alex Hoppen
7ce0e872b7 [Statistic] Refactor to make getInstructionsExecuted publically available 2021-05-20 16:02:41 +02:00
Alexis Laferrière
17e926e93b [Basic] Don't use defined(LLVM_ENABLE_STATS) as it can be set to 0
LLVM_ENABLE_STATS can be defined to 0 since
https://reviews.llvm.org/D91094.

rdar://73834542
2021-02-08 14:27:41 -08:00
Robert Widmann
638977454b Remove SharedTimer Infrastructure
Teach the UnifiedStatsReporter to directly construct
llvm::NamedRegionTimer for itself.
2020-07-16 17:35:50 -07:00
David Zarzycki
fae2c19edb NFC: Make SILType.h and SILDeclRef.h not depend on SIL/*.h
SILType and SILDeclRef do not actually need anything from SIL/*.h. Also,
a few dependencies can be pushed out of the headers into cpp files to
speed up incremental rebuilds.
2020-07-01 08:05:58 -04:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Slava Pestov
368d47429d Frontend: Remove coarse-grained dependency graph implementation 2020-04-29 16:55:53 -04:00
Mike Ash
cd2b54f74e Merge branch 'master' into master-rebranch 2020-01-24 11:30:32 -05:00
Hamish Knight
fe906574cd [Basic] Avoid reentrant stat collection
Currently `UnifiedStatsReporter::flushTracesAndProfiles`
can kick off requests when computing the source
ranges for collected entities, which will try to
record additional stats about the requests.

This currently happens to work without issue,
but #29289 bumped the counters down slightly such
that the vector storing the stats now performs a
re-allocation when we do a reentrant stat entry.
This then caused a use-after-free as we try to
continue iterating over the old buffer.

Fix this issue by refusing to record any new stats
while we're flushing out the ones we've already
recorded.
2020-01-23 16:43:18 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
David Ungar
200b181eb3 Renaming files -> CoarseGrained 2019-12-04 10:51:18 -08:00
Adrian Prantl
468b74bd70 Update Swift master-next for upstream llvm.org changes. 2019-10-21 13:31:31 -07:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Jason Mittertreiner
8998235ed6 Enable Child Memory Usage Tracking on Windows (#23686)
Windows requires a handle to get memory usage, so do a slight refactor
to collect the child's memory usage as it exits instead of as the parent
is cleaning up.
2019-03-30 18:54:30 -07:00
Graydon Hoare
5a563f59af [Stats] Add SWIFTC_MAXIMUM_DETERMINISM to inhibit parallelism everywhere. 2018-09-13 16:15:49 -07:00
Graydon Hoare
1c87229104 [Stats] Flush Stats profiles and tracers at SILModule lifecycle boundary. 2018-09-01 00:05:58 -07:00
Graydon Hoare
044157821e [Stats] Assert main-thread-only use of UnifiedStatsReporter. 2018-09-01 00:05:58 -07:00
Graydon Hoare
e7d0e0d47e [Stats] Only update process-wide counters for frontends. 2018-08-30 14:55:07 -07:00
Graydon Hoare
fb7e7eb028 [Stats] Add statistic for Frontend.MaxMallocUsage. 2018-08-30 14:54:26 -07:00
Graydon Hoare
a25dd40fb9 [Stats] Clear all timers on print, since they stopped self-clearing recently. 2018-08-25 01:24:24 -07:00
Saleem Abdulrasool
4aa137f789 Basic: guard inclusion of unistd.h on non-Unices
unistd.h is a Unix specific header.  Ensure that we do not try to include it on
non-unix environments (i.e. Windows).  This attempts to restore the Windows
build once again.
2018-08-21 09:48:59 -07:00
Graydon Hoare
fe5667a4b6 [Stats] Change NumInstructions to NumInstructionsExecuted, accept 0 when on VMs. 2018-08-16 13:19:36 -07:00
Graydon Hoare
bdb00fceb0 Add Frontend.NumInstructions statistic, populated on macOS by rusage_info_v4. 2018-08-11 23:28:57 -07:00
swift-ci
336e42ee2c Merge remote-tracking branch 'origin/master' into master-next 2018-05-17 15:09:01 -07:00
Graydon Hoare
dcbbafae6f <rdar://40182303> Fix typo in error message, on failure to write stats file. 2018-05-17 13:03:07 -07:00
swift-ci
115f220410 Merge remote-tracking branch 'origin/master' into master-next 2018-04-11 22:15:16 -07:00
Saleem Abdulrasool
a80dd5b963 Basic: attempt to repair inverted dependencies
When linking on Linux, we would fail with unresolved symbol references
to swift::FrontendStatsTracer::getTraceFormatter<T>. The use of the
types, which are defined in swiftSIL occur in swiftBasic.  Provide
inline definitions of the constructors which cause the dependency on
some environments (e.g. Linux).
2018-04-10 10:40:10 -07:00
swift-ci
e86e3d2ac9 Merge remote-tracking branch 'origin/master' into master-next 2018-03-30 11:09:01 -07:00
Graydon Hoare
4b76ac0f6c [Stats] Interpret ru_maxrss differently by platform. 2018-03-30 00:37:55 -07:00
swift-ci
bb170e0aaa Merge remote-tracking branch 'origin/master' into master-next 2018-03-13 14:11:25 -07:00
Sho Ikeda
eaf33e0998 [gardening][lib/Basic] Replace typedef with using 2018-03-13 13:46:38 +09:00
swift-ci
c2a6871095 Merge remote-tracking branch 'origin/master' into master-next 2018-02-21 19:28:52 -08:00
Graydon Hoare
628c446fe3 [Stats] Add -profile-stats-{events,entities} 2018-02-21 16:22:48 -08:00
Graydon Hoare
7fe97c77c5 [Stats] Permit negative counters and deltas. 2018-02-21 14:49:24 -08:00
Graydon Hoare
dd85e946e7 [Stats] Replace nonstandard SharedTimers with FrontendStatsTracers. 2018-02-21 14:49:24 -08:00
Graydon Hoare
819275945d [Stats] Replace RecursiveSharedTimer with FrontendStatsTracer. 2018-02-21 14:49:24 -08:00
Graydon Hoare
deabc3fe65 [Stats] Add a recursive-timers registry to UnifiedStatsReporter. 2018-02-21 14:49:24 -08:00
Graydon Hoare
5f01c19d8e [Stats] Add support for tracing protocol conformances. 2018-02-21 14:49:24 -08:00
Graydon Hoare
76b82accbc [Stats] Simplify FrontendStatsTracer uses and formatter-definitions. 2018-02-21 14:49:24 -08:00
Bob Wilson
ac1376a7ce master-next: Update Statistic initializers for LLVM r323999.
LLVM r323999 changed the Initialized field of llvm::Statistic from a
bool to std::atomic<bool>.
2018-02-04 18:58:38 -08:00