~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to examples/perfcounter/perf_writer_mem.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 *  Unix SMB/CIFS implementation.
 
3
 *  Performance Counter Daemon
 
4
 *
 
5
 *  Copyright (C) Marcin Krzysztof Porwit    2005
 
6
 *  
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 3 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *  
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *  
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#include "perf.h"
 
22
 
 
23
void get_meminfo(PERF_DATA_BLOCK *data)
 
24
{
 
25
    int status;
 
26
    struct sysinfo info;
 
27
    status = sysinfo(&info);
 
28
    
 
29
    data->memInfo.data->availPhysKb = (info.freeram * info.mem_unit)/1024;
 
30
    data->memInfo.data->availSwapKb = (info.freeswap * info.mem_unit)/1024;
 
31
    data->memInfo.data->totalPhysKb = (info.totalram * info.mem_unit)/1024;
 
32
    data->memInfo.data->totalSwapKb = (info.totalswap * info.mem_unit)/1024;
 
33
 
 
34
    /* Also get uptime since we have the structure */
 
35
    data->PerfTime = (unsigned long)info.uptime;
 
36
 
 
37
    return;
 
38
}
 
39
 
 
40
void init_memdata_desc(PERF_DATA_BLOCK *data)
 
41
{
 
42
    init_perf_counter(&(data->memInfo.memObjDesc),
 
43
                      &(data->memInfo.memObjDesc),
 
44
                      get_counter_id(data),
 
45
                      "Memory",
 
46
                      "The Memory performance object consists of counters that describe the behavior of physical and virtual memory on the computer.",
 
47
                      0,
 
48
                      PERF_OBJECT);
 
49
    init_perf_counter(&(data->memInfo.availPhysKb),
 
50
                      &(data->memInfo.memObjDesc),
 
51
                      get_counter_id(data),
 
52
                      "Available Physical Kilobytes",
 
53
                      "Available Physical Kilobytes is the number of free kilobytes in physical memory",
 
54
                      PERF_SIZE_DWORD | PERF_TYPE_NUMBER | PERF_NUMBER_DECIMAL | PERF_DISPLAY_NO_SUFFIX,
 
55
                      PERF_COUNTER);
 
56
    init_perf_counter(&(data->memInfo.availSwapKb),
 
57
                      &(data->memInfo.memObjDesc),
 
58
                      get_counter_id(data),
 
59
                      "Available Swap Kilobytes",
 
60
                      "Available Swap Kilobytes is the number of free kilobytes in swap space",
 
61
                      PERF_SIZE_DWORD | PERF_TYPE_NUMBER | PERF_NUMBER_DECIMAL | PERF_DISPLAY_NO_SUFFIX,
 
62
                      PERF_COUNTER);
 
63
    init_perf_counter(&(data->memInfo.totalPhysKb),
 
64
                      &(data->memInfo.memObjDesc),
 
65
                      get_counter_id(data),
 
66
                      "Total Physical Kilobytes",
 
67
                      "Total Physical Kilobytes is a base counter",
 
68
                      PERF_SIZE_DWORD | PERF_TYPE_NUMBER | PERF_NUMBER_DECIMAL | PERF_COUNTER_BASE | PERF_DISPLAY_NOSHOW,
 
69
                      PERF_COUNTER);
 
70
    init_perf_counter(&(data->memInfo.totalSwapKb),
 
71
                      &(data->memInfo.memObjDesc),
 
72
                      get_counter_id(data),
 
73
                      "Total Swap Kilobytes",
 
74
                      "Total Swap Kilobytes is a base counter",
 
75
                      PERF_SIZE_DWORD | PERF_TYPE_NUMBER | PERF_NUMBER_DECIMAL | PERF_COUNTER_BASE | PERF_DISPLAY_NOSHOW,
 
76
                      PERF_COUNTER);
 
77
 
 
78
    return;
 
79
}
 
80
 
 
81
void init_mem_data(PERF_DATA_BLOCK *data)
 
82
{
 
83
    data->memInfo.data = calloc(1, sizeof(*data->memInfo.data));
 
84
    if(!data->memInfo.data)
 
85
    {
 
86
        perror("init_memdata: out of memory");
 
87
        exit(1);
 
88
    }
 
89
 
 
90
    init_memdata_desc(data);
 
91
 
 
92
    get_meminfo(data);
 
93
 
 
94
    return;
 
95
}
 
96
 
 
97
void output_mem_desc(PERF_DATA_BLOCK *data, RuntimeSettings rt)
 
98
{
 
99
    output_perf_desc(data->memInfo.memObjDesc, rt);
 
100
    output_perf_desc(data->memInfo.availPhysKb, rt);
 
101
    output_perf_desc(data->memInfo.availSwapKb, rt);
 
102
    output_perf_desc(data->memInfo.totalPhysKb, rt);
 
103
    output_perf_desc(data->memInfo.totalSwapKb, rt);
 
104
 
 
105
    return;
 
106
}
 
107
 
 
108
void output_meminfo(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags)
 
109
{
 
110
    output_perf_counter(data->memInfo.availPhysKb, 
 
111
                        (unsigned long long)data->memInfo.data->availPhysKb, 
 
112
                        rt, tdb_flags);
 
113
    output_perf_counter(data->memInfo.availSwapKb, 
 
114
                        (unsigned long long)data->memInfo.data->availSwapKb,
 
115
                        rt, tdb_flags);
 
116
    output_perf_counter(data->memInfo.totalPhysKb,
 
117
                        (unsigned long long)data->memInfo.data->totalPhysKb,
 
118
                        rt, tdb_flags);
 
119
    output_perf_counter(data->memInfo.totalSwapKb,
 
120
                        (unsigned long long)data->memInfo.data->totalSwapKb,
 
121
                        rt, tdb_flags);
 
122
 
 
123
    return;
 
124
}