diff options
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index c88dc4e..73f13f8 100644 --- a/src/util.cc +++ b/src/util.cc @@ -293,3 +293,32 @@ string StripAnsiEscapeCodes(const string& in) { } return stripped; } + +#ifdef _WIN32 +static double GetLoadAverage_win32() +{ + // TODO(nicolas.despres@gmail.com): Find a way to implement it on Windows. + return -0.0f; +} +#else +static double GetLoadAverage_unix() +{ + double loadavg[3] = { 0.0f, 0.0f, 0.0f }; + if (getloadavg(loadavg, 3) < 0) + { + // Maybe we should return an error here or the availability of + // getloadavg(3) should be checked when ninja is configured. + return -0.0f; + } + return loadavg[0]; +} +#endif // _WIN32 + +double GetLoadAverage() +{ +#ifdef _WIN32 + return GetLoadAverage_win32(); +#else + return GetLoadAverage_unix(); +#endif // _WIN32 +} |