1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-01 05:47:01 +03:00

Log slow MySQL queries, threshold set to 0.5s

(cherry picked from commit 43aeed9dbbe6c3716b805276bc8fbd13b36c05e9)
This commit is contained in:
Ruben S. Montero 2018-08-07 23:35:15 +02:00
parent 2faa46fb33
commit bcf333894d
2 changed files with 38 additions and 0 deletions

View File

@ -58,6 +58,28 @@ public:
zone_id = zid;
}
// -------------------------------------------------------------------------
// Profiler Interface
// -------------------------------------------------------------------------
static void start_timer(struct timespec * estart)
{
clock_gettime(CLOCK_MONOTONIC, estart);
}
static double stop_timer(struct timespec * estart)
{
double sec;
struct timespec eend;
clock_gettime(CLOCK_MONOTONIC, &eend);
sec = (eend.tv_sec + (eend.tv_nsec * 1e-9)) - (estart->tv_sec +
(estart->tv_nsec * 1e-9));
return sec;
}
// -------------------------------------------------------------------------
// Logger interface
// -------------------------------------------------------------------------

View File

@ -169,6 +169,10 @@ int MySqlDB::exec(ostringstream& cmd, Callbackable* obj, bool quiet)
Log::MessageType error_level = quiet ? Log::DDEBUG : Log::ERROR;
struct timespec timer;
Log::start_timer(&timer);
MYSQL * db = get_db_connection();
int rc = mysql_query(db, c_str);
@ -272,6 +276,18 @@ int MySqlDB::exec(ostringstream& cmd, Callbackable* obj, bool quiet)
free_db_connection(db);
double sec = Log::stop_timer(&timer);
if ( sec > 0.5 )
{
std::ostringstream oss;
oss << "Slow query (" << one_util::float_to_str(sec) << "s) detected: "
<< str;
NebulaLog::log("SQL", Log::WARNING, oss);
}
return rc;
}