soc.2012.statscollector: 6e5147f0: Roll back cpuinfo; modularize and start ...

sanket at soc.pidgin.im sanket at soc.pidgin.im
Fri May 18 01:17:08 EDT 2012


----------------------------------------------------------------------
Revision: 6e5147f00f6d8d71924f5e713981753fab61e1b8
Parent:   2ff75b88311805cac19d2180e5923c797eeb3418
Author:   sanket at soc.pidgin.im
Date:     05/18/12 02:07:07
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/6e5147f00f6d8d71924f5e713981753fab61e1b8

Changelog: 

Roll back cpuinfo; modularize and start with basic stats

Accurate estimation of following:
* Architecture type
* Bit size of application
* Bit size of the kernel

Works for Windows and Linux currently

Changes against parent 2ff75b88311805cac19d2180e5923c797eeb3418

  patched  pidgin/plugins/statscollector.c

-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c	e66436691c116195609a84913ca51698646c4455
+++ pidgin/plugins/statscollector.c	beef962dbc74dae01b6b5467e31152cdcfd7b4a2
@@ -29,6 +29,7 @@ enum OS_TYPES {WINDOWS, APPLE, UNIX};
 
 /* Types of Operating Systems */
 enum OS_TYPES {WINDOWS, APPLE, UNIX};
+enum BIT_32_64 {BIT_32, BIT_64};
 
 static void
 save_xml(){
@@ -91,116 +92,137 @@ static xmlnode *
 }
 
 static xmlnode *
-get_os_xml(){
+get_app_32_64(){
 
-  xmlnode *os;
-  char *str_os;
+  /* Determines if the application is running in 32 or 64 bit mode */
+  int pt_size;
+  xmlnode *bit_size;
 
-#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 */
+  pt_size = sizeof(int)*8;
+  bit_size = xmlnode_new("app-bit");
+  xmlnode_insert_data(bit_size, g_strdup_printf("%d",pt_size), -1);
+  return bit_size;
+
+}
+
+static xmlnode *
+get_os_32_64(){
+
+  /* Determines whether the kernel we are running is 32 or 64 bit */
+  int bit_size=-1;
+  xmlnode *bit_size_xml;
+#ifdef _WIN32
   BOOL bIsWow64;
   typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
   LPFN_ISWOW64PROCESS fnIsWow64Process;
+#elif defined __linux__
+  struct utsname os_utsname;
+  char *m_name;
 #endif
-#endif
 
-  /* OS specific details such as, OS name, OS version */
-  os = xmlnode_new("os");
+  bit_size_xml = xmlnode_new("os-bit");
 
-  /* 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
-   */
+#ifdef _WIN64
+  bit_size = 64;
 
+#elif defined _WIN32
+  /* Check if we are running as wow64 process */
+  bIsWow64 = FALSE;
+  fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( \
+        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
 
+  if(NULL != fnIsWow64Process)
+  {
+      if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
+      {
+        bit_size = -1; /* Cannot say! */
+      }
+  }
+  if(bIsWow64) bit_size= 64;
+  else bit_size = 32;
 
-#if defined _WIN32 && !(defined _WIN64)
-  str_os = g_strdup("WINDOWS32");
-#elif defined _WIN64
-  str_os = g_strdup("WINDOWS64");
-#elif defined __APPLE__
-  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");
+#elif defined __linux__
+  /* Use uname to find kernel architecture and infer bit-size */
+  uname(&os_utsname);
+  m_name = os_utsname.machine;
+
+  if(!g_strcmp0(m_name, "x86_64")) bit_size = 64;
+  else bit_size = 32;
 #endif
 
-  xmlnode_set_attrib(os, "id", str_os);
+  xmlnode_insert_data(bit_size_xml, g_strdup_printf("%d", bit_size), -1);
 
-#ifdef _WIN32 /* Detects both WIN32 and WIN 64 here */
+  return bit_size_xml;
 
-  ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-  GetVersionEx(&osvi);
+}
 
-  os_major_version = xmlnode_new("major-version");
-  os_minor_version = xmlnode_new("minor-version");
+static xmlnode *
+get_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);
+  /* Obtains the architecture type */
 
-  xmlnode_insert_child(os, os_major_version);
-  xmlnode_insert_child(os, os_minor_version);
+  xmlnode *arch_xml;
+  char *arch_str;
+#ifdef __linux__
+  struct utsname os_utsname;
+#elif defined _WIN32
+  SYSTEM_INFO sys_info;
+#endif
 
-  is_wow_xml = xmlnode_new("is_wow64");
+  arch_xml = xmlnode_new("arch");
 
-#ifdef _WIN64   /* Check if the application is faking 32 bit on 64 bit */
-  bIsWow64 = FALSE;
-  fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( \
-        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
 
-  if(NULL != fnIsWow64Process)
-  {
-      if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
-      {
-          xmlnode_insert_data(is_wow_xml, "null", -1); /* Cannot say! */
-      }
+#ifdef __linux__
+  uname(&os_utsname);
+  arch_str = os_utsname.machine;
+#elif defined _WIN32
+  GetSystemInfo(&sys_info);
+  switch(sys_info.wProcessorArchitecture){
+
+    case 9:
+      arch_str = "AMD64";
+      break;
+    case 6:
+      arch_str = "IA64";
+      break;
+    case 0:
+      arch_str = "INTEL";
+      break;
+    default:
+      arch_str = "UNKNOWN";
   }
-  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 */
+#endif
 
-  xmlnode_insert_child(os,is_wow_xml);
+  xmlnode_set_attrib(arch_xml, "id", arch_str);
 
+  return arch_xml;
 
-#elif defined __APPLE__
-  /* Kung-foo for apple os specific details */
-#elif defined __USE_POSIX /* Covers linux et. al */
+}
 
-  uname(&os_utsname);
-  os_sysname_xml = xmlnode_new("sysname");
-  os_release_xml = xmlnode_new("release");
-  os_version_xml = xmlnode_new("version");
+static xmlnode *
+get_os_name(){
 
-  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);
+  /* Determines the name of the operating system as <os-info id="...">
+   * we could specialize it's name further in this xml
+   */
 
-  xmlnode_insert_child(os, os_sysname_xml);
-  xmlnode_insert_child(os, os_release_xml);
-  xmlnode_insert_child(os, os_version_xml);
+  xmlnode *os_name_xml;
+  char *name_attrib;
 
+  os_name_xml = xmlnode_new("os-info");
+
+#ifdef _WIN32
+  name_attrib = "windows";
+#elif defined __linux__
+  name_attrib = "linux";
+#elif defined __APPLE__
+  name_attrib = "apple";
 #endif
 
-  return os;
+  xmlnode_set_attrib(os_name_xml, "id", name_attrib);
 
+  return os_name_xml;
+
 }
 
 static xmlnode *
@@ -208,10 +230,9 @@ get_cpuinfo_xml(){
 
   /* Obtains a XML node containing the CPU info */
 
-  xmlnode *root, *languages, *node, *ver, *cpu, *app_arch;
+  xmlnode *root, *languages, *node, *ver, *cpu, *app_arch, *os_arch, *arch_type;
   const char * const * langs;
-  char *str_app_arch;
-  int i, app_bs;
+  int i;
 
   root = xmlnode_new("cpuinfo");
 
@@ -220,30 +241,21 @@ get_cpuinfo_xml(){
   cpu = xmlnode_new("cpu");
   xmlnode_insert_child(root, cpu);
 
-  xmlnode_insert_child(cpu, get_os_xml());
+  /* OS Name info */
+  xmlnode_insert_child(cpu, get_os_name());
 
   /* Application 32/64 bits */
-
-  app_arch = xmlnode_new("app-arch");
-
-  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);
+  app_arch = get_app_32_64();
   xmlnode_insert_child(cpu, app_arch);
 
+  /* Native 32/64 bit arch */
+  os_arch = get_os_32_64();
+  xmlnode_insert_child(cpu, os_arch);
 
+  /* Arch type */
+  arch_type = get_arch();
+  xmlnode_insert_child(cpu, arch_type);
 
-/* #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();
@@ -267,6 +279,7 @@ get_cpuinfo_xml(){
   xmlnode_insert_data(ver, purple_core_get_version(), -1);
 
   /* Add the version information to the root cpuinfo */
+
   xmlnode_insert_child(root, ver);
 
   purple_debug_info("STATS", "%s\n", xmlnode_to_formatted_str(root, NULL));


More information about the Commits mailing list