soc.2012.statscollector: 2ff75b88: Change CPU/OS info semantics
sanket at soc.pidgin.im
sanket at soc.pidgin.im
Fri May 18 01:17:08 EDT 2012
----------------------------------------------------------------------
Revision: 2ff75b88311805cac19d2180e5923c797eeb3418
Parent: 5940f48f916c84b754f9585b950d701fa47a0ca6
Author: sanket at soc.pidgin.im
Date: 05/17/12 07:42:17
Branch: im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/2ff75b88311805cac19d2180e5923c797eeb3418
Changelog:
Change CPU/OS info semantics
Instead of using /proc/cpuinfo (which is very LINUX centric) we use a
generic approach to POSIX compliant systems - uname(). It returns us not
only OS name but also version/flavor information. Though it's not very
universally accepted, but that's the tradeoff!
For windows we'll use native functions, and here I have used WOW64 check
to see if a 32 bit application runs on 64 bit windows (major current
concern with pidgin).
Lastly MAC will be handled, and any other OS (though very few left?) will
have to wait for their implementtion.
Changes against parent 5940f48f916c84b754f9585b950d701fa47a0ca6
patched pidgin/plugins/statscollector.c
-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c f6b41bdcb463aa9a67fd7a13551e7ea4b858665f
+++ pidgin/plugins/statscollector.c e66436691c116195609a84913ca51698646c4455
@@ -16,6 +16,10 @@
#include <glib.h>
#include <gtkplugin.h>
+#ifdef _WIN32
+#include<windows.h>
+#endif
+
#define STATS_MAJOR_VERSION 1
#define STATS_MINOR_VERSION 0
@@ -23,6 +27,7 @@ int save_timer = 0;
GHashTable *stats_acc_ht, *stats_plugins_ht;
int save_timer = 0;
+/* Types of Operating Systems */
enum OS_TYPES {WINDOWS, APPLE, UNIX};
static void
@@ -86,146 +91,159 @@ static xmlnode *
}
static xmlnode *
-get_cpuinfo_xml(){
+get_os_xml(){
- /* Obtains a XML node containing the CPU info */
+ xmlnode *os;
+ char *str_os;
- xmlnode *root, *languages, *node, *ver, *os, *cpu, *app_arch;
- const char * const * langs;
- char *str_os, *str_app_arch, *proc_file;
- char **lines;
- int i, app_bs;
- enum OS_TYPES e_os;
+#if defined __USE_POSIX
+ struct utsname os_utsname;
+ xmlnode *os_sysname_xml, *os_release_xml, *os_version_xml;
+#elif defined _WIN32
+ OSVERSIONINFO osvi;
+ xmlnode *os_major_version, *os_minor_version, *is_wow_xml;
+#ifdef _WIN64 /* Checking if 32 bit is running over 64 bit */
+ BOOL bIsWow64;
+ typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
+ LPFN_ISWOW64PROCESS fnIsWow64Process;
+#endif
+#endif
- /* CPU info variables */
- GError *error;
- char *model_name=NULL, *vendor_id=NULL, *cpu_family=NULL;
- int no_cores=0, no_proc=0;
+ /* OS specific details such as, OS name, OS version */
+ os = xmlnode_new("os");
- /* Temp var */
- char **t, *p1, *p2;
+ /* So we will start with some simple CPU information that are also
+ * necessary.
+ * 1. Architecture type
+ * 2. OS name -- and any specifics if possible
+ * 3. Application/OS bit size
+ */
- gsize length;
- xmlnode *model_name_xml, *vendor_id_xml, *cpu_family_xml, *no_cores_xml, \
- *no_proc_xml;
- root = xmlnode_new("cpuinfo");
- /* CPU os/hw info */
-
- cpu = xmlnode_new("cpu");
- xmlnode_insert_child(root, cpu);
-
- /* Base OS */
-
- os = xmlnode_new("os");
-
-#ifdef _WIN32
- e_os = WINDOWS;
+#if defined _WIN32 && !(defined _WIN64)
+ str_os = g_strdup("WINDOWS32");
+#elif defined _WIN64
+ str_os = g_strdup("WINDOWS64");
#elif defined __APPLE__
- e_os = APPLE;
-#elif defined __unix__
- e_os = UNIX;
+ str_os = g_strdup("APPLE");
+#elif defined __linux__ && defined __USE_POSIX
+ str_os = g_strdup("LINUX");
+ /* Use uname to get linux specific information */
+#elif defined __USE_POSIX /* TODO: What defines Posix? */
+ str_os = g_stdup("POSIX");
+#else
+ str_os = g_strdup("OTHER");
#endif
- switch(e_os){
+ xmlnode_set_attrib(os, "id", str_os);
- case WINDOWS:
- str_os = g_strdup("WINDOWS");
- break;
- case APPLE:
- str_os = g_strdup("APPLE");
- break;
- case UNIX:
- str_os = g_strdup("UNIX");
- break;
+#ifdef _WIN32 /* Detects both WIN32 and WIN 64 here */
- }
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&osvi);
- xmlnode_insert_data(os, str_os, -1);
- xmlnode_insert_child(cpu, os);
+ os_major_version = xmlnode_new("major-version");
+ os_minor_version = xmlnode_new("minor-version");
- /* Application arch */
+ xmlnode_insert_data(os_major_version, \
+ g_strdup_printf("%d", osvi.dwMajorVersion), -1);
+ xmlnode_insert_data(os_minor_version, \
+ g_strdup_printf("%d", osvi.dwMinorVersion), -1);
- app_arch = xmlnode_new("app-arch");
+ xmlnode_insert_child(os, os_major_version);
+ xmlnode_insert_child(os, os_minor_version);
- app_bs = sizeof(int)*8;
- if(app_bs==32) str_app_arch = g_strdup("32");
- else if(app_bs==64) str_app_arch = g_strdup("64");
- purple_debug_info("STATS", "ARCH SIZE: %d\n", app_bs);
+ is_wow_xml = xmlnode_new("is_wow64");
- xmlnode_insert_data(app_arch, str_app_arch, -1);
- xmlnode_insert_child(cpu, app_arch);
+#ifdef _WIN64 /* Check if the application is faking 32 bit on 64 bit */
+ bIsWow64 = FALSE;
+ fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( \
+ GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
- /* Processor info */
+ if(NULL != fnIsWow64Process)
+ {
+ if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
+ {
+ xmlnode_insert_data(is_wow_xml, "null", -1); /* Cannot say! */
+ }
+ }
+ if(*bIsWow64)
+ xmlnode_insert_data(is_wow_xml, "true", -1);
+ else xmlnode_insert_data(is_wow_xml, "false", -1);
+#else
+ /* cannot be wow process */
+ xmlnode_insert_data(is_wow_xml, "false", -1);
+#endif /* End checking wow */
-#ifdef __unix__
+ xmlnode_insert_child(os,is_wow_xml);
- /* Read the contents */
- g_file_get_contents("/proc/cpuinfo", &proc_file, &length, &error);
- /* Split it into lines */
- lines = g_strsplit(proc_file, "\n", -1);
+#elif defined __APPLE__
+ /* Kung-foo for apple os specific details */
+#elif defined __USE_POSIX /* Covers linux et. al */
- /* Search for relevant CPUinfo in our case
- * 1. Processor Family
- * 2. Vendor id
- * 3. Model Name
- * 4. CPU cores
- */
+ uname(&os_utsname);
+ os_sysname_xml = xmlnode_new("sysname");
+ os_release_xml = xmlnode_new("release");
+ os_version_xml = xmlnode_new("version");
- for(i=0;lines[i];i++){
+ xmlnode_insert_data(os_sysname_xml, g_strdup(os_utsname.sysname),-1);
+ xmlnode_insert_data(os_release_xml, g_strdup(os_utsname.release),-1);
+ xmlnode_insert_data(os_version_xml, g_strdup(os_utsname.version),-1);
- /* Debug info */
- purple_debug_info("STATS", "CPUINFO: %s\n", lines[i]);
+ xmlnode_insert_child(os, os_sysname_xml);
+ xmlnode_insert_child(os, os_release_xml);
+ xmlnode_insert_child(os, os_version_xml);
- /* Create parts */
- t = g_strsplit(lines[i], ":", -1);
+#endif
- if(t[0] && t[1]){
+ return os;
- p1 = g_strstrip(t[0]), p2 = g_strstrip(t[1]);
+}
- if(!g_strcmp0(p1, "cpu family"))
- cpu_family = p2;
- else if(!g_strcmp0(p1, "model name"))
- model_name = g_strdup(p2);
- else if(!g_strcmp0(p1, "vendor_id"))
- vendor_id = g_strdup(p2);
- else if(!g_strcmp0(p1, "cpu cores")){
- no_cores += atoi(p2);
- no_proc++;
- }
+static xmlnode *
+get_cpuinfo_xml(){
- }
+ /* Obtains a XML node containing the CPU info */
- }
+ xmlnode *root, *languages, *node, *ver, *cpu, *app_arch;
+ const char * const * langs;
+ char *str_app_arch;
+ int i, app_bs;
- cpu_family_xml = xmlnode_new("cpu-family");
- xmlnode_insert_data(cpu_family_xml, cpu_family, -1);
- xmlnode_insert_child(cpu, cpu_family_xml);
+ root = xmlnode_new("cpuinfo");
- model_name_xml = xmlnode_new("model-name");
- xmlnode_insert_data(model_name_xml, model_name, -1);
- xmlnode_insert_child(cpu, model_name_xml);
+ /* CPU os/hw info */
- vendor_id_xml = xmlnode_new("vendor-id");
- xmlnode_insert_data(vendor_id_xml, vendor_id, -1);
- xmlnode_insert_child(cpu, vendor_id_xml);
+ cpu = xmlnode_new("cpu");
+ xmlnode_insert_child(root, cpu);
- no_cores_xml = xmlnode_new("cores");
- xmlnode_insert_data(no_cores_xml, g_strdup_printf("%d",no_cores), -1);
- xmlnode_insert_child(cpu, no_cores_xml);
+ xmlnode_insert_child(cpu, get_os_xml());
- no_proc_xml = xmlnode_new("processors");
- xmlnode_insert_data(no_proc_xml, g_strdup_printf("%d",no_proc), -1);
- xmlnode_insert_child(cpu, no_proc_xml);
+ /* Application 32/64 bits */
+ app_arch = xmlnode_new("app-arch");
-#endif
+ app_bs = sizeof(int)*8;
+ if(app_bs==32) str_app_arch = g_strdup("32");
+ else if(app_bs==64) str_app_arch = g_strdup("64");
+ xmlnode_insert_data(app_arch, str_app_arch, -1);
+ xmlnode_insert_child(cpu, app_arch);
+
+/* #if defined _WIN32 */
+/* */
+/* SYSTEM_INFO sysinfo; */
+/* GetSystemInfo(&sysinfo); */
+/* */
+/* purple_debug_info("STATS_WIN","%u, %u, %u, %u", sysinfo.wProcessorArchitecture, sysinfo.wProcessorLevel, sysinfo.wProcessorRevision, sysinfo.dwPageSize, sysinfo.dwProcessorType, sysinfo.dwNumberOfProcessors); */
+/* */
+/* #endif */
+/* */
/* Languages */
langs = g_get_language_names();
@@ -533,4 +551,3 @@ PURPLE_INIT_PLUGIN(statscollector, init_
}
PURPLE_INIT_PLUGIN(statscollector, init_plugin, info)
-
More information about the Commits
mailing list