Display real memory usage on mac OS X, other ports will follow

This commit is contained in:
lperron@google.com
2010-10-10 12:27:05 +00:00
parent 9026145d65
commit 63e3716360
4 changed files with 41 additions and 7 deletions

View File

@@ -86,4 +86,32 @@ int64 WallTimer::GetInMs() const {
return local_sum_usec / kMilliSecInMicroSec;
#endif
}
// GetUsedMemory
#if defined(__APPLE__) && defined(__GNUC__)
#include <mach/mach_init.h>
#include <mach/task.h>
int64 GetMemoryUsage () {
task_t task = MACH_PORT_NULL;
struct task_basic_info t_info;
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
if (KERN_SUCCESS != task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&t_info,
&t_info_count)) {
return -1;
}
int64 resident_memory = t_info.resident_size;
// int64 virtual_memory = t_info.virtual_size;
return resident_memory;
}
#else
int64 GetMemoryUsage() {
return 0;
}
#endif
} // namespace operations_research

View File

@@ -170,6 +170,8 @@ class WallTimer {
DISALLOW_COPY_AND_ASSIGN(WallTimer);
};
int64 GetMemoryUsage();
} // namespace operations_research

View File

@@ -1258,13 +1258,9 @@ string Solver::DebugString() const {
}
int64 Solver::MemoryUsage() {
// FIXME: Implement the real thing.
return 0ll;
return GetMemoryUsage();
}
int64 Solver::wall_time() const {
return timer_->GetInMs();
}

View File

@@ -205,8 +205,16 @@ void SearchLog::OutputLine(const string& line) {
}
string SearchLog::MemoryUsage() {
return StringPrintf("memory used = %" GG_LL_FORMAT "d", Solver::MemoryUsage());
int64 memory_usage = Solver::MemoryUsage();
if (memory_usage > 0x200000) {
return StringPrintf("memory used = %.2lf MB",
memory_usage * 1.0 / 1024 / 1024);
} else if (memory_usage > 0x1000) {
return StringPrintf("memory used = %" GG_LL_FORMAT "d KB",
memory_usage / 1024);
} else {
return StringPrintf("memory used = %" GG_LL_FORMAT "d", memory_usage);
}
}
SearchMonitor* Solver::MakeSearchLog(int period) {