00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <blackboard/bbconfig.h>
00024 #include <blackboard/internal/memory_manager.h>
00025 #include <blackboard/internal/interface_mem_header.h>
00026 #include <blackboard/exceptions.h>
00027 #include <utils/system/console_colors.h>
00028 #include <utils/time/time.h>
00029 #include <config/sqlite.h>
00030
00031 #include <iostream>
00032 #include <cstdio>
00033
00034 using namespace std;
00035 using namespace fawkes;
00036
00037 int
00038 main(int argc, char **argv)
00039 {
00040 SQLiteConfiguration config(CONFDIR);
00041 config.load();
00042
00043 std::string token = "";
00044 try {
00045 token = config.get_string("/fawkes/mainapp/blackboard_magic_token");
00046 } catch (Exception &e) {
00047 cout << "Could not read shared memory token for blackboard." << endl;
00048 cout << "BlackBoard is probably running without shared memory." << endl;
00049 return -1;
00050 }
00051
00052 BlackBoardMemoryManager *memmgr;
00053 try {
00054 memmgr = new BlackBoardMemoryManager( config.get_uint("/fawkes/mainapp/blackboard_size"),
00055 BLACKBOARD_VERSION,
00056 false,
00057 token.c_str());
00058 } catch (BBMemMgrCannotOpenException &e) {
00059 cout << "No BlackBoard shared memory segment found!" << endl;
00060 return 1;
00061 }
00062
00063 cout << endl << cblue << "Fawkes BlackBoard Memory Info" << cnormal << endl
00064 << "========================================================================" << endl;
00065
00066 printf("Memory Size: %s%8u%s %sB%s BlackBoard version: %s%u%s\n"
00067 "Free Memory: %s%8u%s %sB%s Alloc. memory: %s%8u%s %sB%s Overhang: %s%8u%s %sB%s\n"
00068 "Free Chunks: %s%8u%s Alloc. chunks: %s%8u%s\n",
00069 cdarkgray.c_str(), memmgr->memory_size(), cnormal.c_str(),
00070 clightgray.c_str(), cnormal.c_str(),
00071 cdarkgray.c_str(), memmgr->version(), cnormal.c_str(),
00072 cdarkgray.c_str(), memmgr->free_size(), cnormal.c_str(),
00073 clightgray.c_str(), cnormal.c_str(),
00074 cdarkgray.c_str(), memmgr->allocated_size(), cnormal.c_str(),
00075 clightgray.c_str(), cnormal.c_str(),
00076 cdarkgray.c_str(), memmgr->overhang_size(), cnormal.c_str(),
00077 clightgray.c_str(), cnormal.c_str(),
00078 cdarkgray.c_str(), memmgr->num_free_chunks(), cnormal.c_str(),
00079 cdarkgray.c_str(), memmgr->num_allocated_chunks(), cnormal.c_str());
00080
00081 if ( ! memmgr->try_lock() ) {
00082 timeval a, b;
00083 gettimeofday(&a, NULL);
00084 cout << "Waiting for lock on shared memory.. " << flush;
00085 memmgr->lock();
00086 gettimeofday(&b, NULL);
00087 cout << "lock aquired. Waited " << time_diff_sec(b, a) << " seconds" << endl;
00088 }
00089
00090 if ( memmgr->begin() == memmgr->end() ) {
00091 cout << "No interfaces allocated." << endl;
00092 } else {
00093 cout << endl << "Interfaces:" << endl;
00094
00095 printf("%sMemSize Overhang Type/ID/Hash Serial Ref W/R%s\n"
00096 "------------------------------------------------------------------------\n",
00097 cdarkgray.c_str(), cnormal.c_str());
00098
00099 interface_header_t *ih;
00100 BlackBoardMemoryManager::ChunkIterator cit;
00101 for ( cit = memmgr->begin(); cit != memmgr->end(); ++cit ) {
00102 if ( *cit == NULL ) {
00103 cout << "*cit == NULL" << endl;
00104 break;
00105 } else {
00106 ih = (interface_header_t *)*cit;
00107 char tmp_hash[__INTERFACE_HASH_SIZE * 2 + 1];
00108 for (size_t s = 0; s < __INTERFACE_HASH_SIZE; ++s) {
00109 snprintf(&tmp_hash[s*2], 3, "%02X", ih->hash[s]);
00110 }
00111 printf("%7u %8u %sT%s %-32s %6u %3u %1d/%-3d\n%18s %sI%s %-32s\n%18s %sH%s %-32s\n",
00112 cit.size(), cit.overhang(), clightgray.c_str(), cnormal.c_str(), ih->type,
00113 ih->serial, ih->refcount, ih->flag_writer_active, ih->num_readers,
00114 "", clightgray.c_str(), cnormal.c_str(), ih->id,
00115 "", clightgray.c_str(), cnormal.c_str(), tmp_hash);
00116 }
00117 }
00118 }
00119
00120 memmgr->unlock();
00121
00122 delete memmgr;
00123 return 0;
00124 }