Skip to content

Add new output formats #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/Exception.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "logger/Logger.h"

#include <cstdint>
#include <cstring>

namespace s2j {
Expand Down
1 change: 1 addition & 0 deletions src/common/Exception.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstdint>
#include <string>

namespace s2j {
Expand Down
1 change: 1 addition & 0 deletions src/common/ProcFS.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ProcFS.h"

#include <cstdint>
#include <fstream>
#include <functional>
#include <map>
Expand Down
1 change: 1 addition & 0 deletions src/limits/MemoryLimitListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sys/time.h>

#include <csignal>
#include <cstdint>
#include <fstream>
#include <iostream>

Expand Down
2 changes: 2 additions & 0 deletions src/limits/MemoryLimitListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "seccomp/policy/SyscallPolicy.h"
#include "tracer/TraceEventListener.h"

#include <cstdint>

namespace s2j {
namespace limits {

Expand Down
1 change: 1 addition & 0 deletions src/limits/OutputLimitListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "seccomp/filter/LibSeccompFilter.h"

#include <csignal>
#include <cstdint>
#include <sys/resource.h>
#include <sys/time.h>

Expand Down
2 changes: 2 additions & 0 deletions src/limits/OutputLimitListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "printer/OutputSource.h"
#include "seccomp/policy/SyscallPolicy.h"

#include <cstdint>

namespace s2j {
namespace limits {

Expand Down
2 changes: 2 additions & 0 deletions src/limits/ThreadsLimitListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "seccomp/action/ActionKill.h"
#include "seccomp/filter/LibSeccompFilter.h"

#include <cstdint>

namespace s2j {
namespace limits {

Expand Down
3 changes: 3 additions & 0 deletions src/limits/TimeLimitListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <algorithm>
#include <chrono>
#include <csignal>
#include <cstdint>
#include <ctime>
#include <fstream>
#include <limits>
Expand Down Expand Up @@ -96,6 +97,8 @@ void TimeLimitListener::onPostExecute() {
// TODO: run this just after child exit
auto time = getTimeUsage();
outputBuilder_->setRealTimeMicroseconds(time->realTimeUs);
outputBuilder_->setUserTimeMicroseconds(time->processTimeUs.uTimeUs);
outputBuilder_->setSysTimeMicroseconds(time->processTimeUs.sTimeUs);
verifyTimeUsage(move(time));
}

Expand Down
1 change: 1 addition & 0 deletions src/limits/TimeLimitListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "printer/OutputSource.h"

#include <chrono>
#include <cstdint>

namespace s2j {
namespace limits {
Expand Down
1 change: 1 addition & 0 deletions src/ns/MountNamespaceListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common/WithErrnoCheck.h"
#include "logger/Logger.h"

#include <cstdint>
#include <fcntl.h>
#include <linux/sched.h>
#include <sys/mount.h>
Expand Down
1 change: 1 addition & 0 deletions src/ns/MountNamespaceListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <tclap/CmdLine.h>

#include <cstdint>
#include <string>

namespace s2j {
Expand Down
1 change: 1 addition & 0 deletions src/perf/PerfListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/mman.h>

#include <csignal>
#include <cstdint>
#include <cstdlib>
#include <cstring>

Expand Down
2 changes: 2 additions & 0 deletions src/perf/PerfListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "executor/ExecuteEventListener.h"
#include "printer/OutputSource.h"

#include <cstdint>

namespace s2j {
namespace perf {

Expand Down
15 changes: 0 additions & 15 deletions src/printer/AugmentedOIOutputBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,5 @@ std::string AugmentedOIOutputBuilder::dump() const {
return ss.str();
}

void AugmentedOIOutputBuilder::dumpStatus(std::ostream& ss) const {
if (killReason_ != KillReason::NONE) {
ss << killReasonComment_;
}
else if (killSignal_ > 0) {
ss << "process exited due to signal " << killSignal_;
}
else if (exitStatus_ > 0) {
ss << "runtime error " << exitStatus_;
}
else {
ss << "ok";
}
}

} // namespace printer
} // namespace s2j
4 changes: 0 additions & 4 deletions src/printer/AugmentedOIOutputBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class AugmentedOIOutputBuilder : public OIModelOutputBuilder {
std::string dump() const override;

const static std::string FORMAT_NAME;

private:
void dumpStatus(std::ostream& ss) const;
int encodeStatusCode() const;
};

} // namespace printer
Expand Down
23 changes: 23 additions & 0 deletions src/printer/HumanReadableOIOutputBuilder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "HumanReadableOIOutputBuilder.h"

#include <sstream>

namespace s2j {
namespace printer {

const std::string HumanReadableOIOutputBuilder::FORMAT_NAME = "human";

std::string HumanReadableOIOutputBuilder::dump() const {
// This is inspired by the oiejq script
std::stringstream ss;
ss << std::endl << "-------------------------" << std::endl << "Result: ";
dumpStatus(ss);
ss << std::endl
<< "Time used: " << static_cast<float>(milliSecondsElapsed_) / 1000
<< "s" << std::endl
<< "Memory used: " << memoryPeakKb_ / 1024 << "MiB" << std::endl;
return ss.str();
}

} // namespace printer
} // namespace s2j
16 changes: 16 additions & 0 deletions src/printer/HumanReadableOIOutputBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "OIModelOutputBuilder.h"

namespace s2j {
namespace printer {

class HumanReadableOIOutputBuilder : public OIModelOutputBuilder {
public:
std::string dump() const override;

const static std::string FORMAT_NAME;
};

} // namespace printer
} // namespace s2j
28 changes: 28 additions & 0 deletions src/printer/OIModelOutputBuilder.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "OIModelOutputBuilder.h"

#include <cstdint>
#include <sstream>

namespace s2j {
namespace printer {

Expand All @@ -21,6 +24,16 @@ OutputBuilder& OIModelOutputBuilder::setRealTimeMicroseconds(uint64_t time) {
return *this;
}

OutputBuilder& OIModelOutputBuilder::setUserTimeMicroseconds(uint64_t time) {
userMilliSecondsElapsed_ = time / 1000;
return *this;
}

OutputBuilder& OIModelOutputBuilder::setSysTimeMicroseconds(uint64_t time) {
sysMilliSecondsElapsed_ = time / 1000;
return *this;
}

OutputBuilder& OIModelOutputBuilder::setMemoryPeak(uint64_t memoryPeakKb) {
memoryPeakKb_ = memoryPeakKb;
return *this;
Expand Down Expand Up @@ -53,5 +66,20 @@ OutputBuilder& OIModelOutputBuilder::setKillReason(
return *this;
}

void OIModelOutputBuilder::dumpStatus(std::ostream& ss) const {
if (killReason_ != KillReason::NONE) {
ss << killReasonComment_;
}
else if (killSignal_ > 0) {
ss << "process exited due to signal " << killSignal_;
}
else if (exitStatus_ > 0) {
ss << "runtime error " << exitStatus_;
}
else {
ss << "ok";
}
}

} // namespace printer
} // namespace s2j
8 changes: 8 additions & 0 deletions src/printer/OIModelOutputBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "OutputBuilder.h"

#include <cstdint>

namespace s2j {
namespace printer {

Expand All @@ -11,6 +13,8 @@ class OIModelOutputBuilder : public OutputBuilder {

OutputBuilder& setCyclesUsed(uint64_t cyclesUsed) override;
OutputBuilder& setRealTimeMicroseconds(uint64_t time) override;
OutputBuilder& setUserTimeMicroseconds(uint64_t time) override;
OutputBuilder& setSysTimeMicroseconds(uint64_t time) override;
OutputBuilder& setMemoryPeak(uint64_t memoryPeakKb) override;
OutputBuilder& setExitStatus(uint32_t exitStatus) override;
OutputBuilder& setKillSignal(uint32_t killSignal) override;
Expand All @@ -22,13 +26,17 @@ class OIModelOutputBuilder : public OutputBuilder {

uint64_t milliSecondsElapsed_;
uint64_t realMilliSecondsElapsed_;
uint64_t userMilliSecondsElapsed_;
uint64_t sysMilliSecondsElapsed_;
uint64_t memoryPeakKb_;
uint64_t syscallsCounter_;
uint32_t exitStatus_;
uint32_t killSignal_;

KillReason killReason_ = KillReason::NONE;
std::string killReasonComment_;

void dumpStatus(std::ostream& ss) const;
};

} // namespace printer
Expand Down
15 changes: 0 additions & 15 deletions src/printer/OITimeToolOutputBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,6 @@ std::string OITimeToolOutputBuilder::dump() const {
return ss.str();
}

void OITimeToolOutputBuilder::dumpStatus(std::ostream& ss) const {
if (killReason_ != KillReason::NONE) {
ss << killReasonComment_;
}
else if (killSignal_ > 0) {
ss << "process exited due to signal " << killSignal_;
}
else if (exitStatus_ > 0) {
ss << "runtime error " << exitStatus_;
}
else {
ss << "ok";
}
}

int OITimeToolOutputBuilder::encodeStatusCode() const {
static const int CODE_SIG_BASE = 0;
static const int CODE_RE_BASE = 200;
Expand Down
1 change: 0 additions & 1 deletion src/printer/OITimeToolOutputBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class OITimeToolOutputBuilder : public OIModelOutputBuilder {
const static std::string FORMAT_NAME;

private:
void dumpStatus(std::ostream& ss) const;
int encodeStatusCode() const;
};

Expand Down
7 changes: 7 additions & 0 deletions src/printer/OutputBuilder.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstdint>
#include <string>

namespace s2j {
Expand Down Expand Up @@ -35,6 +36,12 @@ class OutputBuilder {
virtual OutputBuilder& setRealTimeMicroseconds(uint64_t time) {
return *this;
}
virtual OutputBuilder& setUserTimeMicroseconds(uint64_t time) {
return *this;
}
virtual OutputBuilder& setSysTimeMicroseconds(uint64_t time) {
return *this;
}
virtual OutputBuilder& setMemoryPeak(uint64_t memoryPeakKb) {
return *this;
}
Expand Down
15 changes: 0 additions & 15 deletions src/printer/RealTimeOIOutputBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,5 @@ std::string RealTimeOIOutputBuilder::dump() const {
return ss.str();
}

void RealTimeOIOutputBuilder::dumpStatus(std::ostream& ss) const {
if (killReason_ != KillReason::NONE) {
ss << killReasonComment_;
}
else if (killSignal_ > 0) {
ss << "process exited due to signal " << killSignal_;
}
else if (exitStatus_ > 0) {
ss << "runtime error " << exitStatus_;
}
else {
ss << "ok";
}
}

} // namespace printer
} // namespace s2j
4 changes: 0 additions & 4 deletions src/printer/RealTimeOIOutputBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class RealTimeOIOutputBuilder : public OIModelOutputBuilder {
std::string dump() const override;

const static std::string FORMAT_NAME;

private:
void dumpStatus(std::ostream& ss) const;
int encodeStatusCode() const;
};

} // namespace printer
Expand Down
29 changes: 29 additions & 0 deletions src/printer/UserTimeOIOutputBuilder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "UserTimeOIOutputBuilder.h"
#include "common/Exception.h"

#include <sstream>

namespace s2j {
namespace printer {

const std::string UserTimeOIOutputBuilder::FORMAT_NAME = "oiuser";

std::string UserTimeOIOutputBuilder::dump() const {
KillReason reason = killReason_;
if (reason == KillReason::NONE) {
if (killSignal_ > 0 || exitStatus_ > 0) {
reason = KillReason::RE;
}
}

std::stringstream ss;
ss << killReasonName(reason) << " " << exitStatus_ << " "
<< userMilliSecondsElapsed_ << " " << 0ULL << " " << memoryPeakKb_ << " "
<< syscallsCounter_ << std::endl;
dumpStatus(ss);
ss << std::endl;
return ss.str();
}

} // namespace printer
} // namespace s2j
Loading