mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Driver] Added process information to emitted messages
When providing the -parseable-output flag to the swift compiler, it will provide json formatted messages about tasks that run. I added some optional usage information in form of user time, system time and maxrss to the output. This can be used by other tools using the compiler to get some insights about time and memory usage. Since the output does not longer match processes run (in batch mode), I also added a real_pid field so the client could reason about jobs that belong together if needed. rdar://39798231
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "swift/Driver/ParseableOutput.h"
|
||||
|
||||
#include "swift/Basic/JSONSerialization.h"
|
||||
#include "swift/Basic/TaskQueue.h"
|
||||
#include "swift/Driver/Action.h"
|
||||
#include "swift/Driver/Job.h"
|
||||
#include "swift/Frontend/FileTypes.h"
|
||||
@@ -21,6 +22,7 @@
|
||||
|
||||
using namespace swift::driver::parseable_output;
|
||||
using namespace swift::driver;
|
||||
using namespace swift::sys;
|
||||
using namespace swift;
|
||||
|
||||
namespace {
|
||||
@@ -168,26 +170,33 @@ public:
|
||||
|
||||
class BeganMessage : public DetailedCommandBasedMessage {
|
||||
int64_t Pid;
|
||||
TaskProcessInformation ProcInfo;
|
||||
|
||||
public:
|
||||
BeganMessage(const Job &Cmd, int64_t Pid) :
|
||||
DetailedCommandBasedMessage("began", Cmd), Pid(Pid) {}
|
||||
BeganMessage(const Job &Cmd, int64_t Pid, TaskProcessInformation ProcInfo)
|
||||
: DetailedCommandBasedMessage("began", Cmd), Pid(Pid),
|
||||
ProcInfo(ProcInfo) {}
|
||||
|
||||
void provideMapping(swift::json::Output &out) override {
|
||||
DetailedCommandBasedMessage::provideMapping(out);
|
||||
out.mapRequired("pid", Pid);
|
||||
out.mapRequired("process", ProcInfo);
|
||||
}
|
||||
};
|
||||
|
||||
class TaskOutputMessage : public TaskBasedMessage {
|
||||
std::string Output;
|
||||
TaskProcessInformation ProcInfo;
|
||||
|
||||
public:
|
||||
TaskOutputMessage(StringRef Kind, const Job &Cmd, int64_t Pid,
|
||||
StringRef Output) : TaskBasedMessage(Kind, Cmd, Pid),
|
||||
Output(Output) {}
|
||||
StringRef Output, TaskProcessInformation ProcInfo)
|
||||
: TaskBasedMessage(Kind, Cmd, Pid), Output(Output), ProcInfo(ProcInfo) {}
|
||||
|
||||
void provideMapping(swift::json::Output &out) override {
|
||||
TaskBasedMessage::provideMapping(out);
|
||||
out.mapOptional("output", Output, std::string());
|
||||
out.mapRequired("process", ProcInfo);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -195,9 +204,9 @@ class FinishedMessage : public TaskOutputMessage {
|
||||
int ExitStatus;
|
||||
public:
|
||||
FinishedMessage(const Job &Cmd, int64_t Pid, StringRef Output,
|
||||
int ExitStatus) : TaskOutputMessage("finished", Cmd, Pid,
|
||||
Output),
|
||||
ExitStatus(ExitStatus) {}
|
||||
TaskProcessInformation ProcInfo, int ExitStatus)
|
||||
: TaskOutputMessage("finished", Cmd, Pid, Output, ProcInfo),
|
||||
ExitStatus(ExitStatus) {}
|
||||
|
||||
void provideMapping(swift::json::Output &out) override {
|
||||
TaskOutputMessage::provideMapping(out);
|
||||
@@ -210,9 +219,10 @@ class SignalledMessage : public TaskOutputMessage {
|
||||
Optional<int> Signal;
|
||||
public:
|
||||
SignalledMessage(const Job &Cmd, int64_t Pid, StringRef Output,
|
||||
StringRef ErrorMsg, Optional<int> Signal) :
|
||||
TaskOutputMessage("signalled", Cmd, Pid, Output), ErrorMsg(ErrorMsg),
|
||||
Signal(Signal) {}
|
||||
StringRef ErrorMsg, Optional<int> Signal,
|
||||
TaskProcessInformation ProcInfo)
|
||||
: TaskOutputMessage("signalled", Cmd, Pid, Output, ProcInfo),
|
||||
ErrorMsg(ErrorMsg), Signal(Signal) {}
|
||||
|
||||
void provideMapping(swift::json::Output &out) override {
|
||||
TaskOutputMessage::provideMapping(out);
|
||||
@@ -252,25 +262,27 @@ static void emitMessage(raw_ostream &os, Message &msg) {
|
||||
os << JSONString << '\n';
|
||||
}
|
||||
|
||||
void parseable_output::emitBeganMessage(raw_ostream &os,
|
||||
const Job &Cmd, int64_t Pid) {
|
||||
BeganMessage msg(Cmd, Pid);
|
||||
void parseable_output::emitBeganMessage(raw_ostream &os, const Job &Cmd,
|
||||
int64_t Pid,
|
||||
TaskProcessInformation ProcInfo) {
|
||||
BeganMessage msg(Cmd, Pid, ProcInfo);
|
||||
emitMessage(os, msg);
|
||||
}
|
||||
|
||||
void parseable_output::emitFinishedMessage(raw_ostream &os,
|
||||
const Job &Cmd, int64_t Pid,
|
||||
int ExitStatus, StringRef Output) {
|
||||
FinishedMessage msg(Cmd, Pid, Output, ExitStatus);
|
||||
void parseable_output::emitFinishedMessage(raw_ostream &os, const Job &Cmd,
|
||||
int64_t Pid, int ExitStatus,
|
||||
StringRef Output,
|
||||
TaskProcessInformation ProcInfo) {
|
||||
FinishedMessage msg(Cmd, Pid, Output, ProcInfo, ExitStatus);
|
||||
emitMessage(os, msg);
|
||||
}
|
||||
|
||||
void parseable_output::emitSignalledMessage(raw_ostream &os,
|
||||
const Job &Cmd, int64_t Pid,
|
||||
StringRef ErrorMsg,
|
||||
void parseable_output::emitSignalledMessage(raw_ostream &os, const Job &Cmd,
|
||||
int64_t Pid, StringRef ErrorMsg,
|
||||
StringRef Output,
|
||||
Optional<int> Signal) {
|
||||
SignalledMessage msg(Cmd, Pid, Output, ErrorMsg, Signal);
|
||||
Optional<int> Signal,
|
||||
TaskProcessInformation ProcInfo) {
|
||||
SignalledMessage msg(Cmd, Pid, Output, ErrorMsg, Signal, ProcInfo);
|
||||
emitMessage(os, msg);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user