23 #include <blackboard/bbconfig.h> 24 #include <blackboard/internal/memory_manager.h> 25 #include <blackboard/internal/interface_mem_header.h> 26 #include <blackboard/exceptions.h> 27 #include <utils/system/console_colors.h> 28 #include <utils/time/time.h> 29 #include <config/sqlite.h> 38 main(
int argc,
char **argv)
43 std::string token =
"";
45 token = config.
get_string(
"/fawkes/mainapp/blackboard_magic_token");
47 cout <<
"Could not read shared memory token for blackboard." << endl;
48 cout <<
"BlackBoard is probably running without shared memory." << endl;
59 cout <<
"No BlackBoard shared memory segment found!" << endl;
63 cout << endl << cblue <<
"Fawkes BlackBoard Memory Info" << cnormal << endl
64 <<
"========================================================================" << endl;
66 printf(
"Memory Size: %s%8u%s %sB%s BlackBoard version: %s%u%s\n" 67 "Free Memory: %s%8u%s %sB%s Alloc. memory: %s%8u%s %sB%s Overhang: %s%8u%s %sB%s\n" 68 "Free Chunks: %s%8u%s Alloc. chunks: %s%8u%s\n",
69 cdarkgray.c_str(), memmgr->
memory_size(), cnormal.c_str(),
70 clightgray.c_str(), cnormal.c_str(),
71 cdarkgray.c_str(), memmgr->
version(), cnormal.c_str(),
72 cdarkgray.c_str(), memmgr->
free_size(), cnormal.c_str(),
73 clightgray.c_str(), cnormal.c_str(),
75 clightgray.c_str(), cnormal.c_str(),
77 clightgray.c_str(), cnormal.c_str(),
83 gettimeofday(&a, NULL);
84 cout <<
"Waiting for lock on shared memory.. " << flush;
86 gettimeofday(&b, NULL);
87 cout <<
"lock aquired. Waited " <<
time_diff_sec(b, a) <<
" seconds" << endl;
90 if ( memmgr->
begin() == memmgr->
end() ) {
91 cout <<
"No interfaces allocated." << endl;
93 cout << endl <<
"Interfaces:" << endl;
95 printf(
"%sMemSize Overhang Type/ID/Hash Serial Ref W/R%s\n" 96 "------------------------------------------------------------------------\n",
97 cdarkgray.c_str(), cnormal.c_str());
101 for ( cit = memmgr->
begin(); cit != memmgr->
end(); ++cit ) {
102 if ( *cit == NULL ) {
103 cout <<
"*cit == NULL" << endl;
107 char tmp_hash[__INTERFACE_HASH_SIZE * 2 + 1];
108 for (
size_t s = 0; s < __INTERFACE_HASH_SIZE; ++s) {
109 snprintf(&tmp_hash[s*2], 3,
"%02X", ih->hash[s]);
111 printf(
"%7u %8u %sT%s %-32s %6u %3u %1d/%-3d\n%18s %sI%s %-32s\n%18s %sH%s %-32s\n",
112 cit.
size(), cit.
overhang(), clightgray.c_str(), cnormal.c_str(), ih->type,
113 ih->serial, ih->refcount, ih->flag_writer_active, ih->num_readers,
114 "", clightgray.c_str(), cnormal.c_str(), ih->id,
115 "", clightgray.c_str(), cnormal.c_str(), tmp_hash);
unsigned int size() const
Get size of data segment.
ChunkIterator begin()
Get first element for chunk iteration.
virtual void load(const char *file_path)=0
Load configuration.
unsigned int allocated_size() const
Get total allocated memory.
Configuration storage using SQLite.
Fawkes library namespace.
ChunkIterator end()
Get end of chunk list.
BlackBoard memory manager.
unsigned int memory_size() const
Get size of memory.
bool try_lock()
Try to lock memory.
unsigned int version() const
Get BlackBoard version.
unsigned int num_free_chunks() const
Get number of free chunks.
Base class for exceptions in Fawkes.
Thrown if shared memory could not be opened.
double time_diff_sec(const timeval &a, const timeval &b)
Calculate time difference of two time structs.
unsigned int free_size() const
Get total free memory.
Iterator for memory chunks.
unsigned int overhang() const
Get number of overhanging bytes.
void unlock()
Unlock memory.
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
unsigned int num_allocated_chunks() const
Get number of allocated chunks.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
unsigned int overhang_size() const
Get number of overhanging bytes.