[Nagios-devel] putting my money where my mouth is (re: the novel idea)

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] putting my money where my mouth is (re: the novel idea)

Post by Guest »

--IrhDeMKUP4DT/M7F
Content-Type: multipart/mixed; boundary="SLDf9lqlvOQaIe6s"
Content-Disposition: inline


--SLDf9lqlvOQaIe6s
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

so, in light of last night's discussion, i decided to throw together
a small proof of concept to illustrate my point. attached are three
files:

- check_hello.c, a simple "plugin" that prints hello world.
- a Makefile that illustrates just how easy it is to build a
shared object in the way i suggested
- dltest.c, a program that benchmarks one vs. the other by
executing the system/function calls 1000 times and recording
elapsed time in microseconds (i'd recommend piping stdout
to /dev/null)

this is what i get:

copelandia[~/nagiosplug/plugtest]09:41:03$ ./dltest >/dev/null
dlopen: 131
system: 3698327


sean

--SLDf9lqlvOQaIe6s
Content-Type: text/x-csrc; charset=us-ascii
Content-Disposition: attachment; filename="check_hello.c"

#include

int main(){
printf("hello, world!\n");
}

--SLDf9lqlvOQaIe6s
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=Makefile

dltest: dltest.c
gcc -g -o dltest dltest.c -ldl

check_hello.o: check_hello.c
gcc -c check_hello.c

check_hello.shared.o: check_hello.c
gcc -c -fPIC -Dmain=check_hello check_hello.c

check_hello: check_hello.o
gcc -o check_hello check_hello.o

check_hello.so: check_hello.shared.o
ld -shared -o check_hello.so check_hello.o

test:
./dltest

--SLDf9lqlvOQaIe6s
Content-Type: text/x-csrc; charset=us-ascii
Content-Disposition: attachment; filename="dltest.c"
Content-Transfer-Encoding: quoted-printable

#include
#include
#include
#include

const char *ourgv[24] =3D{ "check_hello", NULL };
const char *ourcmd =3D "check_hello";
extern int optind;

int main(){
int i;
struct timeval start, midway, end;
long total_func, total_sys;
void *libhandle=3DNULL;=20
int (*check_func)(int, const char**)=3DNULL;
libhandle=3Ddlopen("./check_hello.so", RTLD_NOW);
if(libhandle=3D=3DNULL){
fprintf(stderr, "libhandle was null. damn. %s\n", dlerror());
}
*(void**)(&check_func) =3Ddlsym(libhandle, "check_hello");
if(check_func=3D=3DNULL || *check_func =3D=3D NULL){
fprintf(stderr, "check_func was null. damn. %s\n", dlerror());
}
=09
gettimeofday(&start, NULL);
for(i=3D0; i<1000; i++){
system(ourcmd);
}
gettimeofday(&midway, NULL);
for(i=3D0; i<1000; i++){
(*check_func)(1, ourgv);
}
gettimeofday(&end, NULL);

total_sys =3D ((midway.tv_sec - start.tv_sec)*1000000) + (midway.tv_usec -=
start.tv_usec);
total_func =3D ((end.tv_sec - midway.tv_sec)*1000000) + (end.tv_usec - mid=
way.tv_usec);

fprintf(stderr, "dlopen: %ld\n", total_func);
fprintf(stderr, "system: %ld\n", total_sys);
}

--SLDf9lqlvOQaIe6s--

--IrhDeMKUP4DT/M7F
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFCf2sNynjLPm522B0RAq2EAJ9jwQLatMGvD+Rwe6p8mZcVJxLvXwCggEJq
2Jv/UpGYcA0QvqJVjCbCre8=
=VuOI
-----END PGP SIGNATURE-----

--IrhDeMKUP4DT/M7F--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked