Skip to content

Commit 7fe97c7

Browse files
committed
[Stats] Permit negative counters and deltas.
1 parent dd85e94 commit 7fe97c7

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

include/swift/Basic/Statistic.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ class UnifiedStatsReporter {
6666
public:
6767
struct AlwaysOnDriverCounters
6868
{
69-
#define DRIVER_STATISTIC(ID) size_t ID;
69+
#define DRIVER_STATISTIC(ID) int64_t ID;
7070
#include "Statistics.def"
7171
#undef DRIVER_STATISTIC
7272
};
7373

7474
struct AlwaysOnFrontendCounters
7575
{
76-
#define FRONTEND_STATISTIC(NAME, ID) size_t ID;
76+
#define FRONTEND_STATISTIC(NAME, ID) int64_t ID;
7777
#include "Statistics.def"
7878
#undef FRONTEND_STATISTIC
7979
};
@@ -98,8 +98,8 @@ class UnifiedStatsReporter {
9898
bool IsEntry;
9999
StringRef EventName;
100100
StringRef CounterName;
101-
size_t CounterDelta;
102-
size_t CounterValue;
101+
int64_t CounterDelta;
102+
int64_t CounterValue;
103103
const void *Entity;
104104
const TraceFormatter *Formatter;
105105
};

lib/Basic/Statistic.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Support/Process.h"
2626
#include "llvm/Support/raw_ostream.h"
2727
#include <chrono>
28+
#include <limits>
2829

2930
#ifdef HAVE_SYS_TIME_H
3031
#include <sys/time.h>
@@ -37,12 +38,15 @@ namespace swift {
3738
using namespace llvm;
3839
using namespace llvm::sys;
3940

40-
static size_t
41+
static int64_t
4142
getChildrenMaxResidentSetSize() {
4243
#if defined(HAVE_GETRUSAGE) && !defined(__HAIKU__)
4344
struct rusage RU;
4445
::getrusage(RUSAGE_CHILDREN, &RU);
45-
return RU.ru_maxrss;
46+
int64_t M = static_cast<int64_t>(RU.ru_maxrss);
47+
if (M < 0)
48+
M = std::numeric_limits<int64_t>::max();
49+
return M;
4650
#else
4751
return 0;
4852
#endif
@@ -377,8 +381,8 @@ UnifiedStatsReporter::saveAnyFrontendStatsEvents(
377381
auto &C = getFrontendCounters();
378382
#define FRONTEND_STATISTIC(TY, NAME) \
379383
do { \
380-
auto total = C.NAME; \
381-
auto delta = C.NAME - LastTracedFrontendCounters->NAME; \
384+
int64_t total = C.NAME; \
385+
int64_t delta = C.NAME - LastTracedFrontendCounters->NAME; \
382386
static char const *name = #TY "." #NAME; \
383387
if (delta != 0) { \
384388
LastTracedFrontendCounters->NAME = C.NAME; \
@@ -428,8 +432,8 @@ UnifiedStatsReporter::~UnifiedStatsReporter()
428432
auto &C = getFrontendCounters();
429433
// Convenience calculation for crude top-level "absolute speed".
430434
if (C.NumSourceLines != 0 && ElapsedTime.getProcessTime() != 0.0)
431-
C.NumSourceLinesPerSecond = (size_t) (((double)C.NumSourceLines) /
432-
ElapsedTime.getProcessTime());
435+
C.NumSourceLinesPerSecond = (int64_t) (((double)C.NumSourceLines) /
436+
ElapsedTime.getProcessTime());
433437
}
434438

435439
std::error_code EC;

0 commit comments

Comments
 (0)