forked from OpenTM2/opentm2-source
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathotmd.cpp
executable file
·174 lines (134 loc) · 5.18 KB
/
otmd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <iostream>
#include <csignal>
#include <cstdlib>
#include <chrono>
#include <thread>
#include <unistd.h>
#include <folly/portability/GFlags.h>
#include <execinfo.h>
#include "opentm2/core/utilities/LogWrapper.h"
#include "cmake/git_version.h"
#include "opentm2/core/utilities/PropertyWrapper.H"
#include "EQF.H"
static bool ValidatePort(const char* flagname, int32_t value) {
if (value > 0 && value < 32768) // value is ok
return true;
printf("Invalid value for --%s: %d\n", flagname, (int)value);
return false;
}
DEFINE_int32(port, 4080, "What port to listen on");
DEFINE_validator(port, &ValidatePort);
DEFINE_bool(localhostonly, false, "Should we use localhost or external address for service");
DEFINE_string(servicename, "t5memory", "Sets service name to use in url");
static bool ValidateTriplesThreshold(const char* flagname, int32_t value) {
if (value >= 0 && value <= 100) // value is ok
return true;
printf("Invalid value for --%s: %d, should be [0...100]\n", flagname, (int)value);
return false;
}
DEFINE_int32(triplesthreshold, 5, "Sets threshold to pre fuzzy filtering based on hashes of neibour tokens");
DEFINE_validator(triplesthreshold, &ValidateTriplesThreshold);
static bool ValidateTimeout(const char* flagname, int32_t value) {
if (value >= 0 && value <= 10000) // value is ok
return true;
printf("Invalid value for --%s: %d, should be [0...10000]\n", flagname, (int)value);
return false;
}
DEFINE_int32(timeout, 3600, "Sets timeout for service request handling");
DEFINE_validator(timeout, &ValidateTimeout);
static bool ValidateThreads(const char* flagname, int32_t value) {
if (value >= 1 && value <= 100) // value is ok
return true;
printf("Invalid value for --%s: %d, should be [1...100]\n", flagname, (int)value);
return false;
}
DEFINE_int32(servicethreads, 1, "Sets amought of worker threads for service");
DEFINE_validator(servicethreads, &ValidateThreads);
static bool ValidateRAM(const char* flagname, int32_t value) {
if (value >= 1 && value <= 10000) // value is ok
return true;
printf("Invalid value for --%s: %d, should be [1...10000]\n", flagname, (int)value);
return false;
}
DEFINE_int32(allowedram, 500, "Sets amought RAM(in MB) allowed for service to use");
DEFINE_validator(allowedram, &ValidateRAM);
static bool ValidateLOGlevel(const char* flagname, int32_t value) {
if (value >= 0 && value <= 6) // value is ok
return true;
printf("Invalid value for --%s: %d, should be [0...6]\n", flagname, (int)value);
return false;
}
DEFINE_int32(t5loglevel, 0, "Sets t5memory log level threshold from DEVELOP(0) to TRANSACTION(6)[disabled]");
DEFINE_validator(t5loglevel, &ValidateLOGlevel);
DEFINE_bool(useconfigfile, false, "Set to use values from config file that should be located under ~/.t5memory/t5memory.conf");
DEFINE_bool(forbiddeletefiles, false, "Set to true to keep all files(including temporary and tm)");
void handle_interrupt_sig(int sig) {
LogMessage1(TRANSACTION, "Received interrupt signal\n");
//StopOtmMemoryService();
LogMessage1(TRANSACTION, "Stopped t5memory\n");
}
void FailureWriter(const char* data, int size){
LogMessage1(FATAL, data);
void *array[10];
// get void*'s for all entries on the stack
size_t sz = backtrace(array, 10);
std::string backtraceStr;
for(int i = 0; i < sz && array[i] != 0; i++){
backtraceStr += (char*) array[i];
backtraceStr += '\n';
}
LogMessage2(FATAL, ":backtrace:\n", backtraceStr.c_str());
// print out all the frames to stderr
//fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
}
/*
void CustomPrefix(std::ostream &s, const LogMessageInfo &l, void*) {
l.
s << l.severity[0]
<< setw(4) << 1900 + l.time.year()
<< setw(2) << 1 + l.time.month()
<< setw(2) << l.time.day()
<< ' '
<< setw(2) << l.time.hour() << ':'
<< setw(2) << l.time.min() << ':'
<< setw(2) << l.time.sec() << "."
<< setw(6) << l.time.usec()
<< ' '
<< setfill(' ') << setw(5)
<< l.thread_id << setfill('0')
<< ' '
<< l.filename << ':' << l.line_number << "]";
}
//*/
//using namespace gflags;
using namespace google;
//using namespace GFLAGS_NAMESPACE;
int proxygen_server_init();
int main(int argc, char* argv[]) {
//#ifdef GLOGGING_ENABLED
FLAGS_log_dir = "/home/or/.t5memory/LOG/";
if(FLAGS_log_dir.empty()){
FLAGS_log_dir = "/root/.t5memory/LOG/";
}
FLAGS_colorlogtostderr = true;
//#endif
//#ifdef GFLAGS_ENABLED
//FLAGS_alsologtostderr = true;
//google::InstallFailureSignalHandler();
// google::InstallFailureWriter(FailureWriter);
google::ParseCommandLineFlags(&argc, &argv, true);
//gflags::ParseCommandLineFlags(&argc, &argv, false);
//#endif//GFLAGS_ENABLED
//#ifdef GLOGGING_ENABLED
google::InitGoogleLogging(argv[0]);//, &CustomPrefix);
//#endif
//int logLevel = 1/0;
//WLogMessage1(logLevel, "fail");
//LOG_DEBUG_MSG() << "SOME_DEBUG_MSG";
LogMessage1(TRANSACTION, "Worker thread starting");
std::thread worker(proxygen_server_init);
worker.join();
LogMessage1(TRANSACTION, "Worker thread finished");
}