Skip to content

Commit

Permalink
Record validator metadata.
Browse files Browse the repository at this point in the history
This can be especially useful when the validator takes more resources
than expected or is misbehaving in other ways.
  • Loading branch information
meisterT committed Mar 2, 2025
1 parent 9013f12 commit d5425d2
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 16 deletions.
1 change: 1 addition & 0 deletions judge/judgedaemon.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ function judge(array $judgeTask): bool
'output_diff' => rest_encode_file($passdir . '/feedback/judgemessage.txt', $output_storage_limit),
'hostname' => $myhost,
'testcasedir' => $testcasedir,
'compare_metadata' => rest_encode_file($passdir . '/compare.meta', false),
];

if (file_exists($passdir . '/feedback/teammessage.txt')) {
Expand Down
36 changes: 36 additions & 0 deletions webapp/migrations/Version20250302070928.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250302070928 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add metadata for the validator.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$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)\'');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE judging_run_output DROP validator_metadata, CHANGE metadata metadata LONGBLOB DEFAULT NULL COMMENT \'Judging metadata(DC2Type:blobtext)\'');
}

public function isTransactional(): bool
{
return false;
}
}
20 changes: 16 additions & 4 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,12 @@ public function addDebugInfo(
),
new OA\Property(
property: 'metadata',
description: 'The (base64-encoded) metadata',
description: 'The (base64-encoded) metadata of the run',
type: 'string'
),
new OA\Property(
property: 'compare_metadata',
description: 'The (base64-encoded) metadata of the validator',
type: 'string'
),
]
Expand Down Expand Up @@ -647,14 +652,15 @@ public function addJudgingRunAction(
$teamMessage = $request->request->get('team_message');
$metadata = $request->request->get('metadata');
$testcasedir = $request->request->get('testcasedir');
$compare_meta = $request->request->get('compare_metadata');

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

$hasFinalResult = $this->addSingleJudgingRun($judgeTaskId, $hostname, $runResult, $runTime,
$outputSystem, $outputError, $outputDiff, $outputRun, $teamMessage, $metadata, $testcasedir);
$outputSystem, $outputError, $outputDiff, $outputRun, $teamMessage, $metadata, $testcasedir, $compare_meta);
$judgehost = $this->em->getRepository(Judgehost::class)->findOneBy(['hostname' => $hostname]);
$judgehost->setPolltime(Utils::now());
$this->em->flush();
Expand Down Expand Up @@ -919,7 +925,8 @@ private function addSingleJudgingRun(
string $outputRun,
?string $teamMessage,
string $metadata,
?string $testcasedir
?string $testcasedir,
?string $compare_meta,
): bool {
$resultsRemap = $this->config->get('results_remap');
$resultsPrio = $this->config->get('results_prio');
Expand All @@ -940,7 +947,8 @@ private function addSingleJudgingRun(
$outputRun,
$teamMessage,
$metadata,
$testcasedir
$testcasedir,
$compare_meta
) {
$judgingRun = $this->em->getRepository(JudgingRun::class)->findOneBy(
['judgetaskid' => $judgeTaskId]);
Expand All @@ -962,6 +970,10 @@ private function addSingleJudgingRun(
->setOutputSystem(base64_decode($outputSystem))
->setMetadata(base64_decode($metadata));

if ($compare_meta) {
$judgingRunOutput->setValidatorMetadata(base64_decode($compare_meta));
}

if ($teamMessage) {
$judgingRunOutput->setTeamMessage(base64_decode($teamMessage));
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public function viewAction(
->join('t.content', 'tc')
->leftJoin('t.judging_runs', 'jr', Join::WITH, 'jr.judging = :judging')
->leftJoin('jr.output', 'jro')
->select('t', 'jr', 'tc.image_thumb AS image_thumb', 'jro.metadata')
->select('t', 'jr', 'tc.image_thumb AS image_thumb', 'jro.metadata', 'jro.validatorMetadata')
->andWhere('t.problem = :problem')
->setParameter('judging', $selectedJudging)
->setParameter('problem', $submission->getProblem())
Expand Down
20 changes: 19 additions & 1 deletion webapp/src/Entity/JudgingRunOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ class JudgingRunOutput
#[ORM\Column(
type: 'blobtext',
nullable: true,
options: ['comment' => 'Judging metadata']
options: ['comment' => 'Judging metadata of the run']
)]
private ?string $metadata = null;

#[ORM\Column(
type: 'blobtext',
nullable: true,
options: ['comment' => 'Judging metadata of the validator']
)]
private ?string $validatorMetadata = null;

public function setRun(JudgingRun $run): JudgingRunOutput
{
$this->run = $run;
Expand Down Expand Up @@ -144,4 +151,15 @@ public function setMetadata(?string $metadata): self
$this->metadata = $metadata;
return $this;
}

public function getValidatorMetadata(): string
{
return $this->validatorMetadata;
}

public function setValidatorMetadata(?string $validatorMetadata): self
{
$this->validatorMetadata = $validatorMetadata;
return $this;
}
}
32 changes: 22 additions & 10 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,16 +1228,28 @@ public function printMetadata(?string $metadata): string
return '';
}
$metadata = Utils::parseMetadata($metadata);
return '<span style="display:inline; margin-left: 5px;">'
. '<i class="fas fa-stopwatch" title="runtime"></i> '
. $metadata['cpu-time'] . 's CPU, '
. $metadata['wall-time'] . 's wall, '
. '<i class="fas fa-memory" title="RAM"></i> '
. Utils::printsize((int)($metadata['memory-bytes'])) . ', '
. '<i class="far fa-question-circle" title="exit-status"></i> '
. 'exit-code: ' . $metadata['exitcode']
. (($metadata['signal'] ?? -1) > 0 ? ' signal: ' . $metadata['signal'] : '')
. '</span>';
$result = '<span style="display:inline; margin-left: 5px;">'
. '<i class="fas fa-stopwatch" title="runtime"></i> ';

if (isset($metadata['cpu-time'])) {
$result .= $metadata['cpu-time'] . 's CPU, ';
}
if (isset($metadata['wall-time'])) {
$result .= $metadata['wall-time'] . 's wall, ';
}
if (isset($metadata['memory-bytes'])) {
$result .= '<i class="fas fa-memory" title="RAM"></i> '
. Utils::printsize((int)($metadata['memory-bytes'])) . ', ';
}
if (isset($metadata['exitcode'])) {
$result .= '<i class="far fa-question-circle" title="exit-status"></i> '
. 'exit-code: ' . $metadata['exitcode'];
}
if (isset($metadata['signal'])) {
$result .= ' signal: ' . $metadata['signal'];
}
$result .= '</span>';
return $result;
}

public function printWarningContent(ExternalSourceWarning $warning): string
Expand Down
15 changes: 15 additions & 0 deletions webapp/templates/jury/submission.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,21 @@
{{ runsOutput[runIdx].team_message }}</pre>
{% endif %}
{% endif %}
{% if runsOutput[runIdx].validatorMetadata is not empty %}
<hr/>
<h5>Validator metadata</h5>
{{ runsOutput[runIdx].validatorMetadata | printMetadata }}
<button class="btn btn-sm btn-outline-secondary" data-bs-toggle="collapse"
data-bs-target="#collapseValMeta-{{ runIdx }}"
aria-expanded="false">
show complete validator metadata
</button>
<div class="collapse" id="collapseValMeta-{{ runIdx }}">
<div class="card card-body output_text">{{ runsOutput[runIdx].validatorMetadata }}</div>
</div>
{% endif %}
{% endif %}
</div>
Expand Down

0 comments on commit d5425d2

Please sign in to comment.