|
39 | 39 | #ifdef HAVE_PROC_PID_RUSAGE |
40 | 40 | #include <libproc.h> |
41 | 41 | #endif |
42 | | -#ifdef HAVE_MALLOC_MALLOC_H |
43 | | -#include <malloc/malloc.h> |
44 | | -#endif |
45 | 42 | #if defined(_WIN32) |
46 | 43 | #define NOMINMAX |
47 | 44 | #include "Windows.h" |
@@ -536,25 +533,16 @@ FrontendStatsTracer::~FrontendStatsTracer() |
536 | 533 | // associated fields in the provided AlwaysOnFrontendCounters. |
537 | 534 | void updateProcessWideFrontendCounters( |
538 | 535 | UnifiedStatsReporter::AlwaysOnFrontendCounters &C) { |
539 | | - if (auto instrExecuted = getInstructionsExecuted()) { |
540 | | - C.NumInstructionsExecuted = instrExecuted; |
| 536 | +#if defined(HAVE_PROC_PID_RUSAGE) && defined(RUSAGE_INFO_V4) |
| 537 | + struct rusage_info_v4 ru; |
| 538 | + if (proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&ru) == 0) { |
| 539 | + C.NumInstructionsExecuted = ru.ri_instructions; |
| 540 | + C.MaxMallocUsage = ru.ri_lifetime_max_phys_footprint; |
| 541 | + return; |
541 | 542 | } |
542 | | - |
543 | | -#if defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H) |
544 | | - // On Darwin we have a lifetime max that's maintained by malloc we can |
545 | | - // just directly query, even if we only make one query on shutdown. |
546 | | - malloc_statistics_t Stats; |
547 | | - // Query all zones. |
548 | | - malloc_zone_statistics(/*zone=*/NULL, &Stats); |
549 | | - C.MaxMallocUsage = (int64_t)Stats.max_size_in_use; |
550 | | -#else |
551 | | - // If we don't have a malloc-tracked max-usage counter, we have to rely |
552 | | - // on taking the max over current-usage samples while running and hoping |
553 | | - // we get called often enough. This will happen when profiling/tracing, |
554 | | - // but not while doing single-query-on-shutdown collection. |
555 | | - C.MaxMallocUsage = std::max(C.MaxMallocUsage, |
556 | | - (int64_t)llvm::sys::Process::GetMallocUsage()); |
557 | 543 | #endif |
| 544 | + |
| 545 | + // FIXME: Do something useful when the above API is not available. |
558 | 546 | } |
559 | 547 |
|
560 | 548 | static inline void |
|
0 commit comments