Add some support for CPU profiling
This commit is contained in:
@@ -150,6 +150,17 @@ public:
|
||||
rescan_lua_source();
|
||||
}
|
||||
|
||||
void do_work_command(const util::StringVec &words) {
|
||||
int reps = 10000;
|
||||
int64_t t1 = util::profiling_clock();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
world_to_synchronous();
|
||||
world_to_asynchronous();
|
||||
}
|
||||
int64_t t2 = util::profiling_clock();
|
||||
stdostream() << "Snapshot/rollback took " << ((t2-t1)/reps) << " nanosec." << std::endl;
|
||||
}
|
||||
|
||||
void do_quit_command(const util::StringVec &words) {
|
||||
abandon_server();
|
||||
stop_driver();
|
||||
@@ -165,6 +176,7 @@ public:
|
||||
else if (words[0] == "choose") do_choose_command(words);
|
||||
else if (words[0] == "tick") do_tick_command(words);
|
||||
else if (words[0] == "cpl") do_cpl_command(words);
|
||||
else if (words[0] == "work") do_work_command(words);
|
||||
else if (words[0] == "quit") do_quit_command(words);
|
||||
else {
|
||||
stdostream() << "Unsupported command: " << words[0] << std::endl;
|
||||
|
||||
@@ -86,6 +86,10 @@ void LuaConsole::simplify(const StringVec &words) {
|
||||
if (words.size() != 1) {
|
||||
synerr("/cpl takes no arguments");
|
||||
}
|
||||
} else if (words[0] == "work") {
|
||||
if (words.size() != 1) {
|
||||
synerr("/work takes no arguments");
|
||||
}
|
||||
} else {
|
||||
synerr("unrecognized command");
|
||||
}
|
||||
|
||||
@@ -10,13 +10,26 @@
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef WIN32
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#define stat _stat
|
||||
#endif
|
||||
|
||||
namespace util {
|
||||
|
||||
int64_t profiling_clock() {
|
||||
#ifdef WIN32
|
||||
return 0.0;
|
||||
#else
|
||||
struct timespec ts;
|
||||
assert(0 == clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts));
|
||||
return int64_t(ts.tv_nsec) + (int64_t(ts.tv_sec)*int64_t(1000000000));
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool ascii_isalpha(char c) {
|
||||
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ using LuaSourcePtr = std::unique_ptr<LuaSourceVec>;
|
||||
using HashValue = std::pair<uint64_t, uint64_t>;
|
||||
using IdVector = std::vector<int64_t>;
|
||||
|
||||
// Return nanoseconds elapsed, for profiling purposes.
|
||||
int64_t profiling_clock();
|
||||
|
||||
// Return true if the string is a valid lua identifier.
|
||||
bool is_identifier(const std::string &str);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user