From ea7e79fc7988cb102449b775d8ffbdb323e63269 Mon Sep 17 00:00:00 2001 From: Timon Habenicht <t.habenicht@tu-bs.de> Date: Wed, 16 May 2018 13:09:32 +0200 Subject: [PATCH] adds stringoutput to LogFileWriter --- .../Utilities/LogFileWriter/LogFileWriter.cpp | 75 +++---------------- .../Utilities/LogFileWriter/LogFileWriter.h | 14 ++-- 2 files changed, 15 insertions(+), 74 deletions(-) diff --git a/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.cpp b/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.cpp index 5eeea9726..4fe9dfbca 100644 --- a/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.cpp +++ b/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.cpp @@ -1,72 +1,27 @@ #include "LogFileWriter.h" -#include <cuda_runtime.h> #include <helper_functions.h> -#include <helper_cuda.h> #include <iomanip> #include <ctime> -#include "Utilities\EvaluationParameter\EvaluationParameter.h" -#include "Utilities\TestInformation\TestInformation.h" -#include "Tests\DataQueue\DataQueue.h" - -LogFileWriter::LogFileWriter(std::vector<std::shared_ptr<EvaluationParameter>> evaPara, std::shared_ptr<TestInformation> testinfo) +LogFileWriter::LogFileWriter(std::string filePath) { std::ostringstream oss; - oss << evaPara.at(0)->getLogFilePath() << "\\logFile_" << calcDateAndTime() << ".txt"; + oss << filePath << "\\logFile_" << calcDateAndTime() << ".txt"; this->logFilePath = oss.str(); logFile.open(logFilePath, std::ios::out); - - makeCenterHead("LogFile Information"); - - logFile << "Date: "<< std::setw(2) << std::setfill('0') << nowLocal.tm_mday << "." << std::setw(2) << nowLocal.tm_mon + 1 << "." << nowLocal.tm_year + 1900 << std::endl; - logFile << "Time: " << std::setw(2) << std::setfill('0') << nowLocal.tm_hour << ":" << std::setw(2) << nowLocal.tm_min << ":" << std::setw(2) << nowLocal.tm_sec << std::endl; - logFile << std::endl; - - - int numberOfCudaDevices; - cudaGetDeviceCount(&numberOfCudaDevices); - for (int i = 0; i < numberOfCudaDevices; i++) { - cudaDeviceProp prop; - cudaGetDeviceProperties(&prop, i); - logFile <<"GPU Device " << i + 1 << ": " << prop.name << std::endl; - } - logFile << std::endl; - - logFile << testinfo->getInformation(); - - makeCenterHead("Test Time Information"); - logFile << "FileWriting: " << std::boolalpha << evaPara.at(0)->getWriteFiles() << std::endl; - logFile << std::endl; - logFile << "TestName \t \t \t" << " L\t\t" << "Time for Test" << std::endl; - logFile << std::endl; - for (int i = 0; i < evaPara.size(); i++) - logFile << std::left << std::setfill(' ') << std::setw(17) << evaPara.at(i)->getTestName() << "\t" << std::right << std::setw(3) << evaPara.at(i)->getLx() << "\t\t" << std::setw(9) << evaPara.at(i)->getTestTime() << " sec" << std::endl; - logFile << std::endl; } -void LogFileWriter::makeDataQueueOutput(DataQueue* data, int arraySize) +std::shared_ptr<LogFileWriter> LogFileWriter::getNewInstance(std::string filePath) { - if (data[0].expected) { - std::ostringstream oss; - oss << data->testName << " " << data->valueName << " Test"; - makeCenterHead(oss.str()); - - logFile << "L" << "\t" << std::setfill(' ') << std::left << std::setw(15) << data->valueName << "Order of Accuracy" << std::endl << std::endl; - - logFile << data[0].la << "\t" << data[0].a << std::endl; - for (int i = 0; i < arraySize; i++) { - if (data[i].expected) { - logFile << std::setfill(' ') << std::setw(23) << " " << data[i].orderOfAccuracy << std::endl; - logFile << data[i].lb << "\t" << data[i].b << std::endl; - } - } - + return std::shared_ptr<LogFileWriter>(new LogFileWriter(filePath)); +} - logFile << std::endl; - } +void LogFileWriter::makeOutput(std::string output) +{ + logFile << output; } std::string LogFileWriter::calcDateAndTime() @@ -76,16 +31,4 @@ std::string LogFileWriter::calcDateAndTime() nowLocal = *localtime(&now); oss << std::setfill('0') << nowLocal.tm_year + 1900 << std::setw(2) << nowLocal.tm_mon + 1 << std::setw(2) << nowLocal.tm_mday << "_" << std::setw(2) << nowLocal.tm_hour << std::setw(2) << nowLocal.tm_min << std::setw(2) << nowLocal.tm_sec; return oss.str(); -} - -void LogFileWriter::makeHastTags() -{ - logFile << "#################################################" << std::endl; -} - -void LogFileWriter::makeCenterHead(std::string output) -{ - makeHastTags(); - logFile << "#" << std::setfill(' ') << std::right << std::setw(24 + output.length()/2) << output << std::setw(24 - output.length() / 2) << "#" << std::endl; - makeHastTags(); -} +} \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.h b/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.h index e582c66a7..6fe47035b 100644 --- a/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.h +++ b/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.h @@ -1,5 +1,5 @@ -#ifndef LOGFILEWRITER_H -#define LOGFILEWRITER_H +#ifndef LOG_FILE_WRITER_H +#define LOG_FILE_WRITER_H #include <string> #include <fstream> @@ -13,17 +13,15 @@ class TestInformation; class LogFileWriter { public: - LogFileWriter(std::vector<std::shared_ptr<EvaluationParameter>> evaPara, std::shared_ptr<TestInformation> testinfo); - void makeDataQueueOutput(DataQueue* data, int arraySize); + static std::shared_ptr<LogFileWriter> getNewInstance(std::string filePath); + void makeOutput(std::string output); private: + LogFileWriter(std::string filePath); std::string calcDateAndTime(); - void makeHastTags(); - void makeCenterHead(std::string output); - + std::fstream logFile; std::string logFilePath; - time_t now; struct tm nowLocal; }; -- GitLab