Commit f23e8717 authored by Millian Poquet's avatar Millian Poquet

Documentation, +const, -old unused code

parent d02488c9
......@@ -102,7 +102,7 @@ PajeTracer::~PajeTracer()
}
}
void PajeTracer::initialize(BatsimContext *context, double time)
void PajeTracer::initialize(const BatsimContext *context, double time)
{
xbt_assert(state == UNINITIALIZED, "Bad PajeTracer::initialize call: the object is not UNINITIALIZED");
......@@ -274,7 +274,7 @@ void PajeTracer::initialize(BatsimContext *context, double time)
state = INITIALIZED;
}
void PajeTracer::finalize(BatsimContext * context, double time)
void PajeTracer::finalize(const BatsimContext * context, double time)
{
xbt_assert(state == INITIALIZED, "Bad PajeTracer::finalize call: the object has not been initialized yet");
......@@ -366,41 +366,6 @@ void PajeTracer::set_machine_as_computing_job(int machineID, int jobID, double t
_wbuf->appendText(buf);
}
void PajeTracer::addJobRunning(int jobID, const vector<int> & usedMachineIDs, double time)
{
xbt_assert(state == INITIALIZED, "Bad addJobLaunching call: the PajeTracer object is not initialized or had been finalized");
const int bufSize = 64;
char buf[bufSize];
// Let's change the state of all the machines which run the job
for (const int & machineID : usedMachineIDs)
{
snprintf(buf, bufSize,
"%d %lf %s %s%d %s%d\n",
SET_STATE, time, machineState, machinePrefix, machineID, jobPrefix, jobID);
_wbuf->appendText(buf);
}
}
void PajeTracer::addJobEnding(int jobID, const vector<int> & usedMachineIDs, double time)
{
xbt_assert(state == INITIALIZED, "Bad addJobLaunching call: the PajeTracer object is not initialized or had been finalized");
(void) jobID;
const int bufSize = 64;
char buf[bufSize];
// Let's change the state of all the machines which run the job
for (const int & machineID : usedMachineIDs)
{
snprintf(buf, bufSize,
"%d %lf %s %s%d %s\n",
SET_STATE, time, machineState, machinePrefix, machineID, mstateWaiting);
_wbuf->appendText(buf);
}
}
void PajeTracer::addJobKill(int jobID, const MachineRange & usedMachineIDs, double time, bool associateKillToMachines)
{
xbt_assert(state == INITIALIZED, "Bad addJobKill call: the PajeTracer object is not initialized or had been finalized");
......@@ -516,7 +481,7 @@ void PajeTracer::hsvToRgb(double h, double s, double v, double & r, double & g,
}
}
void exportJobsToCSV(const string &filename, BatsimContext *context)
void exportJobsToCSV(const string &filename, const BatsimContext *context)
{
ofstream f(filename, ios_base::trunc);
xbt_assert(f.is_open(), "Cannot write file '%s'", filename.c_str());
......@@ -563,7 +528,7 @@ void exportJobsToCSV(const string &filename, BatsimContext *context)
}
void exportScheduleToCSV(const string &filename, double scheduling_time, BatsimContext *context)
void exportScheduleToCSV(const string &filename, double scheduling_time, const BatsimContext *context)
{
ofstream f(filename, ios_base::trunc);
xbt_assert(f.is_open(), "Cannot write file '%s'", filename.c_str());
......
......@@ -27,8 +27,8 @@ class WriteBuffer
public:
/**
* @brief Builds a WriteBuffer
* @param filename The file that will be written
* @param bufferSize The size of the buffer (in bytes).
* @param[in] filename The file that will be written
* @param[in] bufferSize The size of the buffer (in bytes).
*/
WriteBuffer(const std::string & filename, int bufferSize = 64*1024);
......@@ -40,7 +40,7 @@ public:
/**
* @brief Appends a text at the end of the buffer. If the buffer is full, it is automatically flushed into the disk.
* @param text The text to append
* @param[in] text The text to append
*/
void appendText(const char * text);
......@@ -57,17 +57,19 @@ private:
};
/**
* @brief Exports the job execution to a CSV file.
* @param filename This is the name of the output file used to write the CSV data.
* @brief Exports the job execution to a CSV file
* @param[in] filename The name of the output file used to write the CSV data
* @param[in] context The BatsimContext
*/
void exportJobsToCSV(const std::string &filename, BatsimContext * context);
void exportJobsToCSV(const std::string &filename, const BatsimContext * context);
/**
* @brief Compute and exports some schedule criteria to a CSV file.
* @param filename The is the name of the output file used to write the CSV data.
* @param microseconds_used_by_scheduler The number of seconds the scheduler had hand on execution flow
* @brief Compute and exports some schedule criteria to a CSV file
* @param[in] filename The name of the output file used to write the CSV data
* @param[in] scheduling_time The number of seconds the scheduler had hand on execution flow
* @param[in] context The BatsimContext
*/
void exportScheduleToCSV(const std::string &filename, double scheduling_time, BatsimContext * context);
void exportScheduleToCSV(const std::string &filename, double scheduling_time, const BatsimContext * context);
/**
......@@ -75,14 +77,45 @@ void exportScheduleToCSV(const std::string &filename, double scheduling_time, Ba
*/
class PajeTracer
{
private:
/**
* @brief Enumerates the different states of a PajeTracer
*/
enum PajeTracerState
{
UNINITIALIZED //!< The PajeTracer has not been initialized yet
,INITIALIZED //!< The PajeTracer has been initialized
,FINALIZED //!< The PajeTracer has been finalized
};
/**
* @brief Enumerates the constants used in the output of the Paje trace
*/
enum PajeTracerOutputConstants
{
DEFINE_CONTAINER_TYPE = 1 //!< Defines a container type
,CREATE_CONTAINER //!< Creates a container
,DESTROY_CONTAINER //!< Destroys a container
,DEFINE_STATE_TYPE //!< Defines a state type
,DEFINE_ENTITY_VALUE //!< Defines an entity value
,SET_STATE //!< Sets a state
,DEFINE_EVENT_TYPE //!< Defines an event type
,NEW_EVENT //!< Tells an event occured
,DEFINE_VARIABLE_TYPE //!< Defines a variable type
,SET_VARIABLE //!< Sets a variable
};
public:
/**
* @brief Builds a PajeTracer.
* @param filename
* @param logLaunchings If set to true, job launching time will be written in the trace. This option leads to larger trace files.
* @brief Builds a PajeTracer
* @param[in] logLaunchings If set to true, job launching time will be written in the trace. This option leads to larger trace files
*/
PajeTracer(bool _logLaunchings = false);
PajeTracer(bool logLaunchings = false);
/**
* @brief Sets the filename of a PajeTracer
* @param[in] filename The name of the output file
*/
void setFilename(const std::string & filename);
/**
......@@ -93,81 +126,64 @@ public:
/**
* @brief Initializes a PajeTracer.
* @details This function must be called once before adding job launchings, runnings or endings.
* @param context The Batsim context
* @param machines The machines
* @param[in] context The BatsimContext
* @param[in] time The beginning time
*/
void initialize(BatsimContext * context, double time);
void initialize(const BatsimContext * context, double time);
/**
* @brief Finalizes a PajeTracer.
* @details This function must be called before the PajeTracer's object destruction.
* @param context The Batsim context
* @param time The simulation time at which the finalization is done
* @param[in] context The BatsimContext
* @param[in] time The simulation time at which the finalization is done
*/
void finalize(BatsimContext * context, double time);
void finalize(const BatsimContext * context, double time);
/**
* @brief Adds a job launch in the file trace.
* @details Please note that this method can only be called when the PajeTracer object has been initialized and had not been finalized yet.
* @param jobID The job unique number
* @param usedMachineIDs The machines which compute the job
* @param time The simulation time at which the addition is done
* @param[in] jobID The job unique number
* @param[in] usedMachineIDs The machines which compute the job
* @param[in] time The simulation time at which the addition is done
*/
void addJobLaunching(int jobID, const std::vector<int> & usedMachineIDs, double time);
/**
* @brief Created a job in the Pajé output file
* @param jobID The job unique number
* @brief Creates a job in the Pajé output file
* @param[in] jobID The job unique number
*/
void register_new_job(int jobID);
/**
* @brief Sets a machine in the idle state
* @param machineID The unique machine number
* @param time The time at which the machine should be marked as idle
* @param[in] machineID The unique machine number
* @param[in] time The time at which the machine should be marked as idle
*/
void set_machine_idle(int machineID, double time);
/**
* @brief Sets a machine in the computing state
* @param machineID The unique machine number
* @param jobID The unique job number that the machine computes
* @param time The time at which the machine should be marked as computing the job
* @param[in] machineID The unique machine number
* @param[in] jobID The unique job number that the machine computes
* @param[in] time The time at which the machine should be marked as computing the job
*/
void set_machine_as_computing_job(int machineID, int jobID, double time);
/**
* @brief Adds a job run in the file trace.
* @details Please note that this method can only be called when the PajeTracer object has been initialized and had not been finalized yet.
* @param jobID The job unique number
* @param time The simulation time at which the addition is done
*/
void addJobRunning(int jobID, const std::vector<int> & usedMachineIDs, double time);
/**
* @brief Adds a job end in the file trace.
* @details Please note that this method can only be called when the PajeTracer object has been initialized and had not been finalized yet.
* @param jobID The job unique number
* @param usedMachineIDs The machines which compute the job
* @param time The simulation time at which the kill is done
*/
void addJobEnding(int jobID, const std::vector<int> & usedMachineIDs, double time);
/**
* @brief Adds a job kill in the file trace.
* @details Please note that this method can only be called when the PajeTracer object has been initialized and had not been finalized yet.
* @param jobID The job unique number
* @param usedMachineIDs The machines which compute the job
* @param time The simulation time at which the kill is done
* @param associateKillToMachines By default (false), one event is added in the killer container. If set to true, one event is added for every machine on which the kill occurs.
* @param[in] jobID The job unique number
* @param[in] usedMachineIDs The machines which compute the job
* @param[in] time The simulation time at which the kill is done
* @param[in] associateKillToMachines By default (false), one event is added in the killer container. If set to true, one event is added for every machine on which the kill occurs.
*/
void addJobKill(int jobID, const MachineRange & usedMachineIDs, double time, bool associateKillToMachines = false);
/**
* @brief Adds a global utilization value of the system.
* @details Please note that this method can only be called when the PajeTracer object has been initialized and had not been finalized yet.
* @param utilization The global utilization of the system.
* @param time The simulation time at which the system has this utilization value
* @param[in] utilization The global utilization of the system.
* @param[in] time The simulation time at which the system has this utilization value
*/
void addGlobalUtilization(double utilization, double time);
......@@ -188,7 +204,7 @@ private:
/**
* @brief Generate colors
* @details The colors are fairly shared in the Hue color spectrum.
* @param colorCount colorCount
* @param[in] colorCount colorCount
*/
void generateColors(int colorCount = 8);
......@@ -228,26 +244,7 @@ private:
std::map<int, std::string> _jobs;
std::vector<std::string> _colors;
enum
{
UNINITIALIZED,
INITIALIZED,
FINALIZED
} state = UNINITIALIZED;
enum
{
DEFINE_CONTAINER_TYPE = 1,
CREATE_CONTAINER,
DESTROY_CONTAINER,
DEFINE_STATE_TYPE,
DEFINE_ENTITY_VALUE,
SET_STATE,
DEFINE_EVENT_TYPE,
NEW_EVENT,
DEFINE_VARIABLE_TYPE,
SET_VARIABLE,
};
PajeTracerState state = UNINITIALIZED;
};
......
......@@ -83,7 +83,7 @@ struct SchedulingAllocationMessage
struct PStateModificationMessage
{
MachineRange machine_ids; //! The IDs of the machines on which the pstate should be changed
int new_pstate; //! The pstate the machines should be put into
int new_pstate; //! The power state into which the machines should be put
};
/**
......@@ -185,18 +185,16 @@ struct WaiterProcessArguments
/**
* @brief Sends a message from the given process to the given mailbox
* @param[in] dst The destination mailbox
* @param[in] destination_mailbox The destination mailbox
* @param[in] type The type of message to send
* @param[in] job_id The job the message is about
* @param[in] data The data associated to the message
*/
void send_message(const std::string & destination_mailbox, IPMessageType type, void * data = nullptr);
/**
* @brief Sends a message from the given process to the given mailbox
* @param[in] dst The destination mailbox
* @param[in] destination_mailbox The destination mailbox
* @param[in] type The type of message to send
* @param[in] job_id The job the message is about
* @param[in] data The data associated to the message
*/
void send_message(const char * destination_mailbox, IPMessageType type, void * data = nullptr);
......
......@@ -168,7 +168,7 @@ public:
/**
* @brief Computes and returns the total consumed energy of all the computing machines
* @param[in] The Batsim context
* @param[in] context The Batsim context
* @return The total consumed energy of all the computing machines
*/
long double total_consumed_energy(const BatsimContext * context) const;
......
/**
* @file network.cpp
* @brief Contains network-related classes and functions
*/
#include "network.hpp"
#include <sys/socket.h>
......@@ -21,28 +26,16 @@ using namespace std;
UnixDomainSocket::UnixDomainSocket()
{
_server_socket = -1;
_client_socket = -1;
}
UnixDomainSocket::UnixDomainSocket(const string & filename) : UnixDomainSocket()
UnixDomainSocket::UnixDomainSocket(const std::string & filename) : UnixDomainSocket()
{
create_socket(filename);
}
UnixDomainSocket::~UnixDomainSocket()
{
if (_client_socket != -1)
{
::close(_client_socket);
_client_socket = -1;
}
if (_server_socket != -1)
{
::close(_server_socket);
_server_socket = -1;
}
close();
}
void UnixDomainSocket::create_socket(const string & filename)
......@@ -74,8 +67,25 @@ void UnixDomainSocket::accept_pending_connection()
XBT_INFO("Connected!");
}
void UnixDomainSocket::close()
{
if (_client_socket != -1)
{
::close(_client_socket);
_client_socket = -1;
}
if (_server_socket != -1)
{
::close(_server_socket);
_server_socket = -1;
}
}
string UnixDomainSocket::receive()
{
xbt_assert(_client_socket != -1, "Bad UnixDomainSocket::receive call: the client socket does not exist");
string msg;
uint32_t message_size;
uint32_t nb_bytes_read = 0;
......@@ -123,6 +133,8 @@ string UnixDomainSocket::receive()
void UnixDomainSocket::send(const string & message)
{
xbt_assert(_client_socket != -1, "Bad UnixDomainSocket::send call: the client socket does not exist");
uint32_t message_size = message.size();
XBT_INFO("Sending '%s'", message.c_str());
write(_client_socket, &message_size, 4);
......
/**
* @file network.hpp
* @brief Contains network-related classes and functions
*/
#pragma once
#include <string>
struct BatsimContext;
/**
* @brief Contains the different network stamps used in the network protocol
*/
enum NetworkStamp : char
{
STATIC_JOB_ALLOCATION = 'J',
JOB_REJECTION = 'R',
NOP = 'N',
STATIC_JOB_SUBMISSION = 'S',
STATIC_JOB_COMPLETION = 'C',
PSTATE_SET = 'P',
NOP_ME_LATER = 'n',
TELL_ME_CONSUMED_ENERGY = 'E',
PSTATE_HAS_BEEN_SET = 'p',
CONSUMED_ENERGY = 'e'
STATIC_JOB_ALLOCATION = 'J' //!< Decision -> Batsim. Allows the Decision real process to take a scheduling decision: To decide where a job should be executed now
,JOB_REJECTION = 'R' //!< Decision -> Batsim. Allows the Decision real process to reject a job (the job will not be computed)
,NOP = 'N' //!< Decision <-> Batsim. Does nothing. Since the network protocol is synchronous, the simulation would be stopped if a network component (Batsim or the Decision real process) stopped sending messages. That's what this stamp is used for.
,STATIC_JOB_SUBMISSION = 'S' //!< Batsim -> Decision. Batsim tells the Decision real process that a static job (one in the initial workload) has been submitted
,STATIC_JOB_COMPLETION = 'C' //!< Batsim -> Decision. Batsim tells the Decision real process that a static job (one in the initial workload) has been completed (finished its execution)
,PSTATE_SET = 'P' //!< Decision -> Batsim. The Decision real process wants to change the power state of one or several machines
,NOP_ME_LATER = 'n' //!< Decision -> Batsim. The Decision real process wants to be awaken at a future simulation time
,TELL_ME_CONSUMED_ENERGY = 'E' //!< Decision -> Batsim. The Decision real process wants to know how much energy has been consumed on computing machines since the beginning of the simulation
,PSTATE_HAS_BEEN_SET = 'p' //!< Batsim -> Decision. Batsim acknowledges that the power state of one of several machines has been changed
,CONSUMED_ENERGY = 'e' //!< Batsim -> Decision. Batsim tells the Decision process how much energy has been used since the beginning of the simulation
};
/**
* @brief Handles the socket used in the network protocol
*/
class UnixDomainSocket
{
public:
/**
* @brief Creates a UnixDomainSocket, whose internal sockets do not exist
*/
UnixDomainSocket();
/**
* @brief Creates a UnixDomainSocket, whose internal server socket is created via create_socket
* @param[in] filename The name of the file that is used as the Unix Domain Socket
*/
UnixDomainSocket(const std::string & filename);
/**
* @brief Destroys a UnixDomainSocket, closing open sockets
*/
~UnixDomainSocket();
/**
* @brief Creates the server socket
* @brief This method unlinks the file, creates a socket, binds it and starts listening on it
* @param[in] filename The name of the file that is used as the Unix Domain Socket
*/
void create_socket(const std::string & filename);
/**
* @brief Accept one pending connection (wait for it if none has been done yet)
*/
void accept_pending_connection();
/**
* @brief Closes the internal sockets
*/
void close();
/**
* @brief Waits for a message on the client socket (from the Decision real process) then returns it
* @return The message received on the client socket
*/
std::string receive();
/**
* @brief Sends a message on the client socket (to the Decision real process)
* @param[in] message The message to send
*/
void send(const std::string & message);
private:
int _server_socket;
int _client_socket;
int _server_socket = -1; //! The server-side socket
int _client_socket = -1; //! The client-side socket
};
/**
* @brief The process in charge of doing a Request-Reply iteration with the Decision real process
* @details This process sends a message to the Decision real process (Request) then waits for the answered message (Reply)
* @param[in] argc The number of arguments
* @param[in] argv The arguments' values
* @return 0
*/
int request_reply_scheduler_process(int argc, char *argv[]);
/**
* @file profiles.cpp
* Contains profile-related structures and classes
*/
#include "profiles.hpp"
#include <fstream>
......
/**
* @file profiles.hpp
* Contains profile-related structures and classes
*/
#pragma once
#include <string>
......@@ -6,25 +11,41 @@
#include <rapidjson/document.h>
/**
* @brief Enumerates the different types of profiles
*/
enum class ProfileType
{
DELAY,
MSG_PARALLEL,
MSG_PARALLEL_HOMOGENEOUS,
SMPI,
SEQUENCE
DELAY //!< The profile is a delay. Its data is of type DelayProfileData
,MSG_PARALLEL //!< The profile is composed of a computation vector and a communication matrix. Its data is of type MsgParallelProfileData
,MSG_PARALLEL_HOMOGENEOUS //!< The profile is a homogeneous MSG one. Its data is of type MsgParallelHomogeneousProfileData
,SMPI //!< The profile is a SimGrid MPI time-independent trace. Its data is of type SmpiProfileData
,SEQUENCE //!< The profile is non-atomic: it is composed of a sequence of other profiles
};
/**
* @brief Used to store profile information
*/
struct Profile
{
/**
* @brief Destroys a Profile, deleting its data from memory according to the profile type
*/
~Profile();
ProfileType type;
void * data;
ProfileType type; //! The type of the profile
void * data; //! The associated data
};
/**
* @brief The data associated to MSG_PARALLEL profiles
*/
struct MsgParallelProfileData
{
/**
* @brief Destroys a MsgParallelProfileData
* @details This method cleans the cpu and comm arrays from the memory if they are not set to nullptr
*/
~MsgParallelProfileData();
int nb_res; //! The number of resources
......@@ -32,43 +53,91 @@ struct MsgParallelProfileData
double * com = nullptr; //! The communication matrix
};
/**
* @brief The data associated to MSG_PARALLEL_HOMOGENEOUS profiles
*/
struct MsgParallelHomogeneousProfileData
{
double cpu; //! The computation amount on each node
double com; //! The communication amount between each pair of nodes
};
/**
* @brief The data associated to DELAY profiles
*/
struct DelayProfileData
{
double delay; //! The time amount, in seconds, that the job is supposed to take
};
/**
* @brief The data associated to SMPI profiles
*/
struct SmpiProfileData
{
std::vector<std::string> trace_filenames; //! all defined tracefiles
};
//! The structure used to store additional information about profiles of type composed
/**
* @brief The data associated to SEQUENCE profiles
*/
struct SequenceProfileData
{
int repeat; //! The number of times the sequence must be repeated
std::vector<std::string> sequence; //! The sequence of profile names
std::vector<std::string> sequence; //! The sequence of profile names, executed in this order
};
/**
* @brief Used to handles all the profiles of one workload
*/
class Profiles
{
public:
/**
* @brief Creates an empty Profiles
*/
Profiles();
/**
* @brief Destroys a Profiles
* @details All Profile elements are removed from memory
*/
~Profiles();
/**
* @brief Loads the profiles from a workload (a JSON document)
* @param[in] doc The JSON document
* @param[in] filename The name of the file from which the JSON document has been created (debug purpose)
*/
void load_from_json(const rapidjson::Document & doc, const std::string & filename);
/**
* @brief Accesses one profile thanks to its name
* @param[in] profile_name The name of the profile
* @return The profile whose name is profile_name
* @pre Such a profile exists
*/
Profile * operator[](const std::string & profile_name);
/**
* @brief Accesses one profile thanks to its name (const version)
* @param[in] profile_name The name of the profile
* @return The profile whose name is profile_name
* @pre Such a profile exists
*/