void Config::recordQueryPerformance(const std::string& name, size_t delay, size_t size, const Row& r0, const Row& r1) { // Grab a lock on the schedule structure and check the name. ConfigDataInstance config; if (config.schedule().count(name) == 0) { // Unknown query schedule name. return; } // Grab access to the non-const schedule item. auto& query = getInstance().data_.schedule.at(name); auto diff = strtol(r1.at("user_time").c_str(), nullptr, 10) - strtol(r0.at("user_time").c_str(), nullptr, 10); query.user_time += diff; diff = strtol(r1.at("system_time").c_str(), nullptr, 10) - strtol(r0.at("system_time").c_str(), nullptr, 10); query.system_time += diff; diff = strtol(r1.at("resident_size").c_str(), nullptr, 10) - strtol(r0.at("resident_size").c_str(), nullptr, 10); // Memory is stored as an average of BSS changes between query executions. query.memory = (query.memory * query.executions + diff) / (query.executions + 1); query.wall_time += delay; query.output_size += size; query.executions += 1; }
void SchedulerRunner::start() { time_t t = std::time(nullptr); struct tm* local = std::localtime(&t); unsigned long int i = local->tm_sec; for (; (timeout_ == 0) || (i <= timeout_); ++i) { { ConfigDataInstance config; for (const auto& query : config.schedule()) { if (i % query.second.splayed_interval == 0) { launchQuery(query.first, query.second); } } } // Put the thread into an interruptible sleep without a config instance. osquery::interruptableSleep(interval_ * 1000); } }
void Config::recordQueryPerformance(const std::string& name, size_t delay, size_t size, const Row& r0, const Row& r1) { // Grab a lock on the schedule structure and check the name. ConfigDataInstance config; if (config.schedule().count(name) == 0) { // Unknown query schedule name. return; } // Grab access to the non-const schedule item. auto& query = getInstance().data_.schedule.at(name); auto diff = AS_LITERAL(BIGINT_LITERAL, r1.at("user_time")) - AS_LITERAL(BIGINT_LITERAL, r0.at("user_time")); if (diff > 0) { query.user_time += diff; } diff = AS_LITERAL(BIGINT_LITERAL, r1.at("system_time")) - AS_LITERAL(BIGINT_LITERAL, r0.at("system_time")); if (diff > 0) { query.system_time += diff; } diff = AS_LITERAL(BIGINT_LITERAL, r1.at("resident_size")) - AS_LITERAL(BIGINT_LITERAL, r0.at("resident_size")); if (diff > 0) { // Memory is stored as an average of RSS changes between query executions. query.average_memory = (query.average_memory * query.executions) + diff; query.average_memory = (query.average_memory / (query.executions + 1)); } query.wall_time += delay; query.output_size += size; query.executions += 1; }
TEST_F(ConfigTests, test_queries_execute) { ConfigDataInstance config; EXPECT_EQ(config.schedule().size(), 3); }