/soc/2012/sanket/statscollector-2.x.y: 1a0335745d58: Roll back c...

Sanket Agarwal sanket at soc.pidgin.im
Tue Jul 10 00:36:23 EDT 2012


Changeset: 1a0335745d58685d22801d82cb8362b624ca4522
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-05-18 06:07 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/1a0335745d58

Description:

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

diffstat:

 pidgin/plugins/statscollector.c |  227 +++++++++++++++++++++------------------
 1 files changed, 120 insertions(+), 107 deletions(-)

diffs (294 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -29,6 +29,7 @@
 
 /* Types of Operating Systems */
 enum OS_TYPES {WINDOWS, APPLE, UNIX};
+enum BIT_32_64 {BIT_32, BIT_64};
 
 static void
 save_xml(){
@@ -91,73 +92,41 @@
 }
 
 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;
-#endif
+#elif defined __linux__
+  struct utsname os_utsname;
+  char *m_name;
 #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;
 
-
-
-#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");
-#endif
-
-  xmlnode_set_attrib(os, "id", str_os);
-
-#ifdef _WIN32 /* Detects both WIN32 and WIN 64 here */
-
-  ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-  GetVersionEx(&osvi);
-
-  os_major_version = xmlnode_new("major-version");
-  os_minor_version = xmlnode_new("minor-version");
-
-  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);
-
-  xmlnode_insert_child(os, os_major_version);
-  xmlnode_insert_child(os, os_minor_version);
-
-  is_wow_xml = xmlnode_new("is_wow64");
-
-#ifdef _WIN64   /* Check if the application is faking 32 bit on 64 bit */
+#elif defined _WIN32
+  /* Check if we are running as wow64 process */
   bIsWow64 = FALSE;
   fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( \
         GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
@@ -166,40 +135,93 @@
   {
       if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
       {
-          xmlnode_insert_data(is_wow_xml, "null", -1); /* Cannot say! */
+        bit_size = -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 */
+  if(bIsWow64) bit_size= 64;
+  else bit_size = 32;
 
-  xmlnode_insert_child(os,is_wow_xml);
+#elif defined __linux__
+  /* Use uname to find kernel architecture and infer bit-size */
+  uname(&os_utsname);
+  m_name = os_utsname.machine;
 
-
-#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");
-
-  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);
-
-  xmlnode_insert_child(os, os_sysname_xml);
-  xmlnode_insert_child(os, os_release_xml);
-  xmlnode_insert_child(os, os_version_xml);
-
+  if(!g_strcmp0(m_name, "x86_64")) bit_size = 64;
+  else bit_size = 32;
 #endif
 
-  return os;
+  xmlnode_insert_data(bit_size_xml, g_strdup_printf("%d", bit_size), -1);
+
+  return bit_size_xml;
+
+}
+
+static xmlnode *
+get_arch(){
+
+  /* Obtains the architecture type */
+
+  xmlnode *arch_xml;
+  char *arch_str;
+#ifdef __linux__
+  struct utsname os_utsname;
+#elif defined _WIN32
+  SYSTEM_INFO sys_info;
+#endif
+
+  arch_xml = xmlnode_new("arch");
+
+
+#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";
+  }
+#endif
+
+  xmlnode_set_attrib(arch_xml, "id", arch_str);
+
+  return arch_xml;
+
+}
+
+static xmlnode *
+get_os_name(){
+
+  /* Determines the name of the operating system as <os-info id="...">
+   * we could specialize it's name further in this 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
+
+  xmlnode_set_attrib(os_name_xml, "id", name_attrib);
+
+  return os_name_xml;
 
 }
 
@@ -208,10 +230,9 @@
 
   /* 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 @@
   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 @@
   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