void HumanSummaryReportWriter::print_label_and_rounded_hours ( ostream& p_os, string const& p_label, unsigned long long p_seconds, TimePoint const* p_beginning, TimePoint const* p_ending, unsigned int p_left_col_width ) const { StreamFlagGuard guard(p_os); if (!p_label.empty()) { p_os << left << setw(p_left_col_width) << p_label << ' ' << right << setw(output_width()); } p_os << fixed << setprecision(output_precision()) << seconds_to_rounded_hours(p_seconds); guard.reset(); if (p_beginning != nullptr) { p_os << " " << time_point_to_stamp(*p_beginning, time_format(), formatted_buf_len()); } if (p_ending != nullptr) { p_os << " " << time_point_to_stamp(*p_ending, time_format(), formatted_buf_len()); } p_os << endl; return; }
void HumanSummaryReportWriter::write_tree_summary ( ostream& p_os, map<std::string, ActivityStats> const& p_activity_stats_map ) { // TODO When the user passes a string even without the -r option, // when printing in tree mode, it should probably match that string // to non-leaf nodes as well as just leaf nodes. (It should possibly // even do this when not printing in tree mode.) if (p_activity_stats_map.empty()) { p_os << endl; return; } ActivityTree const tree(p_activity_stats_map); ActivityTree::PrintNode const print_node = [this] ( ostream& p_ostream, unsigned int p_node_depth, string const& p_node_label, ActivityStats const& p_stats ) { StreamFlagGuard guard(p_ostream); p_ostream << string(p_node_depth * (output_width() + 4), ' ') << "[ " << fixed << setprecision(output_precision()) << right << setw(output_width()) << seconds_to_rounded_hours(p_stats.seconds) << " ]"; guard.reset(); if (m_include_beginning) { auto const& b = p_stats.beginning; auto const s = time_point_to_stamp(b, time_format(), formatted_buf_len()); p_ostream << "[ " << s << " ]"; } if (m_include_ending) { auto const& e = p_stats.ending; auto const s = time_point_to_stamp(e, time_format(), formatted_buf_len()); p_ostream << "[ " << s << " ]"; } p_ostream << ' ' << p_node_label << endl; return; }; tree.print(p_os, print_node); return; }
void log_message(LogLevel level, const char* function, int line, const char* msg, ...) { if (level < logger.level) return; char buffer[LOG_BUFFER_SIZE]; va_list va; int preffixSize; time_format(buffer, "[%Y:%m:%d-%H:%M:%S]"); str_sprintf(buffer, "%s %s %s ", buffer, log_getLevelStr(level), logger.program, function, line); if (logger.develOutput) str_sprintf(buffer, "%s[%s:%i] ", buffer, function, line); preffixSize = str_len(buffer); va_start(va, msg); vsnprintf(buffer + preffixSize, LOG_BUFFER_SIZE - preffixSize, msg, va); va_end(va); if (logger.stdOutput) puts(buffer); if (logger.logFileFd) { file_write(logger.logFileFd, buffer, str_len(buffer)); file_write(logger.logFileFd, "\n", 1); } }
std::string CScreen::ETA() { int64_t PC = positionCounter.load(std::memory_order_acquire); std::chrono::milliseconds duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime); std::string ret = "ETA: "; ret.append(time_format(duration * (positions - PC) / PC)); return ret; }
void CScreen::printStats(const int depth, const int selectivity, const uint64_t P, const uint64_t O, const int score, const std::chrono::milliseconds duration, const uint64_t NodeCounter, const std::string& PV) { if (verbose >= 3) { std::unique_lock<std::mutex> lock(mtx); printf("%6s| %+2.2d |%16s|%*s|%*s| %s\n", DepthSelectivity(depth, selectivity, P, O).c_str(), score, time_format(duration).c_str(), width_nodes, ThousandsSeparator(NodeCounter).c_str(), width_nps, (duration.count() == 0 ? nullptr : ThousandsSeparator(NodeCounter * 1000ULL / duration.count()).c_str()), PV.c_str()); } }
void display_tick(void) { static uint32_t s = 0; char buf[64]; s++; if(s == 10) { s = 0; struct time *t = time_getTime(); time_format(t, buf); font_renders(buf, 0, 32); lcd_display(); } }
void CScreen::printSummary(uint64_t NodeCounter) { std::chrono::milliseconds duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime); if (positionCounter.load(std::memory_order_acquire) == 0) printf("No positions were solved.\n"); else if (verbose == 0) { std::unique_lock<std::mutex> lock(mtx); printf("%16s %6s %*s %*s\n", time_format(duration).c_str(), short_time_format(std::chrono::duration_cast<std::chrono::duration<long long, std::pico>>(duration) / positionCounter.load(std::memory_order_acquire)).c_str(), width_nodes, ThousandsSeparator(NodeCounter).c_str(), width_nps, duration.count() == 0 ? nullptr : ThousandsSeparator(NodeCounter * 1000 / duration.count()).c_str()); } else { std::unique_lock<std::mutex> lock(mtx); printf("%s positions solved in: %16s\nAverage time per position: %6s\nNodes: %s\nSpeed: %s N/s\n", ThousandsSeparator(positionCounter.load(std::memory_order_acquire)).c_str(), time_format(duration).c_str(), short_time_format(std::chrono::duration_cast<std::chrono::duration<long long, std::pico>>(duration) / positionCounter.load(std::memory_order_acquire)).c_str(), ThousandsSeparator(NodeCounter).c_str(), duration.count() == 0 ? nullptr : ThousandsSeparator(NodeCounter * 1000 / duration.count()).c_str()); } }
void CScreen::printResult(const int number, const int depth, const int selectivity, const uint64_t P, const uint64_t O, const int score, const std::chrono::milliseconds duration, const uint64_t NodeCounter, const std::string& PV) { positionCounter.fetch_add(1, std::memory_order_relaxed); if (verbose == 1) { if (!flag.test_and_set(std::memory_order_acquire)) { if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - lastPrint).count() > 500) { if (positions) { std::unique_lock<std::mutex> lock(mtx); std::cout << "\r" << ThousandsSeparator(positionCounter.load(std::memory_order_acquire)) << " positions solved. " << positionCounter.load(std::memory_order_acquire) * 100 / positions << "% " << ETA(); fflush(stdout); } else { std::unique_lock<std::mutex> lock(mtx); std::cout << "\r" << ThousandsSeparator(positionCounter.load(std::memory_order_acquire)) << " positions solved in " << time_format(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime)); fflush(stdout); } lastPrint = std::chrono::high_resolution_clock::now(); } flag.clear(std::memory_order_release); } } else if (verbose == 2) { std::unique_lock<std::mutex> lock(mtx); printf("%*d|%6s| %+2.2d |%16s|%*s|%*s| %s\n", width_number, number, DepthSelectivity(depth, selectivity, P, O).c_str(), score, time_format(duration).c_str(), width_nodes, ThousandsSeparator(NodeCounter).c_str(), width_nps, (duration.count() == 0 ? nullptr : ThousandsSeparator(NodeCounter * 1000ULL / duration.count()).c_str()), PV.c_str()); } else if (verbose == 3) { std::string L1, L2; GetLines(L1, L2); std::unique_lock<std::mutex> lock(mtx); std::cout << L2 << std::endl; } }
/* New game handler, send and recieve messages with a client */ void *new_game(void *new_conection) { int len; char guess[NUM_CHOOSEN + 1]; guess_out_t *output; char *code = malloc(sizeof(char)*sizeof(NUM_CHOOSEN));; char *time_str = malloc(sizeof(char) * TIME_LEN); /* Get data from strcuture */ data_t *client_data = (data_t*)new_conection; int new_s = client_data->client_socket; char *ip4 = client_data->ip4; pthread_mutex_lock(&mutex); fprintf(logfile, "%s (%s) (sock_id = %d) client connected\n", time_format(time_str), ip4, new_s); pthread_mutex_unlock(&mutex); /* Generate a code for each client if it was not provided */ if(client_data->code != NULL){ strcpy(code, client_data->code); } else { code = generate_code(code); } pthread_mutex_lock(&mutex); fprintf(logfile, "%s (0.0.0.0) Server secret for (%s)(sock_id = %d) = %s\n", time_format(time_str), ip4, new_s, code); pthread_mutex_unlock(&mutex); /*Get and send instructions for the game */ char* instructions = game_instructions(); write(new_s, instructions, strlen(instructions) + 1); /*Read guesses from the user until the number of guesses has been exhausted */ int num_guesses = 0; while (len=recv(new_s,&guess,sizeof(guess),0)){ if(num_guesses < MAX_GUESSES){ /* Write guess into log file */ fprintf(logfile, "%s From: (%s)(socket_id = %d) guess = %s\n", time_format(time_str), ip4, new_s, guess); /*Get the output of the guess*/ output = next_guess(code, guess, num_guesses); /*Send Message to player*/ write(new_s, output->send_msg, output->send_len); /* Write outcome into log file */ pthread_mutex_lock(&mutex); if(strstr(output->log_msg, "SUCCESS")){ correct_guesses++; fprintf(logfile, "%s To: (%s)(socket_id = %d) %s\n", time_format(time_str), ip4, new_s, output->log_msg); } else if(strstr(output->log_msg, "FAILURE")){ fprintf(logfile, "%s To: (%s)(socket_id = %d) %s\n", time_format(time_str), ip4, new_s, output->log_msg); } else if(strstr(output->log_msg, "INVALID")){ fprintf(logfile, "%s To: (%s)(socket_id = %d) %s\n", time_format(time_str), ip4, new_s, output->log_msg); } else { fprintf(logfile, "%s To: (%s)(socket_id = %d) server's hint: %s\n", time_format(time_str), ip4, new_s, output->log_msg); } pthread_mutex_unlock(&mutex); num_guesses = output->num_guesses; } else { break; } } close (new_s); }