Commit c78e8e4a authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

Deleting message directory because empty after moving message* and

errors* .
Improvement of the file loading in parser and trace structures.
parent 2026cfee
......@@ -69,8 +69,8 @@ double convert_to_double(const string arg){
// We had dots initially, we need to have the english system
if(is_english_system_needed) {
if((setlocale(LC_NUMERIC, "en_GB.UTF-8") == NULL) &&
(setlocale(LC_NUMERIC, "C") == NULL)){
if((setlocale(LC_NUMERIC, "C") == NULL) &&
(setlocale(LC_NUMERIC, "en_GB.UTF-8") == NULL)){
cerr << QObject::tr("The locale en_GB.UTF-8 is unavailable so the decimal pointed will not be printed").toStdString() << endl;
}
}
......
......@@ -61,16 +61,12 @@ Definition::Definition(){
_event_name.erase();
}
Definition::Definition(string& eventname){
Definition::Definition(const string& eventname){
_event_name = eventname;
}
void Definition::store(string name, string type){
Field e;
e._name = name;
e._type = type;
_fields.push_back(e);
void Definition::store(const string &name, const string &type){
_fields.push_back(Field(name, type));
}
void Definition::print() const{
......
......@@ -60,6 +60,8 @@ struct Field{
* \brief Contains the type of a definition element.
*/
std::string _type;
Field(const std::string &name, const std::string &type) : _name(name), _type(type){};
};
......@@ -97,19 +99,19 @@ public:
Definition();
/*!
* \fn Definition(std::string &eventname)
* \fn Definition(const std::string &eventname)
* \brief constructor
* \param eventname : the name of the new Definition
*/
Definition(std::string &eventname);
Definition(const std::string &eventname);
/*!
* \fn store(std::string name, std::string type)
* \fn store(const std::string &name, const std::string &type)
* \brief : add a field to definition
* \param name : the name of the event
* \param type : the type of the event
*/
void store(std::string name, std::string type);
void store(const std::string &name, const std::string &type);
/*!
* \fn print() const
......
......@@ -55,10 +55,7 @@
using namespace std;
File::File() {
_current_line = 0;
_filesize = 0.;
_filename = "";
File::File() : _filename(""), _current_line(0), _filesize(0.) {
}
void File::open(string filename) {
......@@ -71,7 +68,6 @@ void File::open(string filename) {
_file.seekg (0, ios::end);
_filesize = _file.tellg();
_file.seekg (0, ios::beg);
}
File::~File() {
......
......@@ -50,13 +50,10 @@
/* -- */
using namespace std;
Line::Line() {
_line_count = 0;
Line::Line() : _line_count(0) {
}
Line::Line(const Line &l) {
_tokens = l._tokens;
_line_count = l._line_count;
Line::Line(const Line &l) : _tokens(l._tokens), _line_count(l._line_count) {
}
Line::Line(string &string_line) {
......@@ -76,7 +73,9 @@ void Line::fill_line(const std::string &string_line) {
char char_read = '\0';
const int size_max = string_line.size();
for(int i = 0 ; char_read != '\n' ; i ++) {
int index_begin_string = 0;
for(int i = 0 ; char_read != '\n' ; ++ i) {
if(i > size_max) {
break;
......@@ -84,44 +83,54 @@ void Line::fill_line(const std::string &string_line) {
char_read = string_line[i];
if(char_read == '\n') {
// End of the line
if(char_read == '\n') { /* Don't forget the last token */
current_token = string_line.substr(index_begin_string, i-index_begin_string);
if(!current_token.empty()) {
_tokens.push_back(current_token);
current_token.clear(); // Reinitialisation
}
continue;
}
// '%' is a "special" token used to specify (Pajé format) that wa are in a definition line
if(char_read == '%') {
_tokens.push_back("%");
current_token = "\0"; // Reinitialisation
current_token.clear(); // Reinitialisation
index_begin_string = i+1;
continue;
}
// Composite token
if(char_read == '\'' || char_read == '"') {
int a = build_composite_token(string_line, i);
i += a;
current_token = "\0"; // Reinitialisation
int composite_token_size = build_composite_token(string_line, i);
i += composite_token_size;
current_token.clear(); // Reinitialisation
index_begin_string = i+1;
continue;
}
if((char_read == ' ' || char_read == '\t')) {
if((char_read == ' ') || (char_read == '\t')){
// We store the token
if(current_token != "\0") {
current_token = string_line.substr(index_begin_string, i-index_begin_string);
if(!current_token.empty()) {
_tokens.push_back(current_token);
current_token = "\0"; // Reinitialisation
current_token.clear(); // Reinitialisation
}
index_begin_string = i+1;
continue;
}
current_token += char_read;
}
if(current_token != "\0") {
if(!current_token.empty()) {
_tokens.push_back(current_token);
current_token = "\0"; // Reinitialisation
current_token.clear(); // Reinitialisation
}
}
bool Line::starts_with(const string &s) const {
if(!_tokens.empty())
return _tokens[0] == s;
else // tokens is empty
......@@ -160,27 +169,17 @@ unsigned int Line::get_line_count() const {
}
int Line::build_composite_token(string line, int index) {
string token;
int i = index+1;
char current_char = line[i];
int position = 0;
do {
current_char = line[i];
if(current_char == '\"' || current_char == '\'') {
continue;
}
// line[index] corresponds to the delimiter ie " or '
// We search the first one after this one
const unsigned int delimiter = line.find_first_of(line[index], index+1);
if(current_char == '\0') {
throw "overflow in buffer";
}
if(delimiter == string::npos) {
throw "overflow in buffer";
}
const string token = line.substr(index+1, delimiter-index-1);
token += current_char;
i ++;
position ++;
} while(current_char != '\"' && current_char != '\'' && current_char != '\n');
_tokens.push_back(token);
return i-index;
return delimiter-index;
}
......@@ -54,6 +54,9 @@
*/
class Parser{
protected:
bool _is_finished;
bool _is_canceled;
public:
/*!
......
......@@ -58,15 +58,14 @@ using namespace std;
const int ParserDefinitionPaje::_OUT_A_DEFINITION = 0;
const int ParserDefinitionPaje::_IN_A_DEFINITION = 1;
ParserDefinitionPaje::ParserDefinitionPaje(){
_state = _OUT_A_DEFINITION;
ParserDefinitionPaje::ParserDefinitionPaje() : _state(_OUT_A_DEFINITION) {
}
int ParserDefinitionPaje::definitions_number(){
int ParserDefinitionPaje::definitions_number() const {
return _definitions.size();
}
void ParserDefinitionPaje::enter_definition(Line &line){
void ParserDefinitionPaje::enter_definition(const Line &line){
if(_state == _IN_A_DEFINITION){
Error::set(Error::_EXPECT_END_DEF, line.get_line_count(), Error::_WARNING);
......@@ -105,7 +104,7 @@ void ParserDefinitionPaje::enter_definition(Line &line){
return;
}
void ParserDefinitionPaje::leave_definition(Line &line){
void ParserDefinitionPaje::leave_definition(const Line &line){
if(_state != _IN_A_DEFINITION){
Error::set(Error::_EXPECT_EVENT_DEF, line.get_line_count(), Error::_WARNING);
......@@ -120,7 +119,7 @@ void ParserDefinitionPaje::leave_definition(Line &line){
}
}
void ParserDefinitionPaje::add_field_to_definition(std::string& first_token,Line& line){
void ParserDefinitionPaje::add_field_to_definition(std::string& first_token, const Line& line){
if(_state == _OUT_A_DEFINITION){
Error::set(Error::_EXPECT_EVENT_DEF, line.get_line_count(), Error::_ERROR);
......@@ -147,7 +146,7 @@ void ParserDefinitionPaje::add_field_to_definition(std::string& first_token,Line
}
void ParserDefinitionPaje::store_definition(Line &line){
void ParserDefinitionPaje::store_definition(const Line &line){
string first_token;
if(!line.item(1, first_token)){
......@@ -177,14 +176,14 @@ Definition& ParserDefinitionPaje::get_definition(unsigned int i){
return _definitions[i];
}
map<unsigned int,Definition>* ParserDefinitionPaje::get_hash_table_of_definitions(){
const map<unsigned int,Definition>* ParserDefinitionPaje::get_hash_table_of_definitions() const{
return &_definitions;
}
void ParserDefinitionPaje::print_definitions(){
map<unsigned int,Definition>::iterator it;
void ParserDefinitionPaje::print_definitions() const {
map<unsigned int,Definition>::const_iterator it_end = _definitions.end();
for (it = _definitions.begin(); it != _definitions.end() ; ++ it){
for (map<unsigned int,Definition>::const_iterator it = _definitions.begin(); it != it_end ; ++ it){
cout << "# " << (*it).first << endl;
......
......@@ -81,13 +81,13 @@ public:
* \fn definitions_number
* \return : the number of definitions in the map
*/
int definitions_number();
int definitions_number() const;
/*!
* \fn store_definition(Line &)
* \param l the line to store.
*/
void store_definition(Line &l);
void store_definition(const Line &l);
/*!
* \fn get_definition(unsigned int i)
......@@ -100,31 +100,31 @@ public:
* \fn get_hash_table_of_definitions
* \return : the hash table of definitions
*/
std::map<unsigned int,Definition> *get_hash_table_of_definitions();
const std::map<unsigned int,Definition> *get_hash_table_of_definitions() const;
/*!
* \fn enter_definition(Line &line)
* \fn enter_definition(const Line &line)
* \param line line
*/
void enter_definition(Line &line);
void enter_definition(const Line &line);
/*!
* \fn leave_definition(Line&line)
* \fn leave_definition(const Line &line)
* \param line
*/
void leave_definition(Line &line);
void leave_definition(const Line &line);
/*!
* \fn add_field_to_definition(std::string& first_token, Line& line)
* \fn add_field_to_definition(std::string& first_token, const Line& line)
* \param first_token : the name of the file to parse
* \param line : the structure of data to fill
*/
void add_field_to_definition(std::string& first_token, Line& line);
void add_field_to_definition(std::string& first_token, const Line& line);
/*! \fn print_definitions
* \brief Print all the definitions. Useful for debug.
*/
void print_definitions();
void print_definitions() const;
};
......
......@@ -66,8 +66,7 @@ uint64_t ParserEventOTF::_cur_time = 0;
uint64_t ParserEventOTF::_min_time = 0;
uint64_t ParserEventOTF::_max_time = 0;
ParserEventOTF::ParserEventOTF() {
_handlers = OTF_HandlerArray_open();
ParserEventOTF::ParserEventOTF() : _handlers(OTF_HandlerArray_open()) {
}
ParserEventOTF::~ParserEventOTF() {
......
......@@ -91,8 +91,8 @@ void ParserEventPaje::store_event(const Definition &definition, Line &line, Trac
while(i < number_of_values+1) {
string current_value;
const string current_field_name = fields[i-1]._name;
const string current_field_type = fields[i-1]._type;
const string &current_field_name = fields[i-1]._name;
const string &current_field_type = fields[i-1]._type;
if (!line.item(i, current_value)) {
Error::set(Error::_LINE_TOO_SHORT_EVENT, line.get_line_count(), Error::_WARNING);
......
......@@ -74,17 +74,24 @@ void ParserOTF::parse(string filename, Trace &trace, bool finish_trace_after_par
ParserEventOTF *parserevent = new ParserEventOTF();
OTF_FileManager* manager = OTF_FileManager_open(100);
OTF_Reader* _reader = OTF_Reader_open(filename.c_str(), manager);
int ret = 0;
if(manager == NULL) {
cerr << QObject::tr("manager failed\n").toStdString() << endl;
delete parserdefinition;
delete parserevent;
return;
}
OTF_Reader* _reader = OTF_Reader_open(filename.c_str(), manager);
if(_reader == NULL) {
cerr << QObject::tr("open failed\n").toStdString() << endl;
delete parserdefinition;
delete parserevent;
OTF_FileManager_close(manager);
return;
}
parserdefinition->set_handlers(&trace);
parserdefinition->read_definitions(_reader);
parserdefinition->create_container_types(&trace);
......
......@@ -61,8 +61,6 @@ class ParserOTF : public Parser {
private:
std::string _file_to_parse;
OTF_Reader* _reader;
bool _is_finished;
bool _is_canceled;
public:
......
......@@ -64,13 +64,9 @@
/* -- */
using namespace std;
ParserPaje::ParserPaje() {
ParserPaje::ParserPaje() : parserdefinition(new ParserDefinitionPaje()), parserevent(new ParserEventPaje()) {
_is_finished = false;
_is_canceled = false;
parserdefinition = new ParserDefinitionPaje();
parserevent = new ParserEventPaje();
}
ParserPaje::~ParserPaje() {
......@@ -163,6 +159,6 @@ void ParserPaje::set_canceled() {
_is_canceled = true;
}
map<unsigned int, Definition> *ParserPaje::get_definitions() const {
const map<unsigned int, Definition> *ParserPaje::get_definitions() const {
return parserdefinition->get_hash_table_of_definitions();
}
......@@ -61,8 +61,6 @@ class Definition;
class ParserPaje : public Parser{
private:
std::string _file_to_parse;
bool _is_finished;
bool _is_canceled;
ParserDefinitionPaje *parserdefinition;
ParserEventPaje *parserevent;
......@@ -125,7 +123,7 @@ public:
* \fn get_definitions()
* \brief get the definitions from the parserdefinition
*/
std::map<unsigned int, Definition> *get_definitions() const;
const std::map<unsigned int, Definition> *get_definitions() const;
};
#endif // PARSERPAJE_HPP
......@@ -72,7 +72,7 @@
/* -- */
using namespace std;
ParserVite::ParserVite(){
ParserVite::ParserVite() {
_is_finished = false;
_is_canceled = false;
}
......@@ -112,31 +112,32 @@ void ParserVite::parse(string filename, Trace &trace, bool finish_trace_after_pa
for (std::list<Container *>::const_iterator it = root_containers->begin();
it != root_containers->end();
it ++) {
++ it) {
containers.push(*it);
}
while (!containers.empty()) {
Container *c = containers.top();
containers.pop();
extra_fields = c->get_extra_fields();
field = extra_fields->find(string("Filename"));
// Search the filename
if (field != extra_fields->end()) {
filename_String = (String *)(*field).second;
name = QString::fromStdString(filename_String->to_string());
}
else {
name = "";
}
if(name != "") {
file_event_names << name;
}
// We add the children
for (list<Container *>::const_iterator i = c->get_children()->begin();
i != c->get_children()->end();
i++) {
containers.push(*i);
}
Container *c = containers.top();
containers.pop();
extra_fields = c->get_extra_fields();
field = extra_fields->find(string("Filename"));
// Search the filename
if (field != extra_fields->end()) {
filename_String = (String *)(*field).second;
name = QString::fromStdString(filename_String->to_string());
}
else {
name = "";
}
if(name != "") {
file_event_names << name;
}
// We add the children
list<Container *>::const_iterator children_end = c->get_children()->end();
for (list<Container *>::const_iterator i = c->get_children()->begin();
i != children_end;
++ i) {
containers.push(*i);
}
}
QStringList::const_iterator it_end = file_event_names.constEnd();
......@@ -166,7 +167,7 @@ void ParserVite::parse(string filename, Trace &trace, bool finish_trace_after_pa
sscanf(event_identity_string.c_str(), "%u", &event_identity);
current_definition = definitions[event_identity];
// If it is a end link we wait for the begin (PajeStartLink) necessary?
// If it is a end link we wait for the begin (PajeStartLink)
if(current_definition.get_event_name() == "PajeEndLink") {
_end_link.push_back(event_line);
continue;
......@@ -213,6 +214,7 @@ void ParserVite::set_file_to_parse(const string filename){
float ParserVite::get_size_loaded() const{
// TODO when multithread :) else we cannot determine it except in computing the sum of all the file sizes and storing already loaded ^^
return 0.5;
}
......
......@@ -61,8 +61,6 @@ class ParserVite : public Parser{
private:
std::string _file_to_parse;
std::vector<Line> _end_link; // useful for multi-thread. We fill it in the threads and store them at the end of all the thread in the trace.
bool _is_finished;
bool _is_canceled;
public:
......
......@@ -101,14 +101,14 @@ void Command_window::on_execute_button_clicked(){
QString end_time = _ui_end_box->text();
QString filter = _ui_filter_box->text();
if(_ui_start_box->text()== "" ||
_ui_start_box->text()=="t0")
if(start_time == "" ||
start_time == "t0")
start_time = "0";
if(_ui_end_box->text() == "" ||
_ui_end_box->text()=="t1")
if(end_time == "" ||
end_time == "t1")
end_time = QString::fromStdString(_trace->get_max_date().to_string());
if(_ui_filter_box->text()== "" ||
_ui_filter_box->text()<0)
if(filter == "" ||
filter < 0)
filter = "0";
set_selected_nodes();
......
......@@ -59,7 +59,7 @@ using namespace std;
Container::Container(Name name, Date creation_time, ContainerType *type, Container *parent, map<std::string, Value *> &opt):
Container::Container(Name name, Date creation_time, ContainerType *type, Container *parent, map<string, Value *> &opt):
_name(name), _creation_time(creation_time), _destruction_time(0.0), _type(type), _parent(parent),
_n_states(0), _state_tree(0), _n_events(0), _event_tree(0), _n_variables(0), _extra_fields(opt) {
}
......@@ -120,7 +120,7 @@ void Container::add_current_state(Date end) {
_n_states++;
}
void Container::set_state(Date time, StateType *type, EntityValue *value, map<std::string, Value *> &opt) {
void Container::set_state(Date time, StateType *type, EntityValue *value, map<string, Value *> &opt) {
if (!_current_states.empty()) {
add_current_state(time);
_current_states.pop();
......@@ -130,7 +130,7 @@ void Container::set_state(Date time, StateType *type, EntityValue *value, map<st
_current_states.push(t);
}
void Container::push_state(Date time, StateType *type, EntityValue *value, map<std::string, Value *> &opt) {
void Container::push_state(Date time, StateType *type, EntityValue *value, map<string, Value *> &opt) {
if (!_current_states.empty())
add_current_state(time);
......@@ -149,22 +149,22 @@ void Container::pop_state(Date time) {
}
}
void Container::new_event(Date time, EventType *type, EntityValue *value, map<std::string, Value *> &opt) {
void Container::new_event(Date time, EventType *type, EntityValue *value, map<string, Value *> &opt) {
_events.push_back(new Event(time, type, this, value, opt));
_n_events++;
}
void Container::start_link(Date time, LinkType *type, Container *source, EntityValue *value, String key, map<std::string, Value *> &opt) {
void Container::start_link(Date time,