Skip to content

Commit de51bbf

Browse files
committed
wip
1 parent 0e51cf5 commit de51bbf

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

src/kernelbot/discord_reporter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import discord
2-
from discord_utils import _send_split_log
2+
from discord_utils import _send_split_log, _send_file
33

44
from libkernelbot.report import (
5+
File,
56
Link,
67
Log,
78
MultiProgressReporter,
@@ -70,6 +71,11 @@ async def display_report(self, title: str, report: RunResultReport):
7071
message += part.text
7172
elif isinstance(part, Log):
7273
message = await _send_split_log(thread, message, part.header, part.content)
74+
elif isinstance(part, File):
75+
if len(message) > 0:
76+
await thread.send(message)
77+
await _send_file(thread, part.message, part.name, part.content)
78+
message = ""
7379
elif isinstance(part, Link):
7480
if len(message) > 0:
7581
await thread.send(message)

src/kernelbot/discord_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import logging
3+
from io import BytesIO
34

45
import discord
56

@@ -136,3 +137,7 @@ async def _send_split_log(thread: discord.Thread, partial_message: str, header:
136137
await thread.send(partial_message)
137138

138139
return ""
140+
141+
142+
async def _send_file(thread: discord.Thread, message: str, name: str, file: bytes):
143+
await thread.send(message, file=discord.File(BytesIO(file), filename=name))

src/libkernelbot/launchers/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def run_submission( # noqa: C901
143143
# Update profile artifact to the actual download URL.
144144
# For the GitHub launcher the profile_artifact currently just contains
145145
# the name of the artifact.
146-
if profile_res is not None:
146+
if profile_res is not None and "profile-data" in index:
147147
profile_res.download_url = index["profile-data"].public_download_url
148148

149149
res = EvalResult(

src/libkernelbot/report.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,19 @@ class Link:
4343
url: str
4444

4545

46+
@dataclasses.dataclass
47+
class File:
48+
"""
49+
Link represents a file that gets attached to the report.
50+
"""
51+
name: str
52+
message: str
53+
content: bytes
54+
55+
4656
class RunResultReport:
4757
def __init__(self, data=None):
48-
self.data: List[Text | Log | Link] = data or []
58+
self.data: List[Text | Log | Link | File] = data or []
4959

5060
def add_text(self, section: str):
5161
self.data.append(Text(section))
@@ -56,6 +66,9 @@ def add_log(self, header: str, log: str):
5666
def add_link(self, title: str, text: str, url: str):
5767
self.data.append(Link(title, text, url))
5868

69+
def add_file(self, name: str, message: str, content: bytes):
70+
self.data.append(File(name, message, content))
71+
5972
def __repr__(self):
6073
return f"RunResultReport(data={self.data})"
6174

@@ -340,12 +353,20 @@ def generate_report(result: FullResult) -> RunResultReport: # noqa: C901
340353
make_profile_log(prof_run.run),
341354
)
342355

343-
if prof_run.profile is not None and prof_run.profile.download_url is not None:
344-
report.add_link(
345-
f"{prof_run.profile.profiler} profiling output",
346-
"Download from GitHub",
347-
prof_run.profile.download_url,
348-
)
356+
for prof_run in profile_runs:
357+
if prof_run.profile is not None:
358+
if prof_run.profile.trace is not None:
359+
report.add_file(
360+
"profile.zip",
361+
f"{prof_run.profile.profiler} profiling output",
362+
base64.b64decode(prof_run.profile.trace),
363+
)
364+
elif prof_run.profile.download_url is not None:
365+
report.add_link(
366+
f"{prof_run.profile.profiler} profiling output",
367+
"Download from GitHub",
368+
prof_run.profile.download_url,
369+
)
349370

350371
if "leaderboard" in runs:
351372
bench_run = runs["leaderboard"]

src/libkernelbot/run_eval.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ def _create_files(files: Optional[dict[str, str]]):
130130
def _directory_to_zip_bytes(directory_path) -> str:
131131
"""Create a zip archive and return as bas64 encoded bytes."""
132132
with tempfile.NamedTemporaryFile() as archive_path:
133+
print(directory_path)
134+
print(archive_path.name)
133135
shutil.make_archive(archive_path.name, 'zip', directory_path)
134136
data = archive_path.read()
137+
print(len(data))
135138
return base64.b64encode(data).decode('utf-8')
136139

137140

@@ -416,6 +419,7 @@ def profile_program_ncu(
416419

417420
profile_result = None
418421

422+
print(list(output_dir.glob("*")))
419423
if run_result.success:
420424
profile_result = ProfileResult(
421425
profiler='Nsight-Compute',

0 commit comments

Comments
 (0)