From 77460a90756dcaa54ec12bbcd30a5266286103d7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 8 Nov 2005 16:33:45 +0000 Subject: r11579: syncing up perf counter code cfrom trunk (This used to be commit 59c00924b67aa3d37a933731a56d03963ec7f1b5) --- examples/perfcounter/perf_writer.c | 214 +++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 examples/perfcounter/perf_writer.c (limited to 'examples/perfcounter/perf_writer.c') diff --git a/examples/perfcounter/perf_writer.c b/examples/perfcounter/perf_writer.c new file mode 100644 index 0000000000..04127f5621 --- /dev/null +++ b/examples/perfcounter/perf_writer.c @@ -0,0 +1,214 @@ +/* + * Unix SMB/CIFS implementation. + * Performance Counter Daemon + * + * Copyright (C) Marcin Krzysztof Porwit 2005 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "perf.h" + +sig_atomic_t keep_running = TRUE; + +/* allocates memory and gets numCPUs, total memory, and PerfFreq, number of disks... */ +void get_constants(PERF_DATA_BLOCK *data) +{ + data->cpuInfo.numCPUs = sysconf(_SC_NPROCESSORS_ONLN); + data->PerfFreq = sysconf(_SC_CLK_TCK); + init_mem_data(data); + init_cpu_data(data); + init_process_data(data); + init_disk_data(data); + + return; +} + +void output_num_instances(PerfCounter obj, int numInst, RuntimeSettings rt) +{ + char key[NAME_LEN]; + char sdata[NAME_LEN]; + + make_key(key, NAME_LEN, obj.index, "inst"); + memset(sdata, 0, NAME_LEN); + sprintf(sdata, "%d", numInst); + add_key(rt.cnames, key, sdata, TDB_INSERT); + + return; +} + +void output_perf_desc(PerfCounter counter, RuntimeSettings rt) +{ + char key[NAME_LEN]; + char sdata[NAME_LEN]; + + /* First insert the counter name */ + make_key(key, NAME_LEN, counter.index, NULL); + add_key(rt.cnames, key, counter.name, TDB_INSERT); + /* Add the help string */ + make_key(key, NAME_LEN, counter.index + 1, NULL); + add_key(rt.cnames, key, counter.help, TDB_INSERT); + /* Add the relationships */ + make_key(key, NAME_LEN, counter.index, "rel"); + add_key(rt.cnames, key, counter.relationships, TDB_INSERT); + /* Add type data if not PERF_OBJECT or PERF_INSTANCE */ + if(counter.record_type == PERF_COUNTER) + { + make_key(key, NAME_LEN, counter.index, "type"); + memset(sdata, 0, NAME_LEN); + sprintf(sdata, "%d", counter.counter_type); + add_key(rt.cnames, key, sdata, TDB_INSERT); + } + + return; +} + +void initialize(PERF_DATA_BLOCK *data, RuntimeSettings *rt, int argc, char **argv) +{ + memset(data, 0, sizeof(*data)); + memset(rt, 0, sizeof(*data)); + + parse_flags(rt, argc, argv); + setup_file_paths(rt); + + get_constants(data); + + if(rt->dflag == TRUE) + daemonize(rt); + + output_mem_desc(data, *rt); + output_cpu_desc(data, *rt); + output_process_desc(data, *rt); + output_disk_desc(data, *rt); + + return; +} + +void refresh_perf_data_block(PERF_DATA_BLOCK *data, RuntimeSettings rt) +{ + data->PerfTime100nSec = 0; + get_meminfo(data); + get_cpuinfo(data); + get_processinfo(data); + get_diskinfo(data); + return; +} + +void output_perf_counter(PerfCounter counter, unsigned long long data, + RuntimeSettings rt, int tdb_flags) +{ + char key[NAME_LEN]; + char sdata[NAME_LEN]; + unsigned int size_mask; + + make_key(key, NAME_LEN, counter.index, NULL); + memset(sdata, 0, NAME_LEN); + + size_mask = counter.counter_type & PERF_SIZE_VARIABLE_LEN; + + if(size_mask == PERF_SIZE_DWORD) + sprintf(sdata, "%d", (unsigned int)data); + else if(size_mask == PERF_SIZE_LARGE) + sprintf(sdata, "%Lu", data); + + add_key(rt.cdata, key, sdata, tdb_flags); + + return; +} + +void output_perf_instance(int parentObjInd, + int instanceInd, + void *instData, + size_t dsize, + char *name, + RuntimeSettings rt, + int tdb_flags) +{ + char key[NAME_LEN]; + char sdata[NAME_LEN]; + + memset(key, 0, NAME_LEN); + sprintf(key, "%di%d", parentObjInd, instanceInd); + add_key_raw(rt.cdata, key, instData, dsize, tdb_flags); + + /* encode name */ + memset(key, 0, NAME_LEN); + sprintf(key, "%di%dname", parentObjInd, instanceInd); + add_key(rt.cnames, key, name, tdb_flags); + + return; +} + +void output_global_data(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags) +{ + int i; + char key[NAME_LEN]; + char sdata[NAME_LEN]; + + /* Initialize BaseIndex */ + make_key(key, NAME_LEN, 1, NULL); + memset(sdata, 0, NAME_LEN); + sprintf(sdata, "%d", data->num_counters); + add_key(rt.cnames, key, sdata, tdb_flags); + /* Initialize PerfTime, PerfFreq and PerfTime100nSec */ + memset(sdata, 0, NAME_LEN); + make_key(key, NAME_LEN, 0, "PerfTime"); + sprintf(sdata, "%Lu", data->PerfTime); + add_key(rt.cdata, key, sdata, tdb_flags); + make_key(key, NAME_LEN, 0, "PerfTime100nSec"); + memset(sdata, 0, NAME_LEN); + sprintf(sdata, "%Lu", data->PerfTime100nSec); + add_key(rt.cdata, key, sdata, tdb_flags); + memset(sdata, 0, NAME_LEN); + make_key(key, NAME_LEN, 0, "PerfFreq"); + sprintf(sdata, "%Lu", data->PerfFreq); + add_key(rt.cnames, key, sdata, tdb_flags); + + return; +} + +void output_perf_data_block(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags) +{ + output_global_data(data, rt, tdb_flags); + output_meminfo(data, rt, tdb_flags); + output_cpuinfo(data, rt, tdb_flags); + output_processinfo(data, rt, tdb_flags); + output_diskinfo(data, rt, tdb_flags); + return; +} + +void update_counters(PERF_DATA_BLOCK *data, RuntimeSettings rt) +{ + refresh_perf_data_block(data, rt); + output_perf_data_block(data, rt, TDB_REPLACE); + + return; +} + +int main(int argc, char **argv) +{ + PERF_DATA_BLOCK data; + RuntimeSettings rt; + + initialize(&data, &rt, argc, argv); + + while(keep_running) + { + update_counters(&data, rt); + sleep(1); + } + + return 0; +} -- cgit From b84c86f7c99ee8671d134f792b1dbbfe89ca368f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 24 Feb 2006 17:53:25 +0000 Subject: r13677: patch from Max N. Boyarov Prevent div/0 when sysconf(_SC_NPROCESSORS_ONLN) fails. (This used to be commit 9a335255529d0e93dabbb6b0910f10fa162f9d4a) --- examples/perfcounter/perf_writer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/perfcounter/perf_writer.c') diff --git a/examples/perfcounter/perf_writer.c b/examples/perfcounter/perf_writer.c index 04127f5621..00e47bdaba 100644 --- a/examples/perfcounter/perf_writer.c +++ b/examples/perfcounter/perf_writer.c @@ -26,7 +26,7 @@ sig_atomic_t keep_running = TRUE; /* allocates memory and gets numCPUs, total memory, and PerfFreq, number of disks... */ void get_constants(PERF_DATA_BLOCK *data) { - data->cpuInfo.numCPUs = sysconf(_SC_NPROCESSORS_ONLN); + data->cpuInfo.numCPUs = sysconf(_SC_NPROCESSORS_ONLN) > 0 ? sysconf(_SC_NPROCESSORS_ONLN) : 1; data->PerfFreq = sysconf(_SC_CLK_TCK); init_mem_data(data); init_cpu_data(data); -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- examples/perfcounter/perf_writer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/perfcounter/perf_writer.c') diff --git a/examples/perfcounter/perf_writer.c b/examples/perfcounter/perf_writer.c index 00e47bdaba..c967579b89 100644 --- a/examples/perfcounter/perf_writer.c +++ b/examples/perfcounter/perf_writer.c @@ -6,7 +6,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- examples/perfcounter/perf_writer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/perfcounter/perf_writer.c') diff --git a/examples/perfcounter/perf_writer.c b/examples/perfcounter/perf_writer.c index c967579b89..4260f9595d 100644 --- a/examples/perfcounter/perf_writer.c +++ b/examples/perfcounter/perf_writer.c @@ -15,8 +15,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "perf.h" -- cgit