ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/page_stats.c
Revision: 1.3
Committed: Wed Feb 19 00:25:36 2003 UTC (21 years, 2 months ago) by pajs
Content type: text/plain
Branch: MAIN
CVS Tags: LIBSTATGRAB_0_2
Changes since 1.2: +37 -1 lines
Log Message:
Added get_page_stats_diff() which returns the number of pages in/out etc since
last time it was called, and the time difference since last time it was called.
This makes it very easy for a host to know how many pages averaged over a period
of time.

File Contents

# Content
1 /*
2 * i-scream central monitoring system
3 * http://www.i-scream.org.uk
4 * Copyright (C) 2000-2002 i-scream
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <stdio.h>
26 #include "statgrab.h"
27 #ifdef SOLARIS
28 #include <kstat.h>
29 #include <sys/sysinfo.h>
30 #include <string.h>
31 #endif
32
33
34 static page_stat_t page_stats;
35 static int page_stats_uninit=1;
36
37 page_stat_t *get_page_stats(){
38 kstat_ctl_t *kc;
39 kstat_t *ksp;
40 cpu_stat_t cs;
41
42 page_stats.num_pagein=0;
43 page_stats.num_pageout=0;
44 page_stats.pages_pagein=0;
45 page_stats.pages_pageout=0;
46
47 if ((kc = kstat_open()) == NULL) {
48 return NULL;
49 }
50 for (ksp = kc->kc_chain; ksp!=NULL; ksp = ksp->ks_next) {
51 if ((strcmp(ksp->ks_module, "cpu_stat")) != 0) continue;
52 if (kstat_read(kc, ksp, &cs) == -1) {
53 continue;
54 }
55
56 page_stats.num_pagein+=(long long)cs.cpu_vminfo.pgin;
57 page_stats.num_pageout+=(long long)cs.cpu_vminfo.pgout;
58 page_stats.pages_pagein+=(long long)cs.cpu_vminfo.pgpgin;
59 page_stats.pages_pageout+=(long long)cs.cpu_vminfo.pgpgout;
60 }
61
62 page_stats.systime=time(NULL);
63
64 kstat_close(kc);
65
66 return &page_stats;
67 }
68
69 page_stat_t *get_page_stats_diff(){
70 page_stat_t *page_ptr;
71 static page_stat_t page_stats_diff;
72
73 if(page_stats_uninit){
74 page_ptr=get_page_stats();
75 if(page_ptr==NULL){
76 return NULL;
77 }
78 page_stats_uninit=0;
79 return page_ptr;
80 }
81
82 page_stats_diff.num_pagein=page_stats.num_pagein;
83 page_stats_diff.num_pageout=page_stats.num_pageout;
84 page_stats_diff.pages_pagein=page_stats.pages_pagein;
85 page_stats_diff.pages_pageout=page_stats.pages_pageout;
86 page_stats_diff.systime=page_stats.systime;
87
88 page_ptr=get_page_stats();
89 if(page_ptr==NULL){
90 return NULL;
91 }
92
93 page_stats_diff.num_pagein=page_stats.num_pagein-page_stats_diff.num_pagein;
94 page_stats_diff.num_pageout=page_stats.num_pageout-page_stats_diff.num_pageout;
95 page_stats_diff.pages_pagein=page_stats.pages_pagein-page_stats_diff.pages_pagein;
96 page_stats_diff.pages_pageout=page_stats.pages_pageout-page_stats_diff.pages_pageout;
97 page_stats_diff.systime=page_stats.systime-page_stats_diff.systime;
98
99 return &page_stats_diff;
100 }