Commit 180dc47a authored by Millian Poquet's avatar Millian Poquet

Verbosity level can now be configured easily (-v or --verbosity option)

parent 82cb1368
......@@ -7,6 +7,8 @@
#include <simgrid/msg.h>
#include <simgrid/plugins.h>
#include <boost/algorithm/string/case_conv.hpp>
#include "context.hpp"
#include "export.hpp"
#include "ipp.hpp"
......@@ -22,6 +24,14 @@ using namespace std;
XBT_LOG_NEW_DEFAULT_CATEGORY(batsim, "batsim");
enum class VerbosityLevel
{
QUIET,
NETWORK_ONLY,
INFORMATION,
DEBUG
};
/**
* @brief The main function arguments (a.k.a. program arguments)
*/
......@@ -36,7 +46,7 @@ struct MainArguments
std::string exportPrefix; //! The filename prefix used to export simulation information
bool energy_used; //! True if and only if the SimGrid energy plugin should be used.
bool quiet; //! True to disable any Batsim output
VerbosityLevel verbosity; //! Sets the Batsim verbosity
bool abort; //! A boolean value. If set to yet, the launching should be aborted for reason abortReason
std::string abortReason; //! Human readable reasons which explains why the launch should be aborted
......@@ -64,8 +74,27 @@ static int parse_opt (int key, char *arg, struct argp_state *state)
case 'p':
mainArgs->energy_used = true;
break;
case 'v':
{
string sArg = arg;
boost::to_lower(sArg);
if (sArg == "quiet")
mainArgs->verbosity = VerbosityLevel::QUIET;
else if (sArg == "network-only")
mainArgs->verbosity = VerbosityLevel::NETWORK_ONLY;
else if (sArg == "information")
mainArgs->verbosity = VerbosityLevel::INFORMATION;
else if (sArg == "debug")
mainArgs->verbosity = VerbosityLevel::DEBUG;
else
{
mainArgs->abort = true;
mainArgs->abortReason += "\n invalid VERBOSITY_LEVEL argument: '" + string(sArg) + "' is not in [quiet, network-only, information, debug].";
}
break;
}
case 'q':
mainArgs->quiet = true;
mainArgs->verbosity = VerbosityLevel::QUIET;
break;
case 's':
mainArgs->socketFilename = arg;
......@@ -116,7 +145,7 @@ int main(int argc, char * argv[])
mainArgs.masterHostName = "master_host";
mainArgs.exportPrefix = "out";
mainArgs.energy_used = false;
mainArgs.quiet = false;
mainArgs.verbosity = VerbosityLevel::INFORMATION;
mainArgs.abort = false;
struct argp_option options[] =
......@@ -125,7 +154,8 @@ int main(int argc, char * argv[])
{"master-host", 'm', "NAME", 0, "The name of the host in PLATFORM_FILE which will run SimGrid scheduling processes and won't be used to compute tasks", 0},
{"export", 'e', "FILENAME_PREFIX", 0, "The export filename prefix used to generate simulation output", 0},
{"energy-plugin", 'p', 0, 0, "Enables energy-aware experiments", 0},
{"quiet", 'q', 0, 0, "Disables any output", 0},
{"verbosity", 'v', "VERBOSITY_LEVEL", 0, "Sets the Batsim verbosity level. Available values are : quiet, network-only, information (default), debug.", 0},
{"quiet", 'q', 0, 0, "Shortcut for --verbosity=quiet", 0},
{0, '\0', 0, 0, 0, 0} // The options array must be NULL-terminated
};
struct argp argp = {options, parse_opt, "PLATFORM_FILE WORKLOAD_FILE", "A tool to simulate (via SimGrid) the behaviour of scheduling algorithms.", 0, 0, 0};
......@@ -140,7 +170,12 @@ int main(int argc, char * argv[])
if (mainArgs.energy_used)
sg_energy_plugin_init();
if (mainArgs.quiet)
/*QUIET,
NETWORK_ONLY,
INFORMATION,
DEBUG */
if (mainArgs.verbosity == VerbosityLevel::QUIET || mainArgs.verbosity == VerbosityLevel::NETWORK_ONLY)
{
xbt_log_control_set("workload.thresh:error");
xbt_log_control_set("jobs.thresh:error");
......@@ -151,9 +186,29 @@ int main(int argc, char * argv[])
xbt_log_control_set("export.thresh:error");
xbt_log_control_set("profiles.thresh:error");
xbt_log_control_set("network.thresh:error");
xbt_log_control_set("server.thresh:error");
xbt_log_control_set("ipp.thresh:error");
}
if (mainArgs.verbosity == VerbosityLevel::NETWORK_ONLY)
{
xbt_log_control_set("network.thresh:info");
}
else if (mainArgs.verbosity == VerbosityLevel::DEBUG)
{
xbt_log_control_set("workload.thresh:debug");
xbt_log_control_set("jobs.thresh:debug");
xbt_log_control_set("batsim.thresh:debug");
xbt_log_control_set("machines.thresh:debug");
xbt_log_control_set("pstate.thresh:debug");
xbt_log_control_set("jobs_execution.thresh:debug");
xbt_log_control_set("export.thresh:debug");
xbt_log_control_set("profiles.thresh:debug");
xbt_log_control_set("network.thresh:debug");
xbt_log_control_set("server.thresh:debug");
xbt_log_control_set("ipp.thresh:debug");
}
// Initialization
MSG_init(&argc, argv);
......
......@@ -17,6 +17,7 @@
#include "jobs_execution.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(network, "network");
XBT_LOG_NEW_CATEGORY(server, "server");
using namespace std;
......@@ -48,7 +49,7 @@ UnixDomainSocket::~UnixDomainSocket()
void UnixDomainSocket::create_socket(const string & filename)
{
XBT_INFO("Creating UDS socket on '%s'", filename.c_str());
XBT_CINFO(network, "Creating UDS socket on '%s'", filename.c_str());
_server_socket = socket(AF_UNIX, SOCK_STREAM, 0);
xbt_assert(_server_socket != -1, "Impossible to create socket");
......@@ -69,10 +70,10 @@ void UnixDomainSocket::create_socket(const string & filename)
void UnixDomainSocket::accept_pending_connection()
{
XBT_INFO("Waiting for an incoming connection...");
XBT_CINFO(network, "Waiting for an incoming connection...");
_client_socket = accept(_server_socket, NULL, NULL);
xbt_assert(_client_socket != -1, "Impossible to accept on socket");
XBT_INFO("Connected!");
XBT_CINFO(network, "Connected!");
}
string UnixDomainSocket::receive()
......@@ -142,7 +143,7 @@ int request_reply_scheduler_process(int argc, char *argv[])
sprintf(sendDateAsString, "%f", MSG_get_clock());
char *sendBuf = (char*) args->send_buffer.c_str();
XBT_INFO("Buffer received in REQ-REP: '%s'", sendBuf);
XBT_CDEBUG(server, "Buffer received in REQ-REP: '%s'", sendBuf);
context->socket.send(sendBuf);
......@@ -391,21 +392,21 @@ int uds_server_process(int argc, char *argv[])
MSG_task_receive(&(task_received), "server");
task_data = (IPMessage *) MSG_task_get_data(task_received);
XBT_INFO("Server received a message of type %s:", ipMessageTypeToString(task_data->type).c_str());
XBT_CINFO(server, "Server received a message of type %s:", ipMessageTypeToString(task_data->type).c_str());
switch (task_data->type)
{
case IPMessageType::SUBMITTER_HELLO:
{
nb_submitters++;
XBT_INFO("New submitter said hello. Number of polite submitters: %d", nb_submitters);
XBT_CINFO(server, "New submitter said hello. Number of polite submitters: %d", nb_submitters);
} break; // end of case SUBMITTER_HELLO
case IPMessageType::SUBMITTER_BYE:
{
nb_submitters_finished++;
XBT_INFO("A submitted said goodbye. Number of finished submitters: %d", nb_submitters_finished);
XBT_CINFO(server, "A submitted said goodbye. Number of finished submitters: %d", nb_submitters_finished);
} break; // end of case SUBMITTER_BYE
......@@ -419,10 +420,10 @@ int uds_server_process(int argc, char *argv[])
nb_completed_jobs++;
Job * job = context->jobs[message->job_id];
XBT_INFO("Job %d COMPLETED. %d jobs completed so far", job->id, nb_completed_jobs);
XBT_CINFO(server, "Job %d COMPLETED. %d jobs completed so far", job->id, nb_completed_jobs);
send_buffer += '|' + std::to_string(MSG_get_clock()) + ":C:" + std::to_string(job->id);
XBT_INFO("Message to send to scheduler: %s", send_buffer.c_str());
XBT_CDEBUG(server, "Message to send to scheduler: %s", send_buffer.c_str());
} break; // end of case JOB_COMPLETED
......@@ -435,9 +436,9 @@ int uds_server_process(int argc, char *argv[])
Job * job = context->jobs[message->job_id];
job->state = JobState::JOB_STATE_SUBMITTED;
XBT_INFO("Job %d SUBMITTED. %d jobs submitted so far", job->id, nb_submitted_jobs);
XBT_CINFO(server, "Job %d SUBMITTED. %d jobs submitted so far", job->id, nb_submitted_jobs);
send_buffer += "|" + std::to_string(MSG_get_clock()) + ":S:" + std::to_string(job->id);
XBT_INFO("Message to send to scheduler: '%s'", send_buffer.c_str());
XBT_CDEBUG(server, "Message to send to scheduler: '%s'", send_buffer.c_str());
} break; // end of case JOB_SUBMITTED
......@@ -450,7 +451,7 @@ int uds_server_process(int argc, char *argv[])
job->state = JobState::JOB_STATE_REJECTED;
nb_completed_jobs++;
XBT_INFO("Job %d has been rejected", job->id);
XBT_CINFO(server, "Job %d has been rejected", job->id);
} break; // end of case SCHED_REJECTION
case IPMessageType::SCHED_NOP_ME_LATER:
......@@ -482,7 +483,7 @@ int uds_server_process(int argc, char *argv[])
send_buffer += "|" + std::to_string(MSG_get_clock()) + ":p:" +
std::to_string(machine->id) + "=" + std::to_string(message->new_pstate);
XBT_INFO("Message to send to scheduler : '%s'", send_buffer.c_str());
XBT_CDEBUG(server, "Message to send to scheduler : '%s'", send_buffer.c_str());
}
else if (machine->pstates[message->new_pstate] == PStateType::SLEEP_PSTATE)
{
......@@ -497,7 +498,7 @@ int uds_server_process(int argc, char *argv[])
MSG_process_create(pname.c_str(), switch_on_machine_process, (void*)args, machine->host);
}
else
XBT_ERROR("Switching from a communication pstate to an invalid pstate on machine %d ('%s') : %d -> %d",
XBT_CERROR(server, "Switching from a communication pstate to an invalid pstate on machine %d ('%s') : %d -> %d",
machine->id, machine->name.c_str(), curr_pstate, message->new_pstate);
}
else if (machine->pstates[curr_pstate] == PStateType::SLEEP_PSTATE)
......@@ -515,20 +516,18 @@ int uds_server_process(int argc, char *argv[])
MSG_process_create(pname.c_str(), switch_off_machine_process, (void*)args, machine->host);
}
else
XBT_ERROR("Machine %d ('%s') has an invalid pstate : %d", machine->id, machine->name.c_str(), curr_pstate);
XBT_CERROR(server, "Machine %d ('%s') has an invalid pstate : %d", machine->id, machine->name.c_str(), curr_pstate);
} break; // end of case PSTATE_MODIFICATION
case IPMessageType::SCHED_NOP:
{
XBT_INFO("Nothing to do received.");
XBT_CINFO(server, "Nothing to do received.");
if (nb_running_jobs == 0 && nb_scheduled_jobs < nb_submitted_jobs)
{
XBT_INFO("Nothing to do whereas no job is running and that they are jobs waiting to be scheduled... This might cause a deadlock!");
XBT_CINFO(server, "Nothing to do whereas no job is running and that they are jobs waiting to be scheduled... This might cause a deadlock!");
// Let us display the available jobs (to help the scheduler debugging)
string debugBuffer;
const std::map<int, Job *> & jobs = context->jobs.jobs();
vector<string> submittedJobs;
......@@ -540,7 +539,7 @@ int uds_server_process(int argc, char *argv[])
string submittedJobsString = boost::algorithm::join(submittedJobs, ", ");
XBT_INFO("The available jobs are [%s]", submittedJobsString.c_str());
XBT_CINFO(server, "The available jobs are [%s]", submittedJobsString.c_str());
}
} break; // end of case SCHED_NOP
......@@ -590,7 +589,7 @@ int uds_server_process(int argc, char *argv[])
case IPMessageType::WAITING_DONE:
{
send_buffer += "|" + std::to_string(MSG_get_clock()) + ":N";
XBT_INFO("Message to send to scheduler: '%s'", send_buffer.c_str());
XBT_CDEBUG(server, "Message to send to scheduler: '%s'", send_buffer.c_str());
} break; // end of case WAITING_DONE
case IPMessageType::SCHED_READY:
......@@ -610,7 +609,7 @@ int uds_server_process(int argc, char *argv[])
send_buffer += "|" + std::to_string(MSG_get_clock()) + ":p:" +
std::to_string(machine->id) + "=" + std::to_string(message->new_pstate);
XBT_INFO("Message to send to scheduler : '%s'", send_buffer.c_str());
XBT_CDEBUG(server, "Message to send to scheduler : '%s'", send_buffer.c_str());
} break; // end of case SWITCHED_ON
case IPMessageType::SWITCHED_OFF:
......@@ -624,7 +623,7 @@ int uds_server_process(int argc, char *argv[])
send_buffer += "|" + std::to_string(MSG_get_clock()) + ":p:" +
std::to_string(machine->id) + "=" + std::to_string(message->new_pstate);
XBT_INFO("Message to send to scheduler : '%s'", send_buffer.c_str());
XBT_CDEBUG(server, "Message to send to scheduler : '%s'", send_buffer.c_str());
} break; // end of case SWITCHED_ON
} // end of switch
......@@ -644,7 +643,7 @@ int uds_server_process(int argc, char *argv[])
} // end of while
XBT_INFO("All jobs completed!");
XBT_CINFO(server, "All jobs completed!");
delete args;
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment