Skip to content

Commit b91f2e1

Browse files
authored
Merge pull request swiftlang#257 from dmbryson/reapply237
Report extended results in commandProcessFinished
2 parents 0871fa0 + ae6934a commit b91f2e1

File tree

15 files changed

+228
-43
lines changed

15 files changed

+228
-43
lines changed

Xcode/Configs/Version.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Define the C API version
1414
//
1515
// See products/libllbuild/include/llbuild/version.h.in for version history
16-
LLBUILD_C_API_VERSION = 4
16+
LLBUILD_C_API_VERSION = 5
1717

1818
// We define both the version value and a named version. The latter is useful
1919
// in Swift conditional compilation, where we don't currently have the ability

examples/c-api/buildsystem/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ static void command_process_had_output(void* context,
179179
static void command_process_finished(void* context,
180180
llb_buildsystem_command_t* command,
181181
llb_buildsystem_process_t* process,
182-
llb_buildsystem_command_result_t result,
183-
int exit_status) {
182+
const llb_buildsystem_command_extended_result_t* result) {
184183
}
185184

186185
int main(int argc, char **argv) {

include/llbuild/BuildSystem/BuildExecutionQueue.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace buildsystem {
2727
class BuildExecutionQueueDelegate;
2828
class Command;
2929
enum class CommandResult;
30+
struct CommandExtendedResult;
3031

3132
/// Opaque type which allows the queue implementation to maintain additional
3233
/// state and associate subsequent requests (e.g., \see executeProcess()) with
@@ -230,14 +231,11 @@ class BuildExecutionQueueDelegate {
230231
/// become invalid as soon as the client returns from this API call.
231232
///
232233
/// \param result - Whether the process suceeded, failed or was cancelled.
233-
/// \param exitStatus - The raw exit status of the process, or -1 if an error
234-
/// was encountered.
235234
//
236235
// FIXME: Need to include additional information on the status here, e.g., the
237236
// signal status, and the process output (if buffering).
238237
virtual void commandProcessFinished(Command*, ProcessHandle handle,
239-
CommandResult result,
240-
int exitStatus) = 0;
238+
const CommandExtendedResult& result) = 0;
241239
};
242240

243241
/// Create an execution queue that schedules jobs to individual lanes with a

include/llbuild/BuildSystem/BuildSystemFrontend.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,11 @@ class BuildSystemFrontendDelegate : public BuildSystemDelegate {
276276
/// become invalid as soon as the client returns from this API call.
277277
///
278278
/// \param result - Whether the process suceeded, failed or was cancelled.
279-
/// \param exitStatus - The raw exit status of the process.
280279
//
281280
// FIXME: Need to include additional information on the status here, e.g., the
282281
// signal status, and the process output (if buffering).
283282
virtual void commandProcessFinished(Command*, ProcessHandle handle,
284-
CommandResult result,
285-
int exitStatus);
283+
const CommandExtendedResult& result);
286284

287285
/// Called when a cycle is detected by the build engine and it cannot make
288286
/// forward progress.

include/llbuild/BuildSystem/CommandResult.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef LLBUILD_BUILDSYSTEM_COMMAND_RESULT_H
1414
#define LLBUILD_BUILDSYSTEM_COMMAND_RESULT_H
1515

16+
#include <inttypes.h>
17+
1618
namespace llbuild {
1719
namespace buildsystem {
1820

@@ -24,6 +26,32 @@ enum class CommandResult {
2426
Skipped,
2527
};
2628

29+
/// Extended result of a command execution.
30+
struct CommandExtendedResult {
31+
CommandResult result; /// The final status of the command
32+
int exitStatus; /// The exit code
33+
34+
uint64_t utime; /// User time (in us)
35+
uint64_t stime; /// Sys time (in us)
36+
uint64_t maxrss; /// Max RSS (in bytes)
37+
38+
39+
CommandExtendedResult(CommandResult result, int exitStatus, uint64_t utime = 0,
40+
uint64_t stime = 0, uint64_t maxrss = 0)
41+
: result(result), exitStatus(exitStatus)
42+
, utime(utime), stime(stime), maxrss(maxrss)
43+
{}
44+
45+
static CommandExtendedResult makeFailed(int exitStatus = -1) {
46+
return CommandExtendedResult(CommandResult::Failed, exitStatus);
47+
}
48+
49+
static CommandExtendedResult makeCancelled(int exitStatus = -1) {
50+
return CommandExtendedResult(CommandResult::Cancelled, exitStatus);
51+
}
52+
53+
};
54+
2755
}
2856
}
2957

lib/BuildSystem/BuildSystemFrontend.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,11 @@ class BuildSystemFrontendExecutionQueueDelegate
229229
}
230230

231231
virtual void commandProcessFinished(Command* command, ProcessHandle handle,
232-
CommandResult result,
233-
int exitStatus) override {
232+
const CommandExtendedResult& result) override {
234233
static_cast<BuildSystemFrontendDelegate*>(&getSystem().getDelegate())->
235234
commandProcessFinished(
236235
command, BuildSystemFrontendDelegate::ProcessHandle { handle.id },
237-
result, exitStatus);
236+
result);
238237
}
239238
};
240239

@@ -546,8 +545,7 @@ commandProcessHadOutput(Command* command, ProcessHandle handle,
546545

547546
void BuildSystemFrontendDelegate::
548547
commandProcessFinished(Command*, ProcessHandle handle,
549-
CommandResult result,
550-
int exitStatus) {
548+
const CommandExtendedResult& result) {
551549
auto impl = static_cast<BuildSystemFrontendDelegateImpl*>(this->impl);
552550
std::unique_lock<std::mutex> lock(impl->processOutputBuffersMutex);
553551

lib/BuildSystem/LaneBasedExecutionQueue.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class LaneBasedExecutionQueue : public BuildExecutionQueue {
325325
context.job.getForCommand(), handle,
326326
Twine("unable to open output pipe (") + strerror(errno) + ")");
327327
getDelegate().commandProcessFinished(context.job.getForCommand(),
328-
handle, CommandResult::Failed, -1);
328+
handle, CommandExtendedResult::makeFailed());
329329
return CommandResult::Failed;
330330
}
331331

@@ -409,7 +409,7 @@ class LaneBasedExecutionQueue : public BuildExecutionQueue {
409409
context.job.getForCommand(), handle,
410410
Twine("unable to spawn process (") + strerror(result) + ")");
411411
getDelegate().commandProcessFinished(context.job.getForCommand(), handle,
412-
CommandResult::Failed, -1);
412+
CommandExtendedResult::makeFailed());
413413
pid = -1;
414414
} else {
415415
spawnedProcesses.insert(pid);
@@ -475,18 +475,21 @@ class LaneBasedExecutionQueue : public BuildExecutionQueue {
475475
context.job.getForCommand(), handle,
476476
Twine("unable to wait for process (") + strerror(errno) + ")");
477477
getDelegate().commandProcessFinished(context.job.getForCommand(), handle,
478-
CommandResult::Failed, -1);
478+
CommandExtendedResult::makeFailed(status));
479479
return CommandResult::Failed;
480480
}
481481

482482
// We report additional info in the tracing interval
483483
// arg2: user time, in us
484484
// arg3: sys time, in us
485485
// arg4: memory usage, in bytes
486-
subprocessInterval.arg2 = (uint64_t(usage.ru_utime.tv_sec) * 1000000000 +
487-
uint64_t(usage.ru_utime.tv_usec) * 1000);
488-
subprocessInterval.arg3 = (uint64_t(usage.ru_stime.tv_sec) * 1000000000 +
489-
uint64_t(usage.ru_stime.tv_usec) * 1000);
486+
uint64_t utime = (uint64_t(usage.ru_utime.tv_sec) * 1000000000 +
487+
uint64_t(usage.ru_utime.tv_usec) * 1000);
488+
uint64_t stime = (uint64_t(usage.ru_stime.tv_sec) * 1000000000 +
489+
uint64_t(usage.ru_stime.tv_usec) * 1000);
490+
491+
subprocessInterval.arg2 = utime;
492+
subprocessInterval.arg3 = stime;
490493
subprocessInterval.arg4 = usage.ru_maxrss;
491494

492495
// FIXME: We should report a statistic for how much output we read from the
@@ -495,8 +498,10 @@ class LaneBasedExecutionQueue : public BuildExecutionQueue {
495498
// Notify of the process completion.
496499
bool cancelled = WIFSIGNALED(status) && (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGKILL);
497500
CommandResult commandResult = cancelled ? CommandResult::Cancelled : (status == 0) ? CommandResult::Succeeded : CommandResult::Failed;
501+
CommandExtendedResult extendedResult(commandResult, status, utime, stime,
502+
usage.ru_maxrss);
498503
getDelegate().commandProcessFinished(context.job.getForCommand(), handle,
499-
commandResult, status);
504+
extendedResult);
500505
return commandResult;
501506
}
502507
};

llbuild.xcodeproj/project.pbxproj

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,26 @@
791791
40377C7C2061D24200C0FD4D /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
792792
403B1A48205312000018A322 /* version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = version.h; sourceTree = "<group>"; };
793793
40F4F4F220531D8A00170EE1 /* version.h.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = version.h.in; sourceTree = "<group>"; };
794+
40F638CE2051EDC800A1CFBE /* count-lines-2 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "count-lines-2"; sourceTree = "<group>"; };
795+
40F638CF2051EDC800A1CFBE /* count-lines-4 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "count-lines-4"; sourceTree = "<group>"; };
796+
40F638D02051EDC800A1CFBE /* count-lines-3 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "count-lines-3"; sourceTree = "<group>"; };
797+
40F638D12051EDC800A1CFBE /* simplebuild.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = simplebuild.py; sourceTree = "<group>"; };
798+
40F638D22051EDC800A1CFBE /* simple-make */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "simple-make"; sourceTree = "<group>"; };
799+
40F638D32051EDC800A1CFBE /* util.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = util.py; sourceTree = "<group>"; };
800+
40F638D42051EDC800A1CFBE /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
801+
40F638D52051EDC800A1CFBE /* count-lines-1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "count-lines-1"; sourceTree = "<group>"; };
802+
40F638D82051EDC800A1CFBE /* basic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = basic.swift; sourceTree = "<group>"; };
803+
40F638DA2051EDC800A1CFBE /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
804+
40F638DB2051EDC800A1CFBE /* .gitignore */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
805+
40F638DD2051EDC800A1CFBE /* index.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index.html; sourceTree = "<group>"; };
806+
40F638DE2051EDC800A1CFBE /* PlayLife.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = PlayLife.js; sourceTree = "<group>"; };
807+
40F638DF2051EDC800A1CFBE /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
808+
40F638E22051EDC800A1CFBE /* LifeBoard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LifeBoard.swift; sourceTree = "<group>"; };
809+
40F638E32051EDC800A1CFBE /* LifeBoard+Build.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "LifeBoard+Build.swift"; sourceTree = "<group>"; };
810+
40F638E42051EDC800A1CFBE /* BuildLife.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BuildLife.swift; sourceTree = "<group>"; };
811+
40F638E62051EDC800A1CFBE /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
812+
40F638E92051EDC800A1CFBE /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
813+
40F638EA2051EDC800A1CFBE /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
794814
40F638EC2053043D00A1CFBE /* Version.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
795815
54E187B61CD296EA00F7EC89 /* BuildNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BuildNode.h; sourceTree = "<group>"; };
796816
54E187B71CD296EA00F7EC89 /* ExternalCommand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExternalCommand.h; sourceTree = "<group>"; };
@@ -1309,6 +1329,113 @@
13091329
/* End PBXFrameworksBuildPhase section */
13101330

13111331
/* Begin PBXGroup section */
1332+
40F638CC2051EDC800A1CFBE /* examples */ = {
1333+
isa = PBXGroup;
1334+
children = (
1335+
40F638CD2051EDC800A1CFBE /* simple-make */,
1336+
40F638D62051EDC800A1CFBE /* swift-bindings */,
1337+
40F638D92051EDC800A1CFBE /* GameOfLife */,
1338+
40F638E72051EDC800A1CFBE /* c-api */,
1339+
);
1340+
path = examples;
1341+
sourceTree = "<group>";
1342+
};
1343+
40F638CD2051EDC800A1CFBE /* simple-make */ = {
1344+
isa = PBXGroup;
1345+
children = (
1346+
40F638CE2051EDC800A1CFBE /* count-lines-2 */,
1347+
40F638CF2051EDC800A1CFBE /* count-lines-4 */,
1348+
40F638D02051EDC800A1CFBE /* count-lines-3 */,
1349+
40F638D12051EDC800A1CFBE /* simplebuild.py */,
1350+
40F638D22051EDC800A1CFBE /* simple-make */,
1351+
40F638D32051EDC800A1CFBE /* util.py */,
1352+
40F638D42051EDC800A1CFBE /* README.md */,
1353+
40F638D52051EDC800A1CFBE /* count-lines-1 */,
1354+
);
1355+
path = "simple-make";
1356+
sourceTree = "<group>";
1357+
};
1358+
40F638D62051EDC800A1CFBE /* swift-bindings */ = {
1359+
isa = PBXGroup;
1360+
children = (
1361+
40F638D72051EDC800A1CFBE /* core */,
1362+
);
1363+
path = "swift-bindings";
1364+
sourceTree = "<group>";
1365+
};
1366+
40F638D72051EDC800A1CFBE /* core */ = {
1367+
isa = PBXGroup;
1368+
children = (
1369+
40F638D82051EDC800A1CFBE /* basic.swift */,
1370+
);
1371+
path = core;
1372+
sourceTree = "<group>";
1373+
};
1374+
40F638D92051EDC800A1CFBE /* GameOfLife */ = {
1375+
isa = PBXGroup;
1376+
children = (
1377+
40F638DA2051EDC800A1CFBE /* README.md */,
1378+
40F638DB2051EDC800A1CFBE /* .gitignore */,
1379+
40F638DC2051EDC800A1CFBE /* Static */,
1380+
40F638DF2051EDC800A1CFBE /* Package.swift */,
1381+
40F638E02051EDC800A1CFBE /* Sources */,
1382+
);
1383+
path = GameOfLife;
1384+
sourceTree = "<group>";
1385+
};
1386+
40F638DC2051EDC800A1CFBE /* Static */ = {
1387+
isa = PBXGroup;
1388+
children = (
1389+
40F638DD2051EDC800A1CFBE /* index.html */,
1390+
40F638DE2051EDC800A1CFBE /* PlayLife.js */,
1391+
);
1392+
path = Static;
1393+
sourceTree = "<group>";
1394+
};
1395+
40F638E02051EDC800A1CFBE /* Sources */ = {
1396+
isa = PBXGroup;
1397+
children = (
1398+
40F638E12051EDC800A1CFBE /* GameOfLife */,
1399+
40F638E52051EDC800A1CFBE /* LifeServer */,
1400+
);
1401+
path = Sources;
1402+
sourceTree = "<group>";
1403+
};
1404+
40F638E12051EDC800A1CFBE /* GameOfLife */ = {
1405+
isa = PBXGroup;
1406+
children = (
1407+
40F638E22051EDC800A1CFBE /* LifeBoard.swift */,
1408+
40F638E32051EDC800A1CFBE /* LifeBoard+Build.swift */,
1409+
40F638E42051EDC800A1CFBE /* BuildLife.swift */,
1410+
);
1411+
path = GameOfLife;
1412+
sourceTree = "<group>";
1413+
};
1414+
40F638E52051EDC800A1CFBE /* LifeServer */ = {
1415+
isa = PBXGroup;
1416+
children = (
1417+
40F638E62051EDC800A1CFBE /* main.swift */,
1418+
);
1419+
path = LifeServer;
1420+
sourceTree = "<group>";
1421+
};
1422+
40F638E72051EDC800A1CFBE /* c-api */ = {
1423+
isa = PBXGroup;
1424+
children = (
1425+
40F638E82051EDC800A1CFBE /* buildsystem */,
1426+
);
1427+
path = "c-api";
1428+
sourceTree = "<group>";
1429+
};
1430+
40F638E82051EDC800A1CFBE /* buildsystem */ = {
1431+
isa = PBXGroup;
1432+
children = (
1433+
40F638E92051EDC800A1CFBE /* README.md */,
1434+
40F638EA2051EDC800A1CFBE /* main.c */,
1435+
);
1436+
path = buildsystem;
1437+
sourceTree = "<group>";
1438+
};
13121439
9DB0478A1DF9D39E006CDF52 /* BuildSystem */ = {
13131440
isa = PBXGroup;
13141441
children = (
@@ -1413,6 +1540,7 @@
14131540
E14144901EBDA4A10046F282 /* Xcode */,
14141541
E1A223FD19F990F10059043E /* products */,
14151542
E1A2240419F991530059043E /* lib */,
1543+
40F638CC2051EDC800A1CFBE /* examples */,
14161544
E19C3FD51B98C1A70035E1AA /* tests */,
14171545
E1C404B51A03090D003392BA /* perftests */,
14181546
E1A224B219F998D40059043E /* unittests */,
@@ -1453,10 +1581,10 @@
14531581
E1A223FD19F990F10059043E /* products */ = {
14541582
isa = PBXGroup;
14551583
children = (
1456-
BC8DEF0420300AAF00E9EF0C /* llbuildSwift */,
14571584
E1A2240119F991350059043E /* llbuild */,
14581585
E1ADC22F1A8591F600D5387C /* libllbuild */,
14591586
E1D191B71B472305000C4E95 /* llbuild-framework */,
1587+
BC8DEF0420300AAF00E9EF0C /* llbuildSwift */,
14601588
E1604CB21BB9E032001153A1 /* swift-build-tool */,
14611589
E1A2240019F991350059043E /* CMakeLists.txt */,
14621590
);

products/libllbuild/BuildSystem-C-API.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,20 @@ class CAPIBuildSystemFrontendDelegate : public BuildSystemFrontendDelegate {
314314
}
315315

316316
virtual void commandProcessFinished(Command* command, ProcessHandle handle,
317-
CommandResult commandResult,
318-
int exitStatus) override {
317+
const CommandExtendedResult& commandResult) override {
319318
if (cAPIDelegate.command_process_finished) {
319+
llb_buildsystem_command_extended_result_t result;
320+
result.result = get_command_result(commandResult.result);
321+
result.exit_status = commandResult.exitStatus;
322+
result.utime = commandResult.utime;
323+
result.stime = commandResult.stime;
324+
result.maxrss = commandResult.maxrss;
325+
320326
cAPIDelegate.command_process_finished(
321327
cAPIDelegate.context,
322328
(llb_buildsystem_command_t*) command,
323329
(llb_buildsystem_process_t*) handle.id,
324-
get_command_result(commandResult),
325-
exitStatus);
330+
&result);
326331
}
327332
}
328333

products/libllbuild/include/llbuild/buildsystem.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ typedef enum {
9595
llb_buildsystem_command_result_skipped = 3,
9696
} llb_buildsystem_command_result_t;
9797

98+
/// Extended result of a command execution
99+
typedef struct llb_buildsystem_command_extended_result_t_ {
100+
llb_buildsystem_command_result_t result; /// Result of command execution
101+
int exit_status; /// The exit code
102+
uint64_t utime; /// User time (in us)
103+
uint64_t stime; /// Sys time (in us)
104+
uint64_t maxrss; /// Max RSS (in bytes)
105+
} llb_buildsystem_command_extended_result_t;
106+
98107
/// Status change event kinds.
99108
typedef enum {
100109
/// Indicates the command is being scanned to determine if it needs to run.
@@ -386,8 +395,7 @@ typedef struct llb_buildsystem_delegate_t_ {
386395
void (*command_process_finished)(void* context,
387396
llb_buildsystem_command_t* command,
388397
llb_buildsystem_process_t* process,
389-
llb_buildsystem_command_result_t result,
390-
int exit_status);
398+
const llb_buildsystem_command_extended_result_t* result);
391399

392400
/// Called when a cycle is detected by the build engine and it cannot make
393401
/// forward progress.

0 commit comments

Comments
 (0)