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>
35 using namespace fawkes;
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);
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
ChunkIterator begin()
Get first element for chunk iteration.
unsigned int overhang_size() const
Get number of overhanging bytes.
Configuration storage using SQLite.
ChunkIterator end()
Get end of chunk list.
unsigned int size() const
Get size of data segment.
unsigned int overhang() const
Get number of overhanging bytes.
BlackBoard memory manager.
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
unsigned int num_allocated_chunks() const
Get number of allocated chunks.
bool try_lock()
Try to lock memory.
virtual void load(const char *filename, const char *defaults_filename, const char *tag=NULL)
Load configuration.
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.
Iterator for memory chunks.
unsigned int memory_size() const
Get size of memory.
void unlock()
Unlock memory.
unsigned int version() const
Get BlackBoard version.
unsigned int allocated_size() const
Get total allocated memory.
unsigned int free_size() const
Get total free memory.
unsigned int num_free_chunks() const
Get number of free chunks.