Skip to content

Commit

Permalink
* Added checkpointing to mpg.pl app generation as command line option…
Browse files Browse the repository at this point in the history
…s (-c and -cz)

* Updated the Documentation generation for mpg.pl to point to a more generic project name
  • Loading branch information
jredmondson committed Nov 12, 2018
1 parent 80eb73b commit 194b025
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scripts/projects/common/docs/Documentation.mpc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ project (documentation_custom) : doxygen_help_gen, build_files {
}

DoxygenTypeSupport_Files {
Doxyfile.dxy >> rislab
Doxyfile.dxy >> api
}
}

66 changes: 58 additions & 8 deletions scripts/projects/common/src/app.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// non-MADARA includes
#include <memory>

// MADARA includes
#include "madara/knowledge/KnowledgeBase.h"
#include "madara/knowledge/CheckpointStreamer.h"
#include "madara/threads/Threader.h"
#include "madara/utility/EpochEnforcer.h"
#include "madara/utility/Utility.h"
#include "madara/knowledge/containers/Integer.h"

// DO NOT DELETE THIS SECTION

Expand Down Expand Up @@ -42,12 +47,18 @@ std::string save_transport_prefix;
std::string save_transport_text;
std::string load_transport_prefix;

// checkpoint settings
knowledge::CheckpointSettings chkpt_settings;
double checkpoint_hertz = 100;

void print_usage(char * prog_name)
{
madara_logger_ptr_log(madara::logger::global_logger.get(),
madara::logger::LOG_ALWAYS,
"\nProgram summary for %s:\n\n"
" [-b |--broadcast ip:port] the broadcast ip to send and listen to\n"
" [-c |--checkpoint filename] save state to a checkpoint file for retrieval\n"
" [-cz |--checkpoint-hz hz] maximum periodicity to save checkpoints at\n"
" [-d |--domain domain] the knowledge domain to send and listen to\n"
" [-e |--rebroadcasts num] number of hops for rebroadcasting messages\n"
" [-f |--logfile file] log to a file\n"
Expand Down Expand Up @@ -94,10 +105,39 @@ void handle_arguments(int argc, char ** argv)

++i;
}
else if (arg1 == "-c" || arg1 == "--checkpoint")
{
if (i + 1 < argc)
{
chkpt_settings.filename = argv[i + 1];
}
else
{
print_usage(argv[0]);
}

++i;
}
else if (arg1 == "-cz" || arg1 == "--checkpoint-hz")
{
if (i + 1 < argc && argv[i + 1][0] != '-')
{
std::stringstream buffer(argv[i + 1]);
buffer >> checkpoint_hertz;
}
else
{
print_usage(argv[0]);
}

++i;
}
else if (arg1 == "-d" || arg1 == "--domain")
{
if (i + 1 < argc && argv[i + 1][0] != '-')
{
settings.write_domain = argv[i + 1];
}
else
{
print_usage(argv[0]);
Expand Down Expand Up @@ -411,6 +451,21 @@ int main(int argc, char ** argv)
// create knowledge base
knowledge::KnowledgeBase kb;

// setup an example container
knowledge::containers::Integer var1 ("var1", kb);

// setup checkpoint streaming, if configured on command line
std::unique_ptr<knowledge::CheckpointStreamer> streamer = 0;

if (chkpt_settings.filename != "" && checkpoint_hertz > 0)
{
std::cerr << "Saving checkpoints to " << chkpt_settings.filename << "\n";

streamer.reset (new knowledge::CheckpointStreamer(
chkpt_settings, kb.get_context(), checkpoint_hertz));
kb.attach_streamer(std::move(streamer));
}

// create threader for thread launching and control
madara::threads::Threader threader (kb);

Expand All @@ -432,14 +487,6 @@ int main(int argc, char ** argv)
kb.evaluate(madara_commands,
knowledge::EvalSettings(false, true));
}

/**
* WARNING: the following section will be regenerated whenever new threads
* are added via this tool. So, you can adjust hertz rates and change how
* the thread is initialized, but the entire section will be regenerated
* with all threads in the threads directory, whenever you use the new
* thread option with the gpc.pl script.
**/

// begin thread creation
// end thread creation
Expand All @@ -456,6 +503,9 @@ int main(int argc, char ** argv)
{
std::cerr << "Executing app control loop\n";

// increment the Integer container var to change knowledge
++var1;

// print knowledge base and send modifieds
kb.print();
kb.send_modifieds();
Expand Down

0 comments on commit 194b025

Please sign in to comment.