add log parser
This commit is contained in:
parent
711808eafb
commit
d4667506dd
3 changed files with 106 additions and 4 deletions
50
include/actsim_agent/log_parser.hpp
Normal file
50
include/actsim_agent/log_parser.hpp
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
*
|
||||||
|
* This file is part of the ACT library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 Fabian Posch
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LOG_PARSER__
|
||||||
|
#define __LOG_PARSER__
|
||||||
|
|
||||||
|
#include <cluster/artifact.hpp>
|
||||||
|
#include "agent_artifact.hpp"
|
||||||
|
|
||||||
|
class LogParser {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
LogParser(std::unique_ptr<DBSimOutputArtifact>& artifact, std::shared_ptr<pl::SimOutputArtifact> reference);
|
||||||
|
LogParser(std::unique_ptr<DBSimOutputArtifact>& artifact);
|
||||||
|
|
||||||
|
void parse_log(const std::string& line);
|
||||||
|
void parse_error(const std::string& line);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::unique_ptr<DBSimOutputArtifact>& artifact;
|
||||||
|
|
||||||
|
std::shared_ptr<pl::SimOutputArtifact> reference;
|
||||||
|
bool has_reference;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
43
src/actsim_agent/log_parser.cpp
Normal file
43
src/actsim_agent/log_parser.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
*
|
||||||
|
* This file is part of the ACT library
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 Fabian Posch
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "log_parser.hpp"
|
||||||
|
|
||||||
|
LogParser::LogParser(std::unique_ptr<DBSimOutputArtifact>& artifact, std::shared_ptr<pl::SimOutputArtifact> reference) : artifact(artifact) {
|
||||||
|
this->reference = reference;
|
||||||
|
this->has_reference = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogParser::LogParser(std::unique_ptr<DBSimOutputArtifact>& artifact) : artifact(artifact) {
|
||||||
|
this->has_reference = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
void LogParser::parse_log(const std::string& line) {
|
||||||
|
this->artifact->add_log_output(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogParser::parse_error(const std::string& line) {
|
||||||
|
this->artifact->add_err_output(line);
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "log_parser.hpp"
|
||||||
#include "worker.hpp"
|
#include "worker.hpp"
|
||||||
|
|
||||||
Worker::Worker(TaskInterface& interface) : interface(interface) {}
|
Worker::Worker(TaskInterface& interface) : interface(interface) {}
|
||||||
|
|
@ -328,6 +329,14 @@ std::unique_ptr<OutputType> Worker::perform_task(std::unique_ptr<InputType>& tas
|
||||||
task->source_config
|
task->source_config
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// create the output parser
|
||||||
|
std::unique_ptr<LogParser> parser;
|
||||||
|
if (task->reference == 0) {
|
||||||
|
parser = std::make_unique<LogParser>(result);
|
||||||
|
} else {
|
||||||
|
parser = std::make_unique<LogParser>(result, this->interface.get_reference(task->reference));
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string>& commands = task->get_content()[0].commands;
|
std::vector<std::string>& commands = task->get_content()[0].commands;
|
||||||
size_t command_n = 0;
|
size_t command_n = 0;
|
||||||
size_t last_pos = 0;
|
size_t last_pos = 0;
|
||||||
|
|
@ -389,7 +398,7 @@ std::unique_ptr<OutputType> Worker::perform_task(std::unique_ptr<InputType>& tas
|
||||||
|
|
||||||
// make sure any remaining output is added to the log
|
// make sure any remaining output is added to the log
|
||||||
if (stdout_buf != "") {
|
if (stdout_buf != "") {
|
||||||
result->add_log_output(stdout_buf);
|
parser->parse_log(stdout_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINT("STDOUT was closed by child");
|
DEBUG_PRINT("STDOUT was closed by child");
|
||||||
|
|
@ -404,7 +413,7 @@ std::unique_ptr<OutputType> Worker::perform_task(std::unique_ptr<InputType>& tas
|
||||||
auto pos = stdout_buf.find('\n');
|
auto pos = stdout_buf.find('\n');
|
||||||
while (pos != std::string::npos) {
|
while (pos != std::string::npos) {
|
||||||
DEBUG_PRINT("Log output line was added");
|
DEBUG_PRINT("Log output line was added");
|
||||||
result->add_log_output(stdout_buf.substr(0, pos));
|
parser->parse_log(stdout_buf.substr(0, pos));
|
||||||
|
|
||||||
if ((pos + 1) < stdout_buf.length()) {
|
if ((pos + 1) < stdout_buf.length()) {
|
||||||
stdout_buf = stdout_buf.substr(pos+1, stdout_buf.length());
|
stdout_buf = stdout_buf.substr(pos+1, stdout_buf.length());
|
||||||
|
|
@ -439,7 +448,7 @@ std::unique_ptr<OutputType> Worker::perform_task(std::unique_ptr<InputType>& tas
|
||||||
|
|
||||||
// make sure any remaining output is added to the log
|
// make sure any remaining output is added to the log
|
||||||
if (stderr_buf != "") {
|
if (stderr_buf != "") {
|
||||||
result->add_err_output(stderr_buf);
|
parser->parse_error(stderr_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINT("STDERR was closed by child");
|
DEBUG_PRINT("STDERR was closed by child");
|
||||||
|
|
@ -454,7 +463,7 @@ std::unique_ptr<OutputType> Worker::perform_task(std::unique_ptr<InputType>& tas
|
||||||
auto pos = stderr_buf.find('\n');
|
auto pos = stderr_buf.find('\n');
|
||||||
while (pos != std::string::npos) {
|
while (pos != std::string::npos) {
|
||||||
DEBUG_PRINT("Error output line was added");
|
DEBUG_PRINT("Error output line was added");
|
||||||
result->add_err_output(stderr_buf.substr(0, pos));
|
parser->parse_error(stderr_buf.substr(0, pos));
|
||||||
|
|
||||||
if ((pos + 1) < stderr_buf.length()) {
|
if ((pos + 1) < stderr_buf.length()) {
|
||||||
stderr_buf = stderr_buf.substr(pos+1, stderr_buf.length());
|
stderr_buf = stderr_buf.substr(pos+1, stderr_buf.length());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue