system-stats: Port for Windows.
authorGurucharan Shetty <gshetty@nicira.com>
Fri, 14 Mar 2014 14:38:52 +0000 (07:38 -0700)
committerGurucharan Shetty <gshetty@nicira.com>
Mon, 17 Mar 2014 21:20:49 +0000 (14:20 -0700)
This does not provide us all the functionality that
is available in Linux. But should be a start.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
include/windows/automake.mk
include/windows/dirent.h [new file with mode: 0644]
vswitchd/system-stats.c

index 140a648..4d5a42c 100644 (file)
@@ -7,6 +7,7 @@
 
 noinst_HEADERS += \
        include/windows/arpa/inet.h \
+       include/windows/dirent.h \
        include/windows/getopt.h \
        include/windows/net/if.h \
        include/windows/netdb.h \
diff --git a/include/windows/dirent.h b/include/windows/dirent.h
new file mode 100644 (file)
index 0000000..e69de29
index ca98b03..6c73933 100644 (file)
@@ -85,7 +85,14 @@ get_page_size(void)
     static unsigned int cached;
 
     if (!cached) {
+#ifndef _WIN32
         long int value = sysconf(_SC_PAGESIZE);
+#else
+        long int value;
+        SYSTEM_INFO sysinfo;
+        GetSystemInfo(&sysinfo);
+        value = sysinfo.dwPageSize;
+#endif
         if (value >= 0) {
             cached = value;
         }
@@ -111,12 +118,20 @@ get_memory_stats(struct smap *stats)
 #endif
         int mem_total, mem_used;
 
+#ifndef _WIN32
         if (pagesize <= 0 || phys_pages <= 0 || avphys_pages <= 0) {
             return;
         }
 
         mem_total = phys_pages * (pagesize / 1024);
         mem_used = (phys_pages - avphys_pages) * (pagesize / 1024);
+#else
+        MEMORYSTATUS memory_status;
+        GlobalMemoryStatus(&memory_status);
+
+        mem_total = memory_status.dwTotalPhys;
+        mem_used = memory_status.dwTotalPhys - memory_status.dwAvailPhys;
+#endif
         smap_add_format(stats, "memory", "%d,%d", mem_total, mem_used);
     } else {
         static const char file_name[] = "/proc/meminfo";
@@ -398,6 +413,7 @@ get_process_info(pid_t pid, struct process_info *pinfo)
 static void
 get_process_stats(struct smap *stats)
 {
+#ifndef _WIN32
     struct dirent *de;
     DIR *dir;
 
@@ -448,6 +464,7 @@ get_process_stats(struct smap *stats)
     }
 
     closedir(dir);
+#endif /* _WIN32 */
 }
 
 static void