Commit 854d759e authored by Millian Poquet's avatar Millian Poquet

Export : C->C++ (to be continued)

parent 6541594e
This diff is collapsed.
#pragma once
#include <stdio.h>
#include <sys/types.h> /* ssize_t, needed by xbt/str.h, included by msg/msg.h */
#include <simgrid/msg.h>
/**
* @brief Handles bufferized writings into a single file
* @details Instead of applying writings directly to the file, a memory buffer is used. When the buffer is full, it is flushed to the disk.
*/
typedef struct
{
FILE * f; //! The file stream
int bufferSize; //! The size of the buffer (octets)
char * buffer; //! The buffer
int bufferPos; //! The number of octets currently in the buffer
} WriteBuffer;
/**
* @brief Creates a WriteBuffer
* @param[in] filename The file name
* @param[in] bufferSize The strictly positive buffer size
*
* @return The newly created WriteBuffer
*/
WriteBuffer * writeBuffer_create(const char * filename, int bufferSize);
/**
* @brief Destroys a WriteBufferex
* @param[in, out] wbuf The WriteBuffer
*/
void writeBuffer_destroy(WriteBuffer ** wbuf);
/**
* @brief Appends a text at the end of the buffer. If the buffer is full, it is automatically flushed into the disk.
* @param wbuf The WriteBuffer
* @param text The text to push in the buffer
*/
void writeBuffer_append(WriteBuffer * wbuf, const char * text);
/**
* @brief Flushes the current content of the buffer into the disk.
* @param wbuf The WriteBuffer
*/
void writeBuffer_flush(WriteBuffer * wbuf);
/**
* @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.
*/
void exportJobsToCSV(const char * filename);
/**
* @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
*/
void exportScheduleToCSV(const char * filename, double scheduling_time);
/**
* @brief The states of a PajeTracer
*/
typedef enum
{
PAJE_STATE_UNINITIALIZED //!< The PajeTracer has not been initialized yet
,PAJE_STATE_INITIALIZED //!< The PajeTracer has been initialized
,PAJE_STATE_FINALIZED //!< The PajeTracer has been finalized
} PajeTracerState;
/**
* @brief Allows to handle a Pajé trace corresponding to a schedule
*/
typedef struct
{
PajeTracerState state; //! The current state of the PajeTracer
int logLaunchings; //! If set to TRUE, job launchings will appear in the Pajé file
WriteBuffer * buf; //! Handles the writings to the file
int colorCount; //! The number of different colors used for the jobs
char ** colors; //! The different colors used for the jobs (as C strings)
} PajeTracer;
/**
* @brief Creates a PajeTracer object
* @param[in] The name of the output file in which the Pajé trace is stored
* @param[in] If set to true, job launching time will be written in the trace. This option leads to larger trace files.
* @param[in] colorCount The number of different colors to use for jobs
* @return The newly created PajeTracer object
*/
PajeTracer * pajeTracer_create(const char * filename, int logLaunchings, int colorCount);
/**
* @brief Destroys a PajeTracer object
* @param[in,out] tracer The PajeTracer object
*/
void pajeTracer_destroy(PajeTracer ** tracer);
/**
* @brief Initializes a PajeTracer object.
* @details This function must be called once before adding job launchings, runnings or endings.
* @param[in,out] tracer The PajeTracer object
* @param[in] date The current simulation date
* @param[in] machineCount The number of machines
* @param[in] machines The machines
*/
void pajeTracer_initialize(PajeTracer * tracer, double date, int machineCount, const msg_host_t * machines);
/**
* @brief Finalizes a PajeTracer object.
* @details This function must be called before the object destruction.
* @param[in,out] tracer The PajeTracer object
* @param[in] date The current simulation date
* @param[in] machineCount The number of machines
* @param[in] machines The machines
*/
void pajeTracer_finalize(PajeTracer * tracer, double date, int machineCount, const msg_host_t * machines);
/**
* @brief Adds a job launching in the Pajé 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[in,out] tracer The PajeTracer object
* @param[in] date The current simulation date
* @param[in] jobID The job number
* @param[in] usedMachinesCount The number of used machines to run the job
* @param[in] usedMachineIDs The numbers of the machines used to run the job
*/
void pajeTracer_addJobLaunching(PajeTracer * tracer, double date, int jobID, int usedMachinesCount, const int * usedMachineIDs);
/**
* @brief Adds a job running in the Pajé trace.
* @details Please note that this method can only be called when the PajeTracer object has been initialized and had not been finalized yet. Furthermore, the corresponding job launching must had been added previously.
* @param[in,out] tracer The PajeTracer object
* @param[in] date The current simulation date
* @param[in] jobID The job number
* @param[in] usedMachinesCount The number of used machines to run the job
* @param[in] usedMachineIDs The numbers of the machines used to run the job
*/
void pajeTracer_addJobRunning(PajeTracer * tracer, double date, int jobID, int usedMachinesCount, const int * usedMachineIDs);
/**
* @brief Adds a job ending in the Pajé trace.
* @details Please note that this method can only be called when the PajeTracer object has been initialized and had not been finalized yet. Furthermore, the corresponding job launching and running must had been added previously.
* @param[in,out] tracer The PajeTracer object
* @param[in] date The current simulation date
* @param[in] jobID The job number
* @param[in] usedMachinesCount The number of used machines to run the job
* @param[in] usedMachineIDs The numbers of the machines used to run the job
*/
void pajeTracer_addJobEnding(PajeTracer * tracer, double date, int jobID, int usedMachinesCount, const int * usedMachineIDs);
/**
* @brief Adds a job kill in the Pajé trace.
* @details Please note that this method can only be called when the PajeTracer object has been initialized and had not been finalized yet. Furthermore, the corresponding job launching must had been added previously.
* @param[in,out] tracer The PajeTracer object
* @param[in] date The current simulation date
* @param[in] jobID The job number
* @param[in] usedMachinesCount The number of used machines to run the job
* @param[in] usedMachineIDs The numbers of the machines used to run the job
*/
void pajeTracer_addJobKill(PajeTracer * tracer, double date, int jobID, int usedMachinesCount, const int * usedMachineIDs);
/**
* @brief Adds the system global utilization in the Pajé 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[in,out] tracer The PajeTracer object
* @param[in] date The current simulation date
* @param[in] utilization The system global utilization.
*/
void pajeTracer_addGlobalUtilization(PajeTracer * tracer, double date, double utilization);
/**
* @brief Generate colors
* @details The colors are fairly shared in the Hue color spectrum.
* @param[in,out] tracer The PajeTracer
* @param[in] colorCount colorCount The number of colors to generate
*/
void pajeTracer_private_generateColors(PajeTracer * tracer, int colorCount);
/**
* @brief Randomize the position of the colors in the colormap
* @param[in,out] tracer The PajeTracer
*/
void pajeTracer_private_shuffleColors(PajeTracer * tracer);
/**
* @brief Give the RGB representation of a color represented in HSV
* @details This function is greatly inspired by http://www.cs.rit.edu/~ncs/color/t_convert.html
* @param[in] h The hue, whose value is in [0,360]
* @param[in] s The saturation, whose value is in [0,1]
* @param[in] v The value, whose value is in [0,1]
* @param[out] r The red, whose value is in [0,1]
* @param[out] g The green, whose value is in [0,1]
* @param[out] b The blue, whose value is in [0,1]
*/
void hsvToRgb(double h, double s, double v, double * r, double * g, double * b);
#pragma once
#include <stdio.h>
#include <sys/types.h> /* ssize_t, needed by xbt/str.h, included by msg/msg.h */
#include <vector>
#include <string>
#include <fstream>
#include <simgrid/msg.h>
#include "machines.hpp"
class WriteBuffer
{
public:
/**
* @brief Builds a WriteBuffer
* @param filename The file that will be written
* @param bufferSize The size of the buffer (in bytes).
*/
WriteBuffer(const std::string & filename, int bufferSize = 64*1024);
/**
* @brief Destructor
* @details This method flushes the buffer if it is not empty, destroys the buffer and closes the file.
*/
~WriteBuffer();
/**
* @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
*/
void appendText(const char * text);
/**
* @brief Write the current content of the buffer into the file
*/
void flushBuffer();
private:
std::ofstream f; //! The file stream on which the buffer is outputted
const int bufferSize; //! The buffer maximum size
char * buffer = nullptr;//! The buffer
int bufferPos = 0; //! The current position of the buffer (previous positions are already written)
};
/**
* @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.
*/
void exportJobsToCSV(const char * filename);
/**
* @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
*/
void exportScheduleToCSV(const char * filename, double scheduling_time);
/**
* @brief Allows to handle a Pajé trace corresponding to a schedule
*/
class PajeTracer
{
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.
*/
PajeTracer(const std::string & filename, bool logLaunchings = false);
/**
* @brief PajeTracer destructor.
*/
~PajeTracer();
/**
* @brief Initializes a PajeTracer.
* @details This function must be called once before adding job launchings, runnings or endings.
* @param machines The machines
*/
void initialize(const std::vector<Machine> & machines, double time);
/**
* @brief Finalizes a PajeTracer.
* @details This function must be called before the PajeTracer's object destruction.
* @param machines The machines
* @param time The simulation time at which the finalization is done
*/
void finalize(const std::vector<Machine> & machines, 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 job The job
* TODO UPDATE
* @param time The simulation time at which the addition is done
*/
void addJobLaunching(int jobID, const std::vector<int> & usedMachineIDs, 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 job The job
* TODO UPDATE
* @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 job The job
* TODO UPDATE
* @param time The simulation time at which the addition 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 job The job that have been killed
* TODO UPDATE
* @param time The simulation time at which the kill is done
*/
void addJobKill(int jobID, const std::vector<int> & usedMachineIDs, double time);
/**
* @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
*/
void addGlobalUtilization(double utilization, double time);
public:
/**
* @brief Give the RGB representation of a color represented in HSV
* @details This function is greatly inspired by http://www.cs.rit.edu/~ncs/color/t_convert.html
* @param[in] h The hue, whose value is in [0,360]
* @param[in] s The saturation, whose value is in [0,1]
* @param[in] v The value, whose value is in [0,1]
* @param[out] r The red, whose value is in [0,1]
* @param[out] g The green, whose value is in [0,1]
* @param[out] b The blue, whose value is in [0,1]
*/
static void hsvToRgb(double h, double s, double v, double & r, double & g, double & b);
private:
/**
* @brief Generate colors
* @details The colors are fairly shared in the Hue color spectrum.
* @param colorCount colorCount
*/
void generateColors(int colorCount = 8);
/**
* @brief Randomize the position of the colors in the colormap
*/
void shuffleColors();
private:
const char * rootType = "root_ct";
const char * machineType = "machine_ct";
const char * machineState = "machine_state";
const char * schedulerType = "scheduler_ct";
const char * killerType = "killer_ct";
const char * killEventKiller = "kk";
const char * killEventMachine = "km";
const char * utilizationVarType = "vu_vt";
const char * mstateWaiting = "w";
const char * mstateLaunching = "l";
const char * varGlobalUtilization = "vgu";
const char * root = "root";
const char * scheduler = "sc";
const char * killer = "k";
const char * machinePrefix = "m";
const char * jobPrefix = "j";
const char * waitingColor= "\"0.0 0.0 0.0\"";
const char * launchingColor = "\"0.3 0.3 0.3\"";
const char * utilizationColor = "\"0.0 0.5 0.0\"";
const bool logLaunchings;
WriteBuffer * wbuf = nullptr;
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,
};
};
......@@ -29,6 +29,7 @@ void Machines::createMachines(xbt_dynar_t hosts)
Machine & machine = _machines[i];
machine.id = i;
machine.name = MSG_host_get_name(host);
machine.host = host;
machine.jobs_being_computed = {};
machine.state = machine_state::IDLE;
......@@ -94,8 +95,3 @@ ostream & operator<<(ostream & out, const Machine & machine)
return out;
}
int main()
{
return 0;
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <simgrid/msg.h>
......@@ -19,6 +20,7 @@ namespace machine_state
struct Machine
{
int id;
std::string name;
msg_host_t host;
machine_state::MachineState state;
std::set<int> jobs_being_computed;
......
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