7#include <boost/filesystem/operations.hpp>
21#include <sys/resource.h>
24# include <sys/param.h>
25# include <sys/sysctl.h>
31# include <sys/types.h>
32# include <sys/sysctl.h>
33# include <mach/task.h>
34# include <mach/mach_init.h>
63 size_t system_memory_use_limit()
66 MEMORYSTATUSEX statex;
67 statex.dwLength =
sizeof(statex);
68 GlobalMemoryStatusEx(&statex);
69 return statex.ullTotalPhys;
71 size_t limit_by_rlimit = std::numeric_limits<size_t>::max();
74 if (getrlimit(RLIMIT_AS, &rlp) == 0
75 && rlp.rlim_cur != std::numeric_limits<rlim_t>::max()) {
76 limit_by_rlimit = rlp.rlim_cur;
78 limit_by_rlimit *= 1024;
80 std::cerr <<
"rlimit " << limit_by_rlimit <<
"\n";
87 size_t len=
sizeof(usermem);
90 if (sysctl(mib, 2, &usermem, &len, NULL, 0) == 0
91 && len ==
sizeof(usermem)) {
92 std::cerr <<
"usermem " << usermem << std::endl;
93 return std::min((
size_t)usermem, limit_by_rlimit);
98 std::string name, unit;
100 std::ifstream is(
"/proc/meminfo");
101 if (is >> name >> value >> unit
102 && name ==
"MemTotal:" && unit ==
"kB")
103 return std::min(value * 1024, limit_by_rlimit);
105#if (defined __FreeBSD__)
106 const long mem = sysconf(_SC_PHYS_PAGES);
108 return std::min(mem * getpagesize(), limit_by_rlimit);
110 return std::min((rlim_t)limit_by_rlimit, std::numeric_limits<rlim_t>::max());
120 std::numeric_limits<rlim_t>::max();
127 std::cerr <<
"ncpu " << ncpu <<
" > " <<
"MaxThreads " <<
MaxThreads <<
"\n";
135 if (num_cpu > MaxThreads)
136 std::cerr <<
"ncpu " << num_cpu <<
" > " <<
"MaxThreads " << MaxThreads <<
"\n";
137 return std::min(num_cpu, MaxThreads);
160 return usi_mode_silent;
164 usi_mode_silent = enable;
168 return search_exact_value_in_one_reply;
172 search_exact_value_in_one_reply = enable;
187 std::cerr <<
"using " << home <<
" as OSL_HOME, word size "
198 return boost::filesystem::exists(dir)
199 && boost::filesystem::is_directory(dir);
204 if (isGoodDir(candidate))
210 std::cerr <<
"skipping " << candidate << std::endl;
217 trySetDir(result, first_try);
219 if (
const char *env = getenv(
"GPSSHOGI_HOME"))
220 trySetDir(result, env);
222#if defined GPSSHOGI_HOME
224 trySetDir(result, GPSSHOGI_HOME);
228 if (
const char *env = getenv(
"OSL_HOME"))
229 trySetDir(result, env);
241 static const std::string home_directory = makeHome(init);
242 return home_directory;
247 return home().c_str();
255#ifdef OSL_PUBLIC_RELEASE
257 if (
const char *env = getenv(
"HOME"))
258 return std::string(env) +
"/gpsusi.conf";
259 if (
const char *env = getenv(
"USERPROFILE"))
260 return std::string(env) +
"/gpsusi.conf";
263 static const std::string home_directory = makeHome();
264 return home_directory +
"/gpsusi.conf";
269 static const int value = getenv(
"OSL_RESIGN_VALUE")
270 ? atoi(getenv(
"OSL_RESIGN_VALUE")) : 0;
271 return (value > 0) ? value : 10000;
277 if (
const char *env = getenv(
"OSL_TEST"))
278 trySetDir(result, env);
281 result = home() +
"/data";
283 std::cerr <<
"using " << result <<
" as OSL_TEST" << std::endl;
290 if (
const char *env = getenv(
"OSL_TEST_PUBLIC"))
291 trySetDir(result, env);
294 result = home() +
"/public-data";
296 std::cerr <<
"using " << result <<
" as OSL_TEST_PUBLIC" << std::endl;
302 static const std::string test_directory = makeTest();
303 return test_directory;
308 static const std::string test_directory = makeTestPublic();
309 return test_directory;
314 struct NameHolder : std::map<std::string,std::string>
316 std::string directory;
318 NameHolder(
const std::string& d) : directory(d)
323 iterator add(
const std::string& key,
const std::string& value)
325 return insert(std::make_pair(key, value)).first;
327 iterator addRelative(
const std::string& key,
const std::string& filename)
329 std::string value = directory + filename;
330 return add(key, value);
332 iterator addRelative(
const std::string& filename)
334 return addRelative(filename, filename);
341 static NameHolder table(testPrivate());
342 NameHolder::iterator p=table.find(filename);
343 if (p == table.end()) {
344 p = table.addRelative(filename);
346 return p->second.c_str();
351 static NameHolder table(testPublic());
352 NameHolder::iterator p=table.find(filename);
353 if (p == table.end()) {
354 p = table.addRelative(filename);
356 return p->second.c_str();
361 static NameHolder table(testPublic()+
"/floodgate2010");
362 NameHolder::iterator p=table.find(filename);
363 if (p == table.end()) {
364 p = table.addRelative(filename);
366 return p->second.c_str();
371 static NameHolder table(home()+
"/data");
372 NameHolder::iterator p=table.find(filename);
373 if (p == table.end()) {
374 if (! filename.empty() && filename[0] ==
'/') {
376 p = table.add(filename, filename);
380 p = table.addRelative(filename,
381 (filename ==
"" ?
"joseki.dat" : filename));
384 return p->second.c_str();
391 static const DWORD process_id = GetCurrentProcessId();
392 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
394 if (NULL == hProcess)
396 std::cerr <<
"Failed to get residentMemoryUse()\n";
400 size_t working_set = 0;
401 PROCESS_MEMORY_COUNTERS pmc;
402 if (GetProcessMemoryInfo(hProcess, &pmc,
sizeof(pmc))) {
403 working_set = pmc.WorkingSetSize;
405 CloseHandle(hProcess);
410 std::ifstream is(
"/proc/self/statm");
411 size_t total, resident;
412 if (is >> total >> resident)
413 return resident*getpagesize();
415 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
416 task_basic_info_64 ti;
417 if (task_info(current_task(), TASK_BASIC_INFO_64, (task_info_t)&ti, &count)
419 return ti.resident_size;
422 static kvm_t *kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY,
"osl kvm_open");
424 kinfo_proc *pp = kvm_getprocs(kd, KERN_PROC_PID, getpid(), &nproc);
426 return pp->ki_rssize * getpagesize();
434 static std::vector<std::function<void()>> initialize_functions;
435 return initialize_functions;
455 bool old_verbose = verbose();
457 std::cerr <<
"health check\n";
462 std::string filename =
"eval.bin";
463 std::cerr <<
"loading " << filename <<
' ';
466 std::cerr << (success ?
"success" :
"failed\a") <<
"\n";
468 std::cerr <<
"exists? " << boost::filesystem::exists(filename.c_str()) <<
"\n";
469 std::cerr <<
"regular? " << boost::filesystem::is_regular_file(filename.c_str()) <<
"\n";
476 std::cerr <<
"loading " << filename <<
' ';
478 std::cerr << (success ?
"success" :
"failed\a") <<
"\n";
480 std::cerr <<
"exists? " << boost::filesystem::exists(filename.c_str()) <<
"\n";
481 std::cerr <<
"regular? " << boost::filesystem::is_regular_file(filename.c_str()) <<
"\n";
487 setVerbose(old_verbose);
493 return dfpn_max_depth;
497 dfpn_max_depth = new_depth;
static std::string defaultFilename()
static std::vector< std::function< void()> > & function_vector()
static std::mutex lock_io
static void registerInitializer(std::function< void()>)
static void showOslHome()
static volatile int in_unit_test
static int usi_output_pawn_value
static void trySetDir(std::string &, const std::string &)
static volatile int root_window_alpha
static int resignThreshold()
static const std::string testPublic()
static void setUsiSilent(bool silent=true)
static const std::string gpsusiConf()
static volatile bool force_root_window
static int dfpn_max_depth
static double memory_use_percent
static bool search_exact_value_in_one_reply
static const char * home_c_str()
static bool healthCheck()
static unsigned int eval_random
static bool searchExactValueInOneReply()
static int dfpnMaxDepth()
static void setUsiMode(UsiMode new_mode=PortableUSI)
static const std::string makeHome(const std::string &first_try="")
static const size_t memory_use_limit_system_max
static bool isGoodDir(const std::string &)
static void setUp()
評価関数等を初期化.
static const char * openingBook(const std::string &filenamme="")
標準の定跡ファイルを返す
static void setNumCPUs(int ncpu)
static size_t memory_use_limit
static volatile UsiMode usi_mode
static const int default_ncpus
static std::string configuration()
static const std::string makeTest()
static bool usiModeInSilent()
static void setHasByoyomi(bool)
static const std::string testPrivate()
テストケースのデータ
static void setSearchExactValueInOneReply(bool new_value)
static const std::string makeTestPublic()
static volatile int root_window_beta
static void setDfpnMaxDepth(int)
static const char * testCsaFile(const std::string &filename)
static const char * testPublicFile(const std::string &filename)
static void setVerbose(bool verbose)
static size_t residentMemoryUse()
static volatile bool usi_mode_silent
static const char * testPrivateFile(const std::string &filename)
static const std::string & home(const std::string &initialize_if_first_invocation="")
compile時に指定されたディレクトリを返す.
static const int MaxThreads