Skip to content

Commit d38d4ca

Browse files
committed
Finish refactor
1 parent 209c580 commit d38d4ca

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

status_manager.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44

55
namespace tsp
66
{
7-
Status_Manager::Status_Manager(Run_cmd cmd, uint32_t slots) : jobid(gen_jobid()), qtime(std::chrono::system_clock::now()), stime(), etime()
7+
Status_Manager::Status_Manager() : jobid(gen_jobid()), qtime(std::chrono::system_clock::now()), stime(), etime()
88
{
99
std::string stat_fn(get_tmp());
1010
stat_fn.append(STATUS_FILE_TEMPLATE);
1111
stat_fn.append(jobid);
1212
stat_file.open(stat_fn);
13-
stat_file << "Command: " << cmd.print() << std::endl;
14-
stat_file << "Slots required: " << std::to_string(slots) << std::endl;
1513
stat_file << "Enqueue time: " << time_writer(qtime) << std::endl;
1614
}
1715
Status_Manager::~Status_Manager()
1816
{
1917
stat_file.close();
2018
}
2119

20+
void Status_Manager::add_cmd(Run_cmd cmd, uint32_t slots)
21+
{
22+
stat_file << "Command: " << cmd.print() << std::endl;
23+
stat_file << "Slots required: " << std::to_string(slots) << std::endl;
24+
}
25+
2226
void Status_Manager::job_start()
2327
{
2428
stime = std::chrono::system_clock::now();

status_manager.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ namespace tsp
1717
public:
1818
const std::string jobid;
1919
std::ofstream stat_file;
20-
Status_Manager(Run_cmd cmd, uint32_t slots);
20+
Status_Manager();
2121
~Status_Manager();
22+
void add_cmd(Run_cmd cmd, uint32_t slots);
2223
void job_start();
2324
void job_end(int exit_stat);
2425

tsp.cpp

+6-19
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,14 @@
2222

2323
int main(int argc, char *argv[])
2424
{
25-
tsp::Semaphore_File *sf = new tsp::Semaphore_File();
26-
// Parse args: only take the ones we use for now
25+
tsp::Status_Manager stat;
2726
int c;
2827
uint32_t nslots = 1;
2928
bool disappear_output = false;
3029
bool do_fork = true;
3130
bool separate_stderr = false;
3231

33-
if (argc == 1)
34-
{
35-
// List all jobs we're aware of
36-
std::cout << "ID State Output E-Level Time Command" << std::endl;
37-
for (const auto &entry : std::filesystem::directory_iterator(get_tmp()))
38-
{
39-
if (entry.path().filename().string().find(STATUS_FILE_TEMPLATE) != std::string::npos)
40-
{
41-
std::ifstream stat_file(entry.path());
42-
43-
}
44-
}
45-
}
46-
32+
// Parse args: only take the ones we use for now
4733
while ((c = getopt(argc, argv, "+nfN:E")) != -1)
4834
{
4935
switch (c)
@@ -64,6 +50,9 @@ int main(int argc, char *argv[])
6450
}
6551
}
6652

53+
tsp::Run_cmd cmd(argv, optind, argc);
54+
stat.add_cmd(cmd,nslots);
55+
6756
if (do_fork)
6857
{
6958
pid_t main_fork_pid;
@@ -83,8 +72,6 @@ int main(int argc, char *argv[])
8372
std::chrono::duration sleep(std::chrono::milliseconds(JITTER_MS + jitter.get()));
8473
std::this_thread::sleep_for(sleep);
8574

86-
tsp::Run_cmd cmd(argv, optind, argc);
87-
tsp::Status_Manager stat(cmd, nslots);
8875
tsp::Tsp_Proc me(nslots);
8976

9077
cpu_set_t mask;
@@ -96,7 +83,7 @@ int main(int argc, char *argv[])
9683
me.refresh_allowed_cores();
9784
}
9885
stat.job_start();
99-
delete sf;
86+
//delete sf;
10087
for (uint32_t i = 0; i < nslots; i++)
10188
{
10289
CPU_SET(me.allowed_cores[i], &mask);

0 commit comments

Comments
 (0)