Skip to content

Commit 71b45e4

Browse files
committed
Record validator metadata.
This can be especially useful when the validator takes more resources than expected or is misbehaving in other ways.
1 parent 9013f12 commit 71b45e4

File tree

7 files changed

+121
-24
lines changed

7 files changed

+121
-24
lines changed

judge/judgedaemon.main.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ function judge(array $judgeTask): bool
14891489
'output_diff' => rest_encode_file($passdir . '/feedback/judgemessage.txt', $output_storage_limit),
14901490
'hostname' => $myhost,
14911491
'testcasedir' => $testcasedir,
1492+
'compare_metadata' => rest_encode_file($passdir . '/compare.meta', false),
14921493
];
14931494

14941495
if (file_exists($passdir . '/feedback/teammessage.txt')) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20250302070928 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return 'Add metadata for the validator.';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('ALTER TABLE judging_run_output ADD validator_metadata LONGBLOB DEFAULT NULL COMMENT \'Judging metadata of the validator(DC2Type:blobtext)\', CHANGE metadata metadata LONGBLOB DEFAULT NULL COMMENT \'Judging metadata of the run(DC2Type:blobtext)\'');
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->addSql('ALTER TABLE judging_run_output DROP validator_metadata, CHANGE metadata metadata LONGBLOB DEFAULT NULL COMMENT \'Judging metadata(DC2Type:blobtext)\'');
30+
}
31+
32+
public function isTransactional(): bool
33+
{
34+
return false;
35+
}
36+
}

webapp/src/Controller/API/JudgehostController.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,12 @@ public function addDebugInfo(
608608
),
609609
new OA\Property(
610610
property: 'metadata',
611-
description: 'The (base64-encoded) metadata',
611+
description: 'The (base64-encoded) metadata of the run',
612+
type: 'string'
613+
),
614+
new OA\Property(
615+
property: 'compare_metadata',
616+
description: 'The (base64-encoded) metadata of the validator',
612617
type: 'string'
613618
),
614619
]
@@ -647,14 +652,15 @@ public function addJudgingRunAction(
647652
$teamMessage = $request->request->get('team_message');
648653
$metadata = $request->request->get('metadata');
649654
$testcasedir = $request->request->get('testcasedir');
655+
$compareMeta = $request->request->get('compare_metadata');
650656

651657
$judgehost = $this->em->getRepository(Judgehost::class)->findOneBy(['hostname' => $hostname]);
652658
if (!$judgehost) {
653659
throw new BadRequestHttpException("Who are you and why are you sending us any data?");
654660
}
655661

656662
$hasFinalResult = $this->addSingleJudgingRun($judgeTaskId, $hostname, $runResult, $runTime,
657-
$outputSystem, $outputError, $outputDiff, $outputRun, $teamMessage, $metadata, $testcasedir);
663+
$outputSystem, $outputError, $outputDiff, $outputRun, $teamMessage, $metadata, $testcasedir, $compareMeta);
658664
$judgehost = $this->em->getRepository(Judgehost::class)->findOneBy(['hostname' => $hostname]);
659665
$judgehost->setPolltime(Utils::now());
660666
$this->em->flush();
@@ -910,16 +916,17 @@ protected function giveBackJudging(int $judgingId, ?Judgehost $judgehost): void
910916
*/
911917
private function addSingleJudgingRun(
912918
int $judgeTaskId,
913-
string $hostname,
914-
string $runResult,
915-
string $runTime,
916-
string $outputSystem,
917-
string $outputError,
918-
string $outputDiff,
919-
string $outputRun,
919+
string $hostname,
920+
string $runResult,
921+
string $runTime,
922+
string $outputSystem,
923+
string $outputError,
924+
string $outputDiff,
925+
string $outputRun,
920926
?string $teamMessage,
921-
string $metadata,
922-
?string $testcasedir
927+
string $metadata,
928+
?string $testcasedir,
929+
?string $compareMeta,
923930
): bool {
924931
$resultsRemap = $this->config->get('results_remap');
925932
$resultsPrio = $this->config->get('results_prio');
@@ -940,7 +947,8 @@ private function addSingleJudgingRun(
940947
$outputRun,
941948
$teamMessage,
942949
$metadata,
943-
$testcasedir
950+
$testcasedir,
951+
$compareMeta
944952
) {
945953
$judgingRun = $this->em->getRepository(JudgingRun::class)->findOneBy(
946954
['judgetaskid' => $judgeTaskId]);
@@ -962,6 +970,10 @@ private function addSingleJudgingRun(
962970
->setOutputSystem(base64_decode($outputSystem))
963971
->setMetadata(base64_decode($metadata));
964972

973+
if ($compareMeta) {
974+
$judgingRunOutput->setValidatorMetadata(base64_decode($compareMeta));
975+
}
976+
965977
if ($teamMessage) {
966978
$judgingRunOutput->setTeamMessage(base64_decode($teamMessage));
967979
}

webapp/src/Controller/Jury/SubmissionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function viewAction(
383383
->join('t.content', 'tc')
384384
->leftJoin('t.judging_runs', 'jr', Join::WITH, 'jr.judging = :judging')
385385
->leftJoin('jr.output', 'jro')
386-
->select('t', 'jr', 'tc.image_thumb AS image_thumb', 'jro.metadata')
386+
->select('t', 'jr', 'tc.image_thumb AS image_thumb', 'jro.metadata', 'jro.validatorMetadata')
387387
->andWhere('t.problem = :problem')
388388
->setParameter('judging', $selectedJudging)
389389
->setParameter('problem', $submission->getProblem())

webapp/src/Entity/JudgingRunOutput.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,17 @@ class JudgingRunOutput
6464
#[ORM\Column(
6565
type: 'blobtext',
6666
nullable: true,
67-
options: ['comment' => 'Judging metadata']
67+
options: ['comment' => 'Judging metadata of the run']
6868
)]
6969
private ?string $metadata = null;
7070

71+
#[ORM\Column(
72+
type: 'blobtext',
73+
nullable: true,
74+
options: ['comment' => 'Judging metadata of the validator']
75+
)]
76+
private ?string $validatorMetadata = null;
77+
7178
public function setRun(JudgingRun $run): JudgingRunOutput
7279
{
7380
$this->run = $run;
@@ -144,4 +151,15 @@ public function setMetadata(?string $metadata): self
144151
$this->metadata = $metadata;
145152
return $this;
146153
}
154+
155+
public function getValidatorMetadata(): string
156+
{
157+
return $this->validatorMetadata;
158+
}
159+
160+
public function setValidatorMetadata(?string $validatorMetadata): self
161+
{
162+
$this->validatorMetadata = $validatorMetadata;
163+
return $this;
164+
}
147165
}

webapp/src/Twig/TwigExtension.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,16 +1228,31 @@ public function printMetadata(?string $metadata): string
12281228
return '';
12291229
}
12301230
$metadata = Utils::parseMetadata($metadata);
1231-
return '<span style="display:inline; margin-left: 5px;">'
1232-
. '<i class="fas fa-stopwatch" title="runtime"></i> '
1233-
. $metadata['cpu-time'] . 's CPU, '
1234-
. $metadata['wall-time'] . 's wall, '
1235-
. '<i class="fas fa-memory" title="RAM"></i> '
1236-
. Utils::printsize((int)($metadata['memory-bytes'])) . ', '
1237-
. '<i class="far fa-question-circle" title="exit-status"></i> '
1238-
. 'exit-code: ' . $metadata['exitcode']
1239-
. (($metadata['signal'] ?? -1) > 0 ? ' signal: ' . $metadata['signal'] : '')
1240-
. '</span>';
1231+
$result = '<span style="display:inline; margin-left: 5px;">';
1232+
1233+
if (isset($metadata['cpu-time']) || isset($metadata['wall-time'])) {
1234+
$result .= '<i class="fas fa-stopwatch" title="runtime"></i> ';
1235+
}
1236+
1237+
if (isset($metadata['cpu-time'])) {
1238+
$result .= $metadata['cpu-time'] . 's CPU, ';
1239+
}
1240+
if (isset($metadata['wall-time'])) {
1241+
$result .= $metadata['wall-time'] . 's wall, ';
1242+
}
1243+
if (isset($metadata['memory-bytes'])) {
1244+
$result .= '<i class="fas fa-memory" title="RAM"></i> '
1245+
. Utils::printsize((int)($metadata['memory-bytes'])) . ', ';
1246+
}
1247+
if (isset($metadata['exitcode'])) {
1248+
$result .= '<i class="far fa-question-circle" title="exit-status"></i> '
1249+
. 'exit-code: ' . $metadata['exitcode'];
1250+
}
1251+
if (isset($metadata['signal'])) {
1252+
$result .= ' signal: ' . $metadata['signal'];
1253+
}
1254+
$result .= '</span>';
1255+
return $result;
12411256
}
12421257

12431258
public function printWarningContent(ExternalSourceWarning $warning): string

webapp/templates/jury/submission.html.twig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,21 @@
822822
{{ runsOutput[runIdx].team_message }}</pre>
823823
{% endif %}
824824
{% endif %}
825+
826+
{% if runsOutput[runIdx].validatorMetadata is not empty %}
827+
<hr/>
828+
<h5>Validator metadata</h5>
829+
{{ runsOutput[runIdx].validatorMetadata | printMetadata }}
830+
<button class="btn btn-sm btn-outline-secondary" data-bs-toggle="collapse"
831+
data-bs-target="#collapseValMeta-{{ runIdx }}"
832+
aria-expanded="false">
833+
show complete validator metadata
834+
</button>
835+
<div class="collapse" id="collapseValMeta-{{ runIdx }}">
836+
<div class="card card-body output_text">{{ runsOutput[runIdx].validatorMetadata }}</div>
837+
</div>
838+
839+
{% endif %}
825840
{% endif %}
826841
827842
</div>

0 commit comments

Comments
 (0)