@@ -204,6 +204,25 @@ class EngineImpl: public ActionExecutorListener {
204
204
std::condition_variable readyJobsCondition;
205
205
bool shutdown{false };
206
206
207
+ // / Perf counters
208
+ std::atomic<uint64_t > st_buildCount{0 };
209
+ std::atomic<uint64_t > st_buildCompletedCount{0 };
210
+
211
+ std::atomic<uint64_t > st_artifactRequestCount{0 };
212
+ std::atomic<uint64_t > st_ruleRequestCount{0 };
213
+
214
+ std::atomic<uint64_t > st_taskCount{0 };
215
+ std::atomic<uint64_t > st_taskTransitions{0 };
216
+ std::atomic<uint64_t > st_taskCacheHits{0 };
217
+ std::atomic<uint64_t > st_taskCacheMisses{0 };
218
+ std::atomic<uint64_t > st_taskCompletedCount{0 };
219
+
220
+ std::atomic<uint64_t > st_actionCount{0 };
221
+ std::atomic<uint64_t > st_actionCompletedCount{0 };
222
+ std::atomic<uint64_t > st_subtaskCount{0 };
223
+ std::atomic<uint64_t > st_subtaskCompletedCount{0 };
224
+
225
+
207
226
public:
208
227
EngineImpl (EngineConfig config, std::shared_ptr<CASDatabase> casDB,
209
228
std::shared_ptr<ActionCache> cache,
@@ -301,6 +320,7 @@ class EngineImpl: public ActionExecutorListener {
301
320
// / @{
302
321
303
322
Build build (const Label& artifact) {
323
+ st_buildCount++;
304
324
auto context = std::shared_ptr<BuildContext>(new BuildContext ());
305
325
306
326
uint64_t buildID = 0 ;
@@ -321,6 +341,7 @@ class EngineImpl: public ActionExecutorListener {
321
341
}
322
342
323
343
if (res.has_error ()) {
344
+ st_buildCompletedCount++;
324
345
logger->event (logctx, {
325
346
makeStat (" log.message" , " build_completed" ),
326
347
makeStat (" build_id" , buildID),
@@ -333,6 +354,24 @@ class EngineImpl: public ActionExecutorListener {
333
354
return Build (context);
334
355
}
335
356
357
+ std::vector<Stat> stats () {
358
+ return {
359
+ makeStat (" builds" , st_buildCount),
360
+ makeStat (" builds_completed" , st_buildCompletedCount),
361
+ makeStat (" artifact_requests" , st_artifactRequestCount),
362
+ makeStat (" rule_requests" , st_ruleRequestCount),
363
+ makeStat (" tasks" , st_taskCount),
364
+ makeStat (" task_transitions" , st_taskTransitions),
365
+ makeStat (" task_cache_hits" , st_taskCacheHits),
366
+ makeStat (" task_cache_misses" , st_taskCacheMisses),
367
+ makeStat (" tasks_completed" , st_taskCompletedCount),
368
+ makeStat (" actions" , st_actionCount),
369
+ makeStat (" actions_completed" , st_actionCompletedCount),
370
+ makeStat (" subtasks" , st_subtaskCount),
371
+ makeStat (" subtasks_completed" , st_subtaskCompletedCount)
372
+ };
373
+ }
374
+
336
375
// / @}
337
376
338
377
// / @name Task Management Client APIs
@@ -344,6 +383,7 @@ class EngineImpl: public ActionExecutorListener {
344
383
345
384
result<uint64_t , Error> taskRequestArtifact (uint64_t taskID,
346
385
const Label& label) {
386
+ st_artifactRequestCount++;
347
387
// FIXME: concretize label with context?
348
388
349
389
uint64_t buildID = 0 ;
@@ -444,6 +484,7 @@ class EngineImpl: public ActionExecutorListener {
444
484
}
445
485
446
486
result<uint64_t , Error> taskRequestRule (uint64_t taskID, const Label& label) {
487
+ st_ruleRequestCount++;
447
488
// FIXME: concretize label with context?
448
489
449
490
uint64_t buildID = 0 ;
@@ -539,6 +580,8 @@ class EngineImpl: public ActionExecutorListener {
539
580
}
540
581
541
582
result<uint64_t , Error> taskRequestAction (uint64_t taskID, const Action& action) {
583
+ st_actionCount++;
584
+
542
585
uint64_t buildID = 0 ;
543
586
uint64_t workID = 0 ;
544
587
@@ -561,6 +604,7 @@ class EngineImpl: public ActionExecutorListener {
561
604
if (res.has_error ()) {
562
605
std::lock_guard<std::mutex> lock (taskInfosMutex);
563
606
actionTaskMap.erase (workID);
607
+ st_actionCompletedCount++;
564
608
return fail (res.error ());
565
609
}
566
610
@@ -575,6 +619,8 @@ class EngineImpl: public ActionExecutorListener {
575
619
}
576
620
577
621
result<uint64_t , Error> taskSpawnSubtask (uint64_t taskID, const Subtask& subtask) {
622
+ st_subtaskCount++;
623
+
578
624
uint64_t buildID = 0 ;
579
625
uint64_t workID = 0 ;
580
626
uint64_t sid = 0 ;
@@ -599,6 +645,7 @@ class EngineImpl: public ActionExecutorListener {
599
645
if (res.has_error ()) {
600
646
std::lock_guard<std::mutex> lock (taskInfosMutex);
601
647
subtaskTaskMap.erase (workID);
648
+ st_subtaskCompletedCount++;
602
649
return fail (res.error ());
603
650
}
604
651
@@ -635,6 +682,8 @@ class EngineImpl: public ActionExecutorListener {
635
682
return ;
636
683
}
637
684
685
+ st_actionCompletedCount++;
686
+
638
687
auto taskID = entry->second ;
639
688
auto & rtask = taskInfos.at (taskID);
640
689
rtask.pendingActions .at (cid.workID ).result = {std::move (result)};
@@ -658,6 +707,8 @@ class EngineImpl: public ActionExecutorListener {
658
707
return ;
659
708
}
660
709
710
+ st_subtaskCompletedCount++;
711
+
661
712
auto taskID = entry->second ;
662
713
auto & rtask = taskInfos.at (taskID);
663
714
rtask.pendingSubtasks .at (cid.workID ) = std::move (result);
@@ -797,6 +848,7 @@ class EngineImpl: public ActionExecutorListener {
797
848
}
798
849
799
850
// Insert the task
851
+ st_taskCount++;
800
852
auto taskID = nextTaskID++;
801
853
auto insertion = taskInfos.try_emplace (taskID, taskID, std::move (task));
802
854
auto & taskInfo = (insertion.first )->second ;
@@ -860,12 +912,14 @@ class EngineImpl: public ActionExecutorListener {
860
912
actionCache->get (cacheKey, [this , ctx, inputs, sres, &taskInfo](result<CacheValue, Error> res) {
861
913
if (res.has_error ()) {
862
914
logger->error (logctx, res.error ());
915
+ st_taskCacheMisses++;
863
916
enqueueReadyTask (taskInfo, ctx, inputs, sres);
864
917
return ;
865
918
}
866
919
867
920
if (!res->has_data ()) {
868
921
// not found
922
+ st_taskCacheMisses++;
869
923
enqueueReadyTask (taskInfo, ctx, inputs, sres);
870
924
return ;
871
925
}
@@ -874,6 +928,7 @@ class EngineImpl: public ActionExecutorListener {
874
928
casDB->get (res->data (), [this , ctx, inputs, sres, &taskInfo](result<CASObject, Error> res) {
875
929
if (res.has_error ()) {
876
930
logger->error (logctx, res.error ());
931
+ st_taskCacheMisses++;
877
932
enqueueReadyTask (taskInfo, ctx, inputs, sres);
878
933
return ;
879
934
}
@@ -884,6 +939,7 @@ class EngineImpl: public ActionExecutorListener {
884
939
makeEngineError (EngineError::InternalProtobufSerialization,
885
940
" failed to parse cached task transition" )
886
941
);
942
+ st_taskCacheMisses++;
887
943
enqueueReadyTask (taskInfo, ctx, inputs, sres);
888
944
return ;
889
945
}
@@ -920,11 +976,13 @@ class EngineImpl: public ActionExecutorListener {
920
976
921
977
if (res.has_error ()) {
922
978
logger->error (logctx, res.error ());
979
+ st_taskCacheMisses++;
923
980
enqueueReadyTask (taskInfo, ctx, inputs, sres);
924
981
return ;
925
982
}
926
983
}
927
984
985
+ st_taskCacheHits++;
928
986
processTaskNextState (taskInfo, value.state ());
929
987
});
930
988
});
@@ -1012,6 +1070,7 @@ class EngineImpl: public ActionExecutorListener {
1012
1070
}
1013
1071
1014
1072
void processTaskNextState (TaskInfo& taskInfo, const TaskNextState& next) {
1073
+ st_taskTransitions++;
1015
1074
std::lock_guard<std::mutex> lock (taskInfosMutex);
1016
1075
1017
1076
switch (next.StateValue_case ()) {
@@ -1091,6 +1150,8 @@ class EngineImpl: public ActionExecutorListener {
1091
1150
}
1092
1151
1093
1152
void processFinishedTask (TaskInfo& taskInfo) {
1153
+ st_taskCompletedCount++;
1154
+
1094
1155
// update all tasks waiting on this task
1095
1156
auto work = [this , &taskInfo](const JobContext&) {
1096
1157
std::lock_guard<std::mutex> lock (taskInfosMutex);
@@ -1428,6 +1489,7 @@ class EngineImpl: public ActionExecutorListener {
1428
1489
1429
1490
1430
1491
void sendResult (const result<Artifact, Error>& buildResult) {
1492
+ engine.st_buildCompletedCount ++;
1431
1493
engine.logger ->event (engine.logctx , {
1432
1494
makeStat (" log.message" , " build_completed" ),
1433
1495
makeStat (" build_id" , buildID),
@@ -1567,3 +1629,7 @@ std::shared_ptr<CASDatabase> Engine::cas() {
1567
1629
Build Engine::build (const Label& artifact) {
1568
1630
return static_cast <EngineImpl*>(impl)->build (artifact);
1569
1631
}
1632
+
1633
+ std::vector<Stat> Engine::stats () {
1634
+ return static_cast <EngineImpl*>(impl)->stats ();
1635
+ }
0 commit comments