/soc/2012/sanket/statscollector-2.x.y: 393be09e8377: Add CPU inf...

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


Changeset: 393be09e8377f84c379b9bb8dd2a849b54eea9e9
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-05-15 11:59 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/393be09e8377

Description:

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

diffstat:

 pidgin/plugins/statscollector.c |  81 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 80 insertions(+), 1 deletions(-)

diffs (101 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -92,10 +92,18 @@
 
   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 @@
   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