From 0068f4864699c47871ed40e7071d6ee54166bfdb Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 3 Jul 2011 20:07:20 +0000 Subject: [PATCH] vm stats logging for linux --- src/session_impl.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 034e357f3..b36b8e4de 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3073,8 +3073,27 @@ namespace aux { kern_return_t error = host_statistics(host_port, HOST_VM_INFO, (host_info_t)vm_stat, &host_count); #elif defined TORRENT_LINUX - // TODO: read straight from /proc/meminfo ? + char buffer[4096]; + char string[1024]; + boost::uint32_t value; + FILE* f = fopen("/proc/vmstat"); + int ret = 0; + while ((ret = fscanf(f, "%s %u\n", string, &value)) != EOF) + { + if (ret != 2) continue; + if (strcmp(string, "nr_active_anon") == 0) vm_stat->active_count += value; + else if (strcmp(string, "nr_active_file") == 0) vm_stat->active_count += value; + else if (strcmp(string, "nr_inactive_anon") == 0) vm_stat->inactive_count += value; + else if (strcmp(string, "nr_inactive_file") == 0) vm_stat->inactive_count += value; + else if (strcmp(string, "nr_free_pages") == 0) vm_stat->free_count = value; + else if (strcmp(string, "nr_unevictable") == 0) vm_stat->wire_count = value; + else if (strcmp(string, "pswpin") == 0) vm_stat->pageins = value; + else if (strcmp(string, "pswpout") == 0) vm_stat->pageouts = value; + else if (strcmp(string, "pgfault") == 0) vm_stat->faults = value; + } + fclose(f); #endif +// TOOD: windows? }