Main Page | Data Structures | File List | Data Fields | Globals

lininfo.c

Go to the documentation of this file.
00001 /*
00002 lkmonitor (Linux Kernel Monitor)
00003 
00004 Application for monitoring and tuning a Linux kernel.
00005 
00006 Copyright (C) 2005,2006  Fernando ApesteguĂ­a
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 */
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <dirent.h>
00025 #include <sys/types.h>
00026 #include <stdlib.h>
00027 #include <glib.h>
00028 
00029 #include "lininfo.h"
00030 #include "others.h"
00031 
00037 int
00038 get_cpu_info (struct cpu_info *cpu)
00039 {
00040   gchar* contenido;
00041   char* str;
00042   
00043   if(g_file_get_contents(CPU_FILE,&contenido,NULL,NULL)==FALSE)
00044           //Error accesing file. Stop program 
00045         g_error("Can't read %s file",CPU_FILE);
00046   
00047   str=contenido;
00048   find_data_for("processor : %[^\n]",cpu->processor,str);
00049   find_data_for("vendor_id : %[^\n]",cpu->vendor_id,str);
00050   find_data_for("cpu family : %[^\n]",cpu->cpu_family,str);
00051   find_data_for("model : %[^\n]",cpu->model,str);
00052   find_data_for("model name : %[^\n]",cpu->model_name,str)      ;
00053   find_data_for("stepping : %[^\n]",cpu->stepping,str);
00054   find_data_for("cpu MHz : %[^\n]",cpu->Mhz,str);
00055   find_data_for("cache size : %[^\n]",cpu->cache,str);
00056   find_data_for("fpu : %[^\n]",cpu->fpu,str);
00057   find_data_for("fpu_exception : %[^\n]",cpu->fpu_exception,str);
00058   find_data_for("cpuid level : %[^\n]",cpu->cpuid_level,str);
00059   find_data_for("wp : %[^\n]",cpu->wp,str);
00060   find_data_for("flags : %[^\n]",cpu->flags,str);
00061   find_data_for("bogomips : %[^\n]",cpu->bogomips,str);
00062         
00063 
00064   g_free(contenido);
00065 
00066   return (0);
00067 }                               
00068 
00069 
00075 int
00076 get_mem_info (struct mem_info *mem)
00077 {
00078         gchar* contenido;
00079         
00080         if(g_file_get_contents(MEM_FILE,&contenido,NULL,NULL)==FALSE)
00081                 //Can't read file. Stop program
00082                 g_error("Can't read %s file",MEM_FILE);
00083 
00084   find_data_for ("MemTotal: %[^\n]",mem->total, contenido);
00085   find_data_for ("MemFree: %[^\n]",mem->free, contenido);
00086   find_data_for ("Buffers: %[^\n]",mem->buffers, contenido);
00087   find_data_for ("Cached: %[^\n]",mem->cached, contenido);
00088   find_data_for ("SwapCached: %[^\n]",mem->swap_cached, contenido);
00089   find_data_for ("Active: %[^\n]",mem->active, contenido);
00090   find_data_for ("Inactive: %[^\n]",mem->inactive,contenido);
00091   find_data_for ("Dirty: %[^\n]",mem->dirty, contenido);
00092   find_data_for ("HighTotal: %[^\n]",mem->high_total, contenido);
00093   find_data_for ("HighFree: %[^\n]",mem->high_free, contenido);
00094   find_data_for ("LowTotal: %[^\n]",mem->low_total, contenido);
00095   find_data_for ("LowFree: %[^\n]",mem->low_free, contenido);
00096   find_data_for ("SwapTotal: %[^\n]",mem->swap_total, contenido);
00097   find_data_for ("SwapFree: %[^\n]",mem->swap_free, contenido);
00098   find_data_for ("HugePages_Total: %[^\n]",mem->hugepages_total, contenido);
00099   find_data_for ("HugePages_Free: %[^\n]",mem->hugepages_free, contenido);
00100   find_data_for ("Hugepagesize: %[^\n]",mem->hugepages_size, contenido);
00101 
00102   g_free(contenido);
00103   
00104   return (0);
00105 }                               

Generated on Wed Feb 15 11:24:01 2006 for lkmonitor by  doxygen 1.3.9.1