Skip to content

Commit 5753b1c

Browse files
committed
Add log timestamps
1 parent db69d3f commit 5753b1c

File tree

6 files changed

+46
-36
lines changed

6 files changed

+46
-36
lines changed

include/chia/phase1.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void compute_f1(const uint8_t* id, int num_threads, DS* T1_sort)
281281
output.close();
282282
T1_sort->finish();
283283

284-
std::cout << "[P1] Table 1 took " << (get_wall_time_micros() - begin) / 1e6 << " sec" << std::endl;
284+
std::cout << get_curr_datetime() << " [P1] Table 1 took " << (get_wall_time_micros() - begin) / 1e6 << " sec" << std::endl;
285285
}
286286

287287
template<typename T, typename S, typename R, typename DS_L, typename DS_R>
@@ -400,7 +400,7 @@ uint64_t compute_matches( int R_index, int num_threads,
400400
R_sort->finish();
401401
}
402402
if(num_written < num_found) {
403-
// std::cout << "[P1] Lost " << num_found - num_written
403+
// std::cout << get_curr_datetime() << " [P1] Lost " << num_found - num_written
404404
// << " matches due to 32-bit overflow." << std::endl;
405405
}
406406
return num_written;
@@ -443,7 +443,7 @@ uint64_t compute_table( int R_index, int num_threads,
443443
if(R_tmp) {
444444
R_tmp->close();
445445
}
446-
std::cout << "[P1] Table " << R_index << " took " << (get_wall_time_micros() - begin) / 1e6 << " sec"
446+
std::cout << get_curr_datetime() << " [P1] Table " << R_index << " took " << (get_wall_time_micros() - begin) / 1e6 << " sec"
447447
<< ", found " << num_matches << " matches" << std::endl;
448448
return num_matches;
449449
}
@@ -504,7 +504,7 @@ void compute( const input_t& input, output_t& out,
504504
out.table[5] = tmp_6.get_info();
505505
out.table[6] = tmp_7.get_info();
506506

507-
std::cout << "Phase 1 took " << (get_wall_time_micros() - total_begin) / 1e6 << " sec" << std::endl;
507+
std::cout << get_curr_datetime() << " Phase 1 took " << (get_wall_time_micros() - total_begin) / 1e6 << " sec" << std::endl;
508508
}
509509

510510

include/chia/phase2.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void compute_table( int R_index, int num_threads,
4646
R_input.read(&pool, num_threads_read);
4747
pool.close();
4848

49-
std::cout << "[P2] Table " << R_index << " scan took "
49+
std::cout << get_curr_datetime() << " [P2] Table " << R_index << " scan took "
5050
<< (get_wall_time_micros() - begin) / 1e6 << " sec" << std::endl;
5151
}
5252
const auto begin = get_wall_time_micros();
@@ -116,7 +116,7 @@ void compute_table( int R_index, int num_threads,
116116
if(R_file) {
117117
R_file->flush();
118118
}
119-
std::cout << "[P2] Table " << R_index << " rewrite took "
119+
std::cout << get_curr_datetime() << " [P2] Table " << R_index << " rewrite took "
120120
<< (get_wall_time_micros() - begin) / 1e6 << " sec"
121121
<< ", dropped " << R_table.num_entries - num_written << " entries"
122122
<< " (" << 100 * (1 - double(num_written) / R_table.num_entries) << " %)" << std::endl;
@@ -138,7 +138,7 @@ void compute( const phase1::output_t& input, output_t& out,
138138
for(const auto& table : input.table) {
139139
max_table_size = std::max(max_table_size, table.num_entries);
140140
}
141-
std::cout << "[P2] max_table_size = " << max_table_size << std::endl;
141+
std::cout << get_curr_datetime() << " [P2] max_table_size = " << max_table_size << std::endl;
142142

143143
auto curr_bitfield = std::make_shared<bitfield>(max_table_size);
144144
auto next_bitfield = std::make_shared<bitfield>(max_table_size);
@@ -167,7 +167,7 @@ void compute( const phase1::output_t& input, output_t& out,
167167
out.table_7 = table_7.get_info();
168168
out.bitfield_1 = next_bitfield;
169169

170-
std::cout << "Phase 2 took " << (get_wall_time_micros() - total_begin) / 1e6 << " sec" << std::endl;
170+
std::cout << get_curr_datetime() << " Phase 2 took " << (get_wall_time_micros() - total_begin) / 1e6 << " sec" << std::endl;
171171
}
172172

173173

include/chia/phase3.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void compute_stage1(int L_index, int num_threads,
195195

196196
R_sort_2->finish();
197197

198-
std::cout << "[P3-1] Table " << L_index + 1 << " took "
198+
std::cout << get_curr_datetime() << " [P3-1] Table " << L_index + 1 << " took "
199199
<< (get_wall_time_micros() - begin) / 1e6 << " sec"
200200
<< ", wrote " << R_num_write << " right entries" << std::endl;
201201
}
@@ -261,7 +261,7 @@ uint32_t WriteHeader(
261261
num_bytes += fwrite((pointers), 8, 10, file) * 8;
262262

263263
fflush(file);
264-
std::cout << "Wrote plot header with " << num_bytes << " bytes" << std::endl;
264+
std::cout << get_curr_datetime() << " Wrote plot header with " << num_bytes << " bytes" << std::endl;
265265
return num_bytes;
266266
}
267267

@@ -460,9 +460,9 @@ uint64_t compute_stage2(int L_index, int num_threads,
460460
Encoding::ANSFree(kRValues[L_index - 1]);
461461

462462
if(L_num_write < R_num_read) {
463-
// std::cout << "[P3-2] Lost " << R_num_read - L_num_write << " entries due to 32-bit overflow." << std::endl;
463+
// std::cout << get_curr_datetime() << " [P3-2] Lost " << R_num_read - L_num_write << " entries due to 32-bit overflow." << std::endl;
464464
}
465-
std::cout << "[P3-2] Table " << L_index + 1 << " took "
465+
std::cout << get_curr_datetime() << " [P3-2] Table " << L_index + 1 << " took "
466466
<< (get_wall_time_micros() - begin) / 1e6 << " sec"
467467
<< ", wrote " << L_num_write << " left entries"
468468
<< ", " << num_written_final << " final" << std::endl;
@@ -559,7 +559,7 @@ void compute( phase2::output_t& input, output_t& out,
559559
out.num_written_7 = num_written_final_7;
560560
out.final_pointer_7 = final_pointers[7];
561561

562-
std::cout << "Phase 3 took " << (get_wall_time_micros() - total_begin) / 1e6 << " sec"
562+
std::cout << get_curr_datetime() << " Phase 3 took " << (get_wall_time_micros() - total_begin) / 1e6 << " sec"
563563
", wrote " << num_written_final << " entries to final plot" << std::endl;
564564
}
565565

include/chia/phase4.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ uint64_t compute( FILE* plot_file, const int header_size,
7979

8080
std::vector<uint32_t> C2;
8181

82-
std::cout << "[P4] Starting to write C1 and C3 tables" << std::endl;
82+
std::cout << get_curr_datetime() << " [P4] Starting to write C1 and C3 tables" << std::endl;
8383

8484
struct park_deltas_t {
8585
uint64_t offset = 0;
@@ -215,8 +215,8 @@ uint64_t compute( FILE* plot_file, const int header_size,
215215
final_file_writer_1 +=
216216
fwrite_at(plot_file, final_file_writer_1, C1_entry_buf, sizeof(C1_entry_buf));
217217

218-
std::cout << "[P4] Finished writing C1 and C3 tables" << std::endl;
219-
std::cout << "[P4] Writing C2 table" << std::endl;
218+
std::cout << get_curr_datetime() << " [P4] Finished writing C1 and C3 tables" << std::endl;
219+
std::cout << get_curr_datetime() << " [P4] Writing C2 table" << std::endl;
220220

221221
for(const uint64_t C2_entry : C2) {
222222
Bits(C2_entry, k).ToBytes(C1_entry_buf);
@@ -227,7 +227,7 @@ uint64_t compute( FILE* plot_file, const int header_size,
227227
final_file_writer_1 +=
228228
fwrite_at(plot_file, final_file_writer_1, C1_entry_buf, sizeof(C1_entry_buf));
229229

230-
std::cout << "[P4] Finished writing C2 table" << std::endl;
230+
std::cout << get_curr_datetime() << " [P4] Finished writing C2 table" << std::endl;
231231

232232
final_file_writer_1 = header_size - 8 * 3;
233233
uint8_t table_pointer_bytes[8] = {};
@@ -265,7 +265,7 @@ void compute( const phase3::output_t& input, output_t& out,
265265

266266
std::rename(input.plot_file_name.c_str(), out.plot_file_name.c_str());
267267

268-
std::cout << "Phase 4 took " << (get_wall_time_micros() - total_begin) / 1e6 << " sec"
268+
std::cout << get_curr_datetime() << " Phase 4 took " << (get_wall_time_micros() - total_begin) / 1e6 << " sec"
269269
", final plot size is " << out.plot_size << " bytes" << std::endl;
270270
}
271271

include/chia/util.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,16 @@ namespace Util {
375375
}
376376
}
377377

378+
inline
379+
std::string get_curr_datetime()
380+
{
381+
time_t now;
382+
time(&now);
383+
char buf[sizeof "YYYY-MM-ddTHH:mm:ssZ"];
384+
strftime(buf, sizeof buf, "%FT%TZ", gmtime(&now));
385+
return std::string( buf );
386+
}
387+
378388
inline
379389
int64_t get_wall_time_micros() {
380390
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();

src/chia_plot.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,27 @@ phase4::output_t create_plot( const int num_threads,
6262
{
6363
const auto total_begin = get_wall_time_micros();
6464

65-
std::cout << "Process ID: " << GETPID() << std::endl;
66-
std::cout << "Number of Threads: " << num_threads << std::endl;
67-
std::cout << "Number of Buckets: 2^" << log_num_buckets
65+
std::cout << get_curr_datetime() << " Process ID: " << GETPID() << std::endl;
66+
std::cout << get_curr_datetime() << " Number of Threads: " << num_threads << std::endl;
67+
std::cout << get_curr_datetime() << " Number of Buckets: 2^" << log_num_buckets
6868
<< " (" << (1 << log_num_buckets) << ")" << std::endl;
6969

7070
bls::G1Element pool_key;
7171
bls::G1Element farmer_key;
7272
try {
7373
pool_key = bls::G1Element::FromByteVector(pool_key_bytes);
7474
} catch(std::exception& ex) {
75-
std::cout << "Invalid poolkey: " << bls::Util::HexStr(pool_key_bytes) << std::endl;
75+
std::cout << get_curr_datetime() << " Invalid poolkey: " << bls::Util::HexStr(pool_key_bytes) << std::endl;
7676
throw;
7777
}
7878
try {
7979
farmer_key = bls::G1Element::FromByteVector(farmer_key_bytes);
8080
} catch(std::exception& ex) {
81-
std::cout << "Invalid farmerkey: " << bls::Util::HexStr(farmer_key_bytes) << std::endl;
81+
std::cout << get_curr_datetime() << " Invalid farmerkey: " << bls::Util::HexStr(farmer_key_bytes) << std::endl;
8282
throw;
8383
}
84-
std::cout << "Pool Public Key: " << bls::Util::HexStr(pool_key.Serialize()) << std::endl;
85-
std::cout << "Farmer Public Key: " << bls::Util::HexStr(farmer_key.Serialize()) << std::endl;
84+
std::cout << get_curr_datetime() << " Pool Public Key: " << bls::Util::HexStr(pool_key.Serialize()) << std::endl;
85+
std::cout << get_curr_datetime() << " Farmer Public Key: " << bls::Util::HexStr(farmer_key.Serialize()) << std::endl;
8686

8787
vector<uint8_t> seed(32);
8888
randombytes_buf(seed.data(), seed.size());
@@ -109,9 +109,9 @@ phase4::output_t create_plot( const int num_threads,
109109
const std::string plot_name = "plot-k32-" + get_date_string_ex("%Y-%m-%d-%H-%M")
110110
+ "-" + bls::Util::HexStr(params.id.data(), params.id.size());
111111

112-
std::cout << "Working Directory: " << (tmp_dir.empty() ? "$PWD" : tmp_dir) << std::endl;
113-
std::cout << "Working Directory 2: " << (tmp_dir_2.empty() ? "$PWD" : tmp_dir_2) << std::endl;
114-
std::cout << "Plot Name: " << plot_name << std::endl;
112+
std::cout << get_curr_datetime() << " Working Directory: " << (tmp_dir.empty() ? "$PWD" : tmp_dir) << std::endl;
113+
std::cout << get_curr_datetime() << " Working Directory 2: " << (tmp_dir_2.empty() ? "$PWD" : tmp_dir_2) << std::endl;
114+
std::cout << get_curr_datetime() << " Plot Name: " << plot_name << std::endl;
115115

116116
// memo = bytes(pool_public_key) + bytes(farmer_public_key) + bytes(local_master_sk)
117117
params.memo.insert(params.memo.end(), pool_key_bytes.begin(), pool_key_bytes.end());
@@ -135,7 +135,7 @@ phase4::output_t create_plot( const int num_threads,
135135
phase4::compute(out_3, out_4, num_threads, log_num_buckets, plot_name, tmp_dir, tmp_dir_2);
136136

137137
const auto time_secs = (get_wall_time_micros() - total_begin) / 1e6;
138-
std::cout << "Total plot creation time was "
138+
std::cout << get_curr_datetime() << " Total plot creation time was "
139139
<< time_secs << " sec (" << time_secs / 60. << " min)" << std::endl;
140140
return out_4;
141141
}
@@ -312,11 +312,11 @@ int main(int argc, char** argv)
312312
std::cout << " - " << GIT_COMMIT_HASH;
313313
#endif
314314
std::cout << std::endl;
315-
std::cout << "Final Directory: " << final_dir << std::endl;
315+
std::cout << get_curr_datetime() << " Final Directory: " << final_dir << std::endl;
316316
if(num_plots >= 0) {
317-
std::cout << "Number of Plots: " << num_plots << std::endl;
317+
std::cout << get_curr_datetime() << " Number of Plots: " << num_plots << std::endl;
318318
} else {
319-
std::cout << "Number of Plots: infinite" << std::endl;
319+
std::cout << get_curr_datetime() << " Number of Plots: infinite" << std::endl;
320320
}
321321

322322
Thread<std::pair<std::string, std::string>> copy_thread(
@@ -327,11 +327,11 @@ int main(int argc, char** argv)
327327
const auto bytes = final_copy(from_to.first, from_to.second);
328328

329329
const auto time = (get_wall_time_micros() - total_begin) / 1e6;
330-
std::cout << "Copy to " << from_to.second << " finished, took " << time << " sec, "
330+
std::cout << get_curr_datetime() << " Copy to " << from_to.second << " finished, took " << time << " sec, "
331331
<< ((bytes / time) / 1024 / 1024) << " MB/s avg." << std::endl;
332332
break;
333333
} catch(const std::exception& ex) {
334-
std::cout << "Copy to " << from_to.second << " failed with: " << ex.what() << std::endl;
334+
std::cout << get_curr_datetime() << " Copy to " << from_to.second << " failed with: " << ex.what() << std::endl;
335335
std::this_thread::sleep_for(std::chrono::minutes(5));
336336
}
337337
}
@@ -343,13 +343,13 @@ int main(int argc, char** argv)
343343
std::cout << std::endl << "Process has been interrupted, waiting for copy/rename operations to finish ..." << std::endl;
344344
break;
345345
}
346-
std::cout << "Crafting plot " << i+1 << " out of " << num_plots << std::endl;
346+
std::cout << get_curr_datetime() << " Crafting plot " << i+1 << " out of " << num_plots << std::endl;
347347
const auto out = create_plot(num_threads, log_num_buckets, pool_key, farmer_key, tmp_dir, tmp_dir2);
348348

349349
if(final_dir != tmp_dir)
350350
{
351351
const auto dst_path = final_dir + out.params.plot_name + ".plot";
352-
std::cout << "Started copy to " << dst_path << std::endl;
352+
std::cout << get_curr_datetime() << " Started copy to " << dst_path << std::endl;
353353
copy_thread.take_copy(std::make_pair(out.plot_file_name, dst_path));
354354
}
355355
}

0 commit comments

Comments
 (0)