soc.2012.statscollector: 24aa37e2: Add CPU info parameters for LINUX

sanket at soc.pidgin.im sanket at soc.pidgin.im
Tue May 15 22:46:02 EDT 2012


----------------------------------------------------------------------
Revision: 24aa37e2fa24137b3f94b3e1fca5cbf35519ac2a
Parent:   b2e6ddd92a0b541f8ad099f1af2742504c7d591f
Author:   sanket at soc.pidgin.im
Date:     05/15/12 07:59:33
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/24aa37e2fa24137b3f94b3e1fca5cbf35519ac2a

Changelog: 

Add CPU info parameters for LINUX

Using /proc/cpuinfo and otherwise we can now gather the following statistics:
1. OS name
2. Pidgin application architecture
3. CPU family, CPU vendor id, Processors and cores, Processor model name

Changes against parent b2e6ddd92a0b541f8ad099f1af2742504c7d591f

  patched  pidgin/plugins/statscollector.c

-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c	aad6a454e319ed1355fcd6f80d2169cb30d1a73c
+++ pidgin/plugins/statscollector.c	e6b510c9bf1f1178aa863e675140bfd4243a5e18
@@ -92,10 +92,18 @@ get_cpuinfo_xml(){
 
   xmlnode *root, *languages, *node, *ver, *os, *cpu, *native_arch, *app_arch;
   const char * const * langs;
-  char *str_os, *str_native_arch, *str_app_arch;
+  char *str_os, *str_native_arch, *str_app_arch, *proc_file;
+  char **lines;
   int i, app_bs, native_bs;
   enum OS_TYPES e_os;
 
+  /* CPU info variables */
+  GError *error;
+  char *model_name, *vendor_id, *cpu_family;
+  int  no_cores=0, length, no_proc=0;
+  xmlnode *model_name_xml, *vendor_id_xml, *cpu_family_xml, *no_cores_xml, \
+    *no_proc_xml;
+
   root = xmlnode_new("cpuinfo");
 
   /* CPU os/hw info */
@@ -141,6 +149,77 @@ get_cpuinfo_xml(){
   xmlnode_insert_data(app_arch, str_app_arch, -1);
   xmlnode_insert_child(cpu, app_arch);
 
+  /* Processor info */
+
+#ifdef __unix__
+
+  /* Read the contents */
+  proc_file = (char *)malloc(4096*sizeof(char));
+  proc_file[0] = '\0';
+  g_file_get_contents("/proc/cpuinfo", &proc_file, &length, &error);
+
+  /* Split it into lines */
+  lines = g_strsplit(proc_file, "\n", -1);
+
+  /* Search for relevant CPUinfo in our case
+   * 1. Processor Family
+   * 2. Vendor id
+   * 3. Model Name
+   * 4. CPU cores
+   */
+
+  for(i=0;lines[i];i++){
+
+    /* Debug info */
+    purple_debug_info("STATS", "CPUINFO: %s\n", lines[i]);
+
+    /* Create parts */
+    char **t = g_strsplit(lines[i], ":", -1);
+
+    if(t[0] && t[1]){
+
+      char *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++;
+      }
+
+    }
+
+  }
+
+  cpu_family_xml = xmlnode_new("cpu-family");
+  xmlnode_insert_data(cpu_family_xml, cpu_family, -1);
+  xmlnode_insert_child(cpu, cpu_family_xml);
+
+  model_name_xml = xmlnode_new("model-name");
+  xmlnode_insert_data(model_name_xml, model_name, -1);
+  xmlnode_insert_child(cpu, model_name_xml);
+
+  vendor_id_xml = xmlnode_new("vendor-id");
+  xmlnode_insert_data(vendor_id_xml, vendor_id, -1);
+  xmlnode_insert_child(cpu, vendor_id_xml);
+
+  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);
+
+  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);
+
+
+#endif
+
+
+
   /* Languages */
 
   langs = g_get_language_names();


More information about the Commits mailing list