Initial import.
This commit is contained in:
commit
ed320731e9
93 changed files with 21078 additions and 0 deletions
146
utils/applog.c
Normal file
146
utils/applog.c
Normal file
|
@ -0,0 +1,146 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "xmrig.h"
|
||||
#include "applog.h"
|
||||
#include "threads.h"
|
||||
#include <sys/time.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WIN32
|
||||
# include "compat/winansi.h"
|
||||
#endif
|
||||
|
||||
#include "options.h"
|
||||
|
||||
|
||||
MUTEX applog_mutex;
|
||||
|
||||
|
||||
void applog_init()
|
||||
{
|
||||
MUTEX_INIT(applog_mutex);
|
||||
}
|
||||
|
||||
|
||||
void applog(int prio, const char *fmt, ...)
|
||||
{
|
||||
if (opt_background) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
struct tm tm;
|
||||
struct tm *tm_p;
|
||||
time_t now = time(NULL);
|
||||
|
||||
MUTEX_LOCK(applog_mutex);
|
||||
tm_p = localtime(&now);
|
||||
memcpy(&tm, tm_p, sizeof(tm));
|
||||
MUTEX_UNLOCK(applog_mutex);
|
||||
|
||||
const char* color = "";
|
||||
|
||||
if (opt_colors) {
|
||||
switch (prio) {
|
||||
case LOG_ERR: color = CL_RED; break;
|
||||
case LOG_WARNING: color = CL_YLW; break;
|
||||
case LOG_NOTICE: color = CL_WHT; break;
|
||||
case LOG_INFO: color = ""; break;
|
||||
case LOG_DEBUG: color = CL_GRY; break;
|
||||
|
||||
case LOG_BLUE:
|
||||
prio = LOG_NOTICE;
|
||||
color = CL_CYN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const int len = 64 + strlen(fmt) + 2;
|
||||
char *f = alloca(len);
|
||||
|
||||
sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n",
|
||||
tm.tm_year + 1900,
|
||||
tm.tm_mon + 1,
|
||||
tm.tm_mday,
|
||||
tm.tm_hour,
|
||||
tm.tm_min,
|
||||
tm.tm_sec,
|
||||
color,
|
||||
fmt,
|
||||
opt_colors ? CL_N : ""
|
||||
);
|
||||
|
||||
MUTEX_LOCK(applog_mutex);
|
||||
vfprintf(stderr, f, ap);
|
||||
fflush(stderr);
|
||||
MUTEX_UNLOCK(applog_mutex);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
void applog_notime(int prio, const char *fmt, ...)
|
||||
{
|
||||
if (opt_background) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
const char* color = "";
|
||||
|
||||
if (opt_colors) {
|
||||
switch (prio) {
|
||||
case LOG_ERR: color = CL_RED; break;
|
||||
case LOG_WARNING: color = CL_YLW; break;
|
||||
case LOG_NOTICE: color = CL_WHT; break;
|
||||
case LOG_INFO: color = ""; break;
|
||||
case LOG_DEBUG: color = CL_GRY; break;
|
||||
|
||||
case LOG_BLUE:
|
||||
prio = LOG_NOTICE;
|
||||
color = CL_CYN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const int len = 64 + strlen(fmt) + 2;
|
||||
char *f = alloca(len);
|
||||
|
||||
sprintf(f, "%s%s%s\n",
|
||||
color,
|
||||
fmt,
|
||||
opt_colors ? CL_N : ""
|
||||
);
|
||||
|
||||
MUTEX_LOCK(applog_mutex);
|
||||
vfprintf(stderr, f, ap);
|
||||
fflush(stderr);
|
||||
MUTEX_UNLOCK(applog_mutex);
|
||||
|
||||
va_end(ap);
|
||||
}
|
74
utils/applog.h
Normal file
74
utils/applog.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __APPLOG_H__
|
||||
#define __APPLOG_H__
|
||||
|
||||
enum {
|
||||
LOG_ERR,
|
||||
LOG_WARNING,
|
||||
LOG_NOTICE,
|
||||
LOG_INFO,
|
||||
LOG_DEBUG,
|
||||
LOG_BLUE = 0x10
|
||||
};
|
||||
|
||||
#define CL_N "\x1B[0m"
|
||||
#define CL_RED "\x1B[31m"
|
||||
#define CL_GRN "\x1B[32m"
|
||||
#define CL_YLW "\x1B[33m"
|
||||
#define CL_BLU "\x1B[34m"
|
||||
#define CL_MAG "\x1B[35m"
|
||||
#define CL_CYN "\x1B[36m"
|
||||
|
||||
#define CL_BLK "\x1B[22;30m" /* black */
|
||||
#define CL_RD2 "\x1B[22;31m" /* red */
|
||||
#define CL_GR2 "\x1B[22;32m" /* green */
|
||||
#define CL_BRW "\x1B[22;33m" /* brown */
|
||||
#define CL_BL2 "\x1B[22;34m" /* blue */
|
||||
#define CL_MA2 "\x1B[22;35m" /* magenta */
|
||||
#define CL_CY2 "\x1B[22;36m" /* cyan */
|
||||
#define CL_SIL "\x1B[22;37m" /* gray */
|
||||
|
||||
#ifdef WIN32
|
||||
#define CL_GRY "\x1B[01;30m" /* dark gray */
|
||||
#else
|
||||
#define CL_GRY "\x1B[90m" /* dark gray selectable in putty */
|
||||
#endif
|
||||
#define CL_LRD "\x1B[01;31m" /* light red */
|
||||
#define CL_LGR "\x1B[01;32m" /* light green */
|
||||
#define CL_YL2 "\x1B[01;33m" /* yellow */
|
||||
#define CL_LBL "\x1B[01;34m" /* light blue */
|
||||
#define CL_LMA "\x1B[01;35m" /* light magenta */
|
||||
#define CL_LCY "\x1B[01;36m" /* light cyan */
|
||||
|
||||
#define CL_WHT "\x1B[01;37m" /* white */
|
||||
|
||||
#define OPT_COLOR(color, text) (opt_colors ? (color text CL_N) : text)
|
||||
|
||||
|
||||
void applog_init();
|
||||
void applog(int prio, const char *fmt, ...);
|
||||
void applog_notime(int prio, const char *fmt, ...);
|
||||
|
||||
#endif /* __APPLOG_H__ */
|
103
utils/summary.c
Normal file
103
utils/summary.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "options.h"
|
||||
#include "applog.h"
|
||||
#include "version.h"
|
||||
#include "persistent_memory.h"
|
||||
#include "cpu.h"
|
||||
|
||||
|
||||
static void print_memory() {
|
||||
const char *t1 = (persistent_memory_flags & MEMORY_HUGEPAGES_AVAILABLE) ? OPT_COLOR(CL_LGR, "available") : OPT_COLOR(CL_LRD, "unavailable");
|
||||
const char *t2 = (persistent_memory_flags & MEMORY_HUGEPAGES_ENABLED) ? OPT_COLOR(CL_LGR, "enabled") : OPT_COLOR(CL_LRD, "disabled");
|
||||
|
||||
if (opt_colors) {
|
||||
applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "HUGE PAGES: %s, %s", t1, t2);
|
||||
}
|
||||
else {
|
||||
applog_notime(LOG_INFO, " * HUGE PAGES: %s, %s", t1, t2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void print_cpu() {
|
||||
const char *t1 = (cpu_info.flags & CPU_FLAG_X86_64) ? OPT_COLOR(CL_LGR, "x86_64") : OPT_COLOR(CL_LRD, "-x86_64");
|
||||
const char *t2 = (cpu_info.flags & CPU_FLAG_AES) ? OPT_COLOR(CL_LGR, "AES-NI") : OPT_COLOR(CL_LRD, "-AES-NI");
|
||||
const char *t3 = (cpu_info.flags & CPU_FLAG_BMI2) ? OPT_COLOR(CL_LGR, "BMI2") : OPT_COLOR(CL_LRD, "-BMI2");
|
||||
|
||||
if (opt_colors) {
|
||||
applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "CPU: %s", cpu_info.brand);
|
||||
applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "CPU FEATURES: %s %s %s", t1, t2, t3);
|
||||
}
|
||||
else {
|
||||
applog_notime(LOG_INFO, " * CPU: %s", cpu_info.brand);
|
||||
applog_notime(LOG_INFO, " * CPU FEATURES: %s %s %s", t1, t2, t3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void print_threads() {
|
||||
if (opt_colors) {
|
||||
applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "THREADS: " CL_WHT "%d" CL_WHT ", av=%d, donate=%d%%", opt_n_threads, opt_algo_variant, opt_donate_level);
|
||||
}
|
||||
else {
|
||||
applog_notime(LOG_INFO, " * THREADS: %d, av=%d, donate=%d%%", opt_n_threads, opt_algo_variant, opt_donate_level);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void print_stratum() {
|
||||
if (opt_colors) {
|
||||
applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "STRATUM URL: " CL_LCY "%s", opt_url);
|
||||
|
||||
if (opt_backup_url) {
|
||||
applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "FAILOVER URL: " CL_LCY "%s", opt_backup_url);
|
||||
}
|
||||
else {
|
||||
applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "FAILOVER URL: " CL_LRD "none");
|
||||
}
|
||||
}
|
||||
else {
|
||||
applog_notime(LOG_INFO, " * STRATUM URL: %s", opt_url);
|
||||
applog_notime(LOG_INFO, " * FAILOVER URL: %s", opt_backup_url ? opt_backup_url : "none");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print_summary() {
|
||||
if (opt_colors) {
|
||||
applog_notime(LOG_INFO, CL_LGR " * " CL_WHT APP_NAME " " APP_VERSION " " CL_LCY APP_SITE);
|
||||
}
|
||||
else {
|
||||
applog_notime(LOG_INFO, " * " APP_NAME " " APP_VERSION " " APP_SITE);
|
||||
}
|
||||
|
||||
print_memory();
|
||||
print_cpu();
|
||||
print_threads();
|
||||
print_stratum();
|
||||
}
|
||||
|
||||
|
||||
|
29
utils/summary.h
Normal file
29
utils/summary.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __SUMMARY_H__
|
||||
#define __SUMMARY_H__
|
||||
|
||||
void print_summary();
|
||||
|
||||
#endif /* __SUMMARY_H__ */
|
41
utils/threads.h
Normal file
41
utils/threads.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __THREADS_H__
|
||||
#define __THREADS_H__
|
||||
|
||||
#if defined(WIN32) && defined(USE_NATIVE_THREADS)
|
||||
# include <windows.h>
|
||||
# define MUTEX CRITICAL_SECTION
|
||||
# define MUTEX_INIT(mutex) InitializeCriticalSection(&mutex)
|
||||
# define MUTEX_LOCK(mutex) EnterCriticalSection(&mutex)
|
||||
# define MUTEX_UNLOCK(mutex) LeaveCriticalSection(&mutex)
|
||||
#else
|
||||
# include <pthread.h>
|
||||
# define MUTEX pthread_mutex_t
|
||||
# define MUTEX_INIT(mutex) pthread_mutex_init(&mutex, NULL)
|
||||
# define MUTEX_LOCK(mutex) pthread_mutex_lock(&mutex)
|
||||
# define MUTEX_UNLOCK(mutex) pthread_mutex_unlock(&mutex)
|
||||
#endif
|
||||
|
||||
#endif /* __THREADS_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue