Skip to content
Snippets Groups Projects
Commit 252c297b authored by Monty Brandenberg's avatar Monty Brandenberg
Browse files

Add metrics gathering utils for Mac OS X. All platforms have useful numbers now.

parent b27bb47f
Branches
Tags
No related merge requests found
...@@ -577,7 +577,7 @@ int getopt(int argc, char * const argv[], const char *optstring) ...@@ -577,7 +577,7 @@ int getopt(int argc, char * const argv[], const char *optstring)
#if defined(WIN32) #if LL_WINDOWS
#define PSAPI_VERSION 1 #define PSAPI_VERSION 1
#include "windows.h" #include "windows.h"
...@@ -640,8 +640,10 @@ class Metrics::MetricsImpl ...@@ -640,8 +640,10 @@ class Metrics::MetricsImpl
protected: protected:
}; };
#elif defined(DARWIN) #elif LL_DARWIN
#include <sys/resource.h>
#include <mach/mach.h>
class Metrics::MetricsImpl class Metrics::MetricsImpl
{ {
...@@ -652,14 +654,72 @@ class Metrics::MetricsImpl ...@@ -652,14 +654,72 @@ class Metrics::MetricsImpl
~MetricsImpl() ~MetricsImpl()
{} {}
void init(Metrics *) void init(Metrics * metrics)
{} {
U64 utime, stime;
void sample(Metrics *) if (getTimes(&utime, &stime))
{} {
metrics->mStartSTime = stime;
metrics->mStartUTime = utime;
}
metrics->mStartWallTime = totalTime();
sample(metrics);
}
void sample(Metrics * metrics)
{
U64 vsz;
if (getVM(&vsz))
{
metrics->mMaxVSZ = (std::max)(metrics->mMaxVSZ, vsz);
metrics->mMinVSZ = (std::min)(metrics->mMinVSZ, vsz);
}
}
void term(Metrics * metrics)
{
U64 utime, stime;
if (getTimes(&utime, &stime))
{
metrics->mEndSTime = stime;
metrics->mEndUTime = utime;
}
metrics->mEndWallTime = totalTime();
}
protected:
bool getVM(U64 * vsz)
{
task_basic_info task_info_block;
mach_msg_type_number_t task_info_count(TASK_BASIC_INFO_COUNT);
if (KERN_SUCCESS != task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t) &task_info_block,
&task_info_count))
{
return false;
}
* vsz = task_info_block.virtual_size;
return true;
}
bool getTimes(U64 * utime, U64 * stime)
{
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage))
{
return false;
}
* utime = U64(usage.ru_utime.tv_sec) * U64L(1000000) + usage.ru_utime.tv_usec;
* stime = U64(usage.ru_stime.tv_sec) * U64L(1000000) + usage.ru_stime.tv_usec;
return true;
}
void term(Metrics *)
{}
}; };
#else #else
...@@ -821,7 +881,7 @@ class Metrics::MetricsImpl ...@@ -821,7 +881,7 @@ class Metrics::MetricsImpl
}; };
#endif // defined(WIN32) #endif // LL_WINDOWS
Metrics::Metrics() Metrics::Metrics()
: mMaxVSZ(U64(0)), : mMaxVSZ(U64(0)),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment