[Compbench-devel] CompBenchmarks++/Benchmark Benchmark-DLLoader.cpp, NONE, 1.1 Benchmark-DLLoader.h
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2006-11-01 13:03:17
|
Update of /cvsroot/compbench/CompBenchmarks++/Benchmark In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv11449 Modified Files: Makefile.am Added Files: Benchmark-DLLoader.cpp Benchmark-DLLoader.h Log Message: Dynamic library handling inferface. --- NEW FILE: Benchmark-DLLoader.cpp --- #include <Benchmark/Benchmark-DLLoader.h> #include <string> #include <iostream> #include <vector> #include <config.h> /* cache... */ std::vector<cbmlib_internal*> cbmlib_loaded_libraries; cbmlib_internal *cbmlib_check_previousload(char *package_id) { int i; int s = cbmlib_loaded_libraries.size(); cbmlib_internal *l; for(i=0; i<s; i++) { l=cbmlib_loaded_libraries[i]; if (l->package_id==package_id) return(l); } return(0); } cbmlib_internal *cbmlib_load_internal(const char *lib, char *package_id) { void *library; cbmlib_internal *r; std::cout << "Loading " << lib << "... "; r=cbmlib_check_previousload(package_id); if (r) { std::cout << "found (cached)." << std::endl; return(r); } library=dlopen(lib, RTLD_NOW); if (library) { std::cout << "found." << std::endl; r=new cbmlib_internal; r->library=library; std::cout << " Checking cbmlib_getBenchmarkNumber... "; r->Number=(cbmlib_internal_number_t) (dlsym(r->library, "cbmlib_getBenchmarkNumber")); if (!r->Number) { dlclose(library); std::cout << "N.A." << std::endl; delete(r); return(0); } else { std::cout << "found." << std::endl; } std::cout << " Checking cbmlib_getBenchmark... "; r->Bench=(cbmlib_internal_bench_t) dlsym(r->library, "cbmlib_getBenchmark"); if (!r->Bench) { dlclose(library); std::cout << "N.A." << std::endl; delete(r); return(0); } else { std::cout << "found." << std::endl; } std::cout << " Checking cbmlib_getBenchmarkByName... "; r->BenchByName=(cbmlib_internal_benchbyname_t) dlsym(r->library, "cbmlib_getBenchmarkByName"); if (!r->Bench) { dlclose(library); std::cout << "N.A." << std::endl; delete(r); return(0); } else { std::cout << "found." << std::endl; } r->package_id=package_id; cbmlib_loaded_libraries.push_back(r); return(r); } else { std::cout << "N.A." << std::endl; } return(0); } cbmlib_internal *cbmlib_load(char *package_id) { std::string local = "./Benchmark/.libs/libcompbenchmarks-"; cbmlib_internal *r; local+=package_id; local+=".so"; r=cbmlib_load_internal(local.c_str(), package_id); if (r) return(r); local=PREFIX; local+="/lib/libcompbenchmarks-"; local+=package_id; local+=".so"; r=cbmlib_load_internal(local.c_str(), package_id); return(r); } CBMBenchmark *cbmlib_bench_load(char *bench_id, CBMSystem *_system) { std::string bench = bench_id; std::string package = _system->Split(bench, "-", 0); CBMBenchmark *b; cbmlib_internal *l = cbmlib_load((char*) package.c_str()); if (l) { b=l->BenchByName(bench_id, _system); return(b); } else return(0); } void cbmlib_done(void) { int i; int s = cbmlib_loaded_libraries.size(); cbmlib_internal *l; for(i=0; i<s; i++) { l=cbmlib_loaded_libraries[i]; dlclose(l->library); delete(l); } } --- NEW FILE: Benchmark-DLLoader.h --- /* ---------------------------------------------------------------------------- $Id: Benchmark-DLLoader.h,v 1.1 2006/11/01 13:03:13 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMBENCHMARKDLLOADER #define H_CBMBENCHMARKDLLOADER #include <System/System.h> #include <Benchmark/Benchmark.h> #include <dlfcn.h> /** Function prototype for getting benchmark's number in a shared library */ typedef int (*cbmlib_internal_number_t)(void); /** Function prototype for getting a benchmark object by its index */ typedef CBMBenchmark* (*cbmlib_internal_bench_t)(int, CBMSystem*); /** Function prototype for getting a benchmark object by its name */ typedef CBMBenchmark* (*cbmlib_internal_benchbyname_t)(char*, CBMSystem*); /** Internal benchmark's shared library object */ typedef struct cbmlib_internal { void *library; std::string package_id; cbmlib_internal_number_t Number; cbmlib_internal_bench_t Bench; cbmlib_internal_benchbyname_t BenchByName; }; /** \brief Load a library according to the benchmark/package's internal name. \param package_id something like gzip, bzip2, nbench and so on. */ cbmlib_internal *cbmlib_load(char *package_id); /** \brief Gets a CBMBenchmark instance from a shared library. \param bench_id gzip-1c, benchpp-whetstone and so on. \param _system A system instance. */ CBMBenchmark *cbmlib_bench_load(char *bench_id, CBMSystem *_system); /** \brief Remove any internal existing reference to shared library. */ void cbmlib_done(void); #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/Benchmark/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.am 1 Nov 2006 13:00:50 -0000 1.7 --- Makefile.am 1 Nov 2006 13:03:13 -0000 1.8 *************** *** 45,52 **** CBM_GENLIBWRAPPER = $(top_srcdir)/Benchmark/benchmarks-genlibwrapper.sh ! CBM_GENLIST = $(top_srcdir)/Benchmark/benchmarks-list.sh ! extra_DIST = benchmarks-genlibwrapper.sh benchmarks-list.sh benchmarks.list %.libwrapper.h: $(top_srcdir)/Benchmark/benchmarks.list $(CBM_GENLIBWRAPPER) --- 45,52 ---- CBM_GENLIBWRAPPER = $(top_srcdir)/Benchmark/benchmarks-genlibwrapper.sh ! CBM_GENLIBLIST = $(top_srcdir)/Benchmark/benchmarks-genliblist.sh ! extra_DIST = benchmarks-genlibwrapper.sh benchmarks-genliblist.sh benchmarks.list %.libwrapper.h: $(top_srcdir)/Benchmark/benchmarks.list $(CBM_GENLIBWRAPPER) *************** *** 54,60 **** @$(CBM_GENLIBWRAPPER) $@ $(top_srcdir)/Benchmark > $@ ! Benchmark-Selector.liblist.h: $(top_srcdir)/Benchmark/benchmarks.list $(CBM_GENLIST) @echo "Generating benchmark's list in $@" ! @$(CBM_GENLIST) > $@ clean-all: rm *.libwrapper.h *.liblist.h \ No newline at end of file --- 54,60 ---- @$(CBM_GENLIBWRAPPER) $@ $(top_srcdir)/Benchmark > $@ ! Benchmark-Selector.liblist.h: $(top_srcdir)/Benchmark/benchmarks.list $(CBM_GENLIBLIST) @echo "Generating benchmark's list in $@" ! @$(CBM_GENLIBLIST) > $@ clean-all: rm *.libwrapper.h *.liblist.h \ No newline at end of file |