Skip to content

Commit 13441dc

Browse files
committed
swift/t with flowcept
1 parent 848b877 commit 13441dc

2 files changed

Lines changed: 45 additions & 18 deletions

File tree

wfcommons/wfbench/translator/swift_t.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def translate(self, output_folder: pathlib.Path) -> None:
7777
in_count = 0
7878
self.output_folder = output_folder
7979
self.cpu_benchmark = output_folder.joinpath("./bin/cpu-benchmark").absolute()
80-
self.script = f"string fs = sprintf(flowcept_start, \"{self.workflow.workflow_id}\", \"{self.workflow.name}\");\nstring fss = python_persist(fs);\n\n" if self.workflow.workflow_id else ""
80+
self.script = f"string fs = sprintf(flowcept_start, \"{self.workflow.workflow_id}\");\nstring fss = python_persist(fs);\n\n" if self.workflow.workflow_id else ""
8181
self.script += "string root_in_files[];\n"
8282

8383
for task_name in self.root_task_names:
@@ -103,9 +103,8 @@ def translate(self, output_folder: pathlib.Path) -> None:
103103

104104
# flowcept end
105105
if self.workflow.workflow_id:
106-
self.script += f"int dep_{self.cmd_counter} = {self.last_file};\n" \
107-
f"string fc_stop = sprintf(flowcept_stop, dep_{self.cmd_counter});\n" \
108-
"python_persist(fc_stop);"
106+
self.script += f"string fc = sprintf(flowcept, \"{self.workflow.workflow_id}\", \"{self.workflow.name}\", \"{self.last_file}\");\n" \
107+
"python_persist(fc);\n"
109108

110109
run_workflow_code = self._merge_codelines("templates/swift_t_templates/workflow.swift", self.script)
111110

@@ -169,7 +168,6 @@ def _add_tasks(self, category: str) -> None:
169168
prefix = ""
170169

171170
for file in task.output_files:
172-
out_file = file.file_id
173171
file_size = file.size
174172

175173
for file in task.input_files:
@@ -225,15 +223,14 @@ def _add_tasks(self, category: str) -> None:
225223
f" string of_{self.cmd_counter} = sprintf(\"0%s\", co_{self.cmd_counter});\n" \
226224
f" {category}__out[i] = string2int(of_{self.cmd_counter});\n" \
227225
"}\n\n"
228-
self.last_file = f"{category}__out[{num_tasks - 1}]"
229-
226+
self.last_file = f"{self.output_folder.absolute()}/data/{category}_{num_tasks - 1}_output.txt"
230227
else:
228+
self.last_file = f"{self.output_folder.absolute()}/data/{category}_0_output.txt"
231229
args = args.replace(
232-
", of", f", \"{self.output_folder.absolute()}/data/{category}_0_output.txt\"").replace("[i]", "[0]")
230+
", of", f", \"{self.last_file}\"").replace("[i]", "[0]")
233231
self.script += f"string cmd_{self.cmd_counter} = sprintf(command, \"{self.cpu_benchmark}\", \"{category}\", {args});\n" \
234232
f"string co_{self.cmd_counter} = python_persist(cmd_{self.cmd_counter});\n" \
235233
f"string of_{self.cmd_counter} = sprintf(\"0%s\", co_{self.cmd_counter});\n" \
236234
f"{category}__out[0] = string2int(of_{self.cmd_counter});\n\n"
237-
self.last_file = f"{category}__out[0]"
238235

239236
self.cmd_counter += 1

wfcommons/wfbench/translator/templates/swift_t_templates/workflow.swift

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,55 @@ import python;
44
import string;
55
import unix;
66

7-
global const string flowcept_start =
7+
global const string flowcept_start =
88
"""
9+
import time
910
workflow_id = "%s"
11+
time.sleep(30)
12+
""";
13+
14+
global const string flowcept =
15+
"""
16+
import logging
17+
import os.path
18+
import subprocess
19+
import time
1020
from flowcept.flowcept_api.flowcept_controller import Flowcept
11-
flowcept_agent = Flowcept(workflow_id=workflow_id, workflow_name="%s", bundle_exec_id=workflow_id)
21+
22+
logging.basicConfig(
23+
level=logging.INFO,
24+
format="[WfBench][%%(asctime)s][%%(levelname)s] %%(message)s",
25+
datefmt="%%H:%%M:%%S",
26+
handlers=[logging.StreamHandler()]
27+
)
28+
29+
workflow_id = "%s"
30+
workflow_name = "%s"
31+
file_path = "%s"
32+
33+
logging.info("Flowcept Starting")
34+
flowcept_agent = Flowcept(workflow_id=workflow_id, workflow_name=workflow_name, bundle_exec_id=workflow_id)
1235
1336
try:
1437
flowcept_agent.start()
1538
except Exception:
1639
import traceback
1740
traceback.print_exc()
18-
""";
1941
20-
global const string flowcept_stop =
21-
"""
22-
import time
23-
dep = %i
24-
time.sleep(240)
42+
while not os.path.exists(file_path):
43+
time.sleep(1)
44+
45+
if os.path.isfile(file_path):
46+
time.sleep(240)
47+
try:
48+
flowcept_agent.stop()
49+
except Exception:
50+
import traceback
51+
traceback.print_exc()
52+
else:
53+
raise ValueError(f"{file_path} is not a file!")
54+
55+
logging.info("Flowcept Completed")
2556
""";
2657

2758
string command =
@@ -195,7 +226,6 @@ logging.info(f"Benchmark {task_name} completed!")
195226
if 'workflow_id':
196227
fc_task.end()
197228
fc.stop()
198-
time.sleep(1)
199229
""";
200230

201231
# Generated code goes here

0 commit comments

Comments
 (0)