int main() { cea::DebugLog::create(); cea::DebugLog::clear(); // RECS2 Powermeter //sensor1 = new cea::RecsPowerMeter("192.168.0.250"); cea::RecsPowerMeter sensor1("10.11.12.254"); // Check if the CPU share is being correctly calculated // This consist in verifying if the sum of all process share // is the same as the total CPU share if (sensor1.getStatus()) { while (1) { for (int id = 0; id < 18; id++) std::cout << id << " " << sensor1.getValue(id, 0) << " " << sensor1.getValue(id, 1) << std::endl; std::cout << std::endl << "Press ENTER to continue...\n"; getchar(); } } else std::cerr << "error: sensor could not be opened." << std::endl; cea::SensorController::storeXML(sensor1, "/tmp/recs.xml"); cea::Sensor *s; s = cea::SensorController::loadXmlFile("/tmp/recs.xml"); if (s != NULL) std::cout << s->toXml(); delete s; return 0; }
//Efectúa el ensayo completo, guardando datos en la EEPROM---------// void realizar_ensayo(void){ int i; s1 = sensor1 (); printf("s1:%ld \r",s1); delay_ms(10); s2 = sensor2 (); printf("s2:%4ld \r",s2); delay_ms(10); s3 = sensor3 (); printf("s3:%4ld \r",s3); delay_ms(10); s4 = sensor4 (); printf("s4:%4ld \r",s4); delay_ms(10); delay_ms(TIEMPO_ENTRE_LECTURAS); }
void run_redis_store_performance_tests(const bool auto_commit, const bool auto_flush, const long flush_timeout, const size_t num_readings) { try { klio::SensorFactory::Ptr sensor_factory(new klio::SensorFactory()); klio::Sensor::Ptr sensor1(sensor_factory->createSensor("sensor1", "sensor1", "Watt", "Europe/Berlin")); klio::Sensor::Ptr sensor2(sensor_factory->createSensor("sensor2", "sensor2", "Watt", "Europe/Berlin")); klio::StoreFactory::Ptr store_factory(new klio::StoreFactory()); klio::Store::Ptr store; boost::posix_time::time_duration elapsed_time; double seconds = 0; boost::posix_time::ptime time_before; boost::posix_time::ptime time_after; std::cout.precision(7); std::cout << std::fixed; try { std::cout << std::endl << "Performance Test" << std::endl; std::cout << std::endl << "Performance Test - RedisStore - " << " auto commit: " << (auto_commit ? "true" : "false") << ", auto flushing: " << (auto_flush ? "true" : "false") << std::endl; store = store_factory->create_redis_store( klio::RedisStore::DEFAULT_REDIS_HOST, klio::RedisStore::DEFAULT_REDIS_PORT, klio::RedisStore::DEFAULT_REDIS_DB, auto_commit, auto_flush, flush_timeout); if (!auto_commit) { store->start_transaction(); } time_before = boost::posix_time::microsec_clock::local_time(); store->add_sensor(sensor1); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Add 1st sensor: " << seconds << " s" << std::endl; time_before = boost::posix_time::microsec_clock::local_time(); store->add_sensor(sensor2); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Add 2nd sensor: " << seconds << " s" << std::endl; klio::TimeConverter::Ptr tc(new klio::TimeConverter()); klio::timestamp_t timestamp = tc->get_timestamp() - 1000; double reading = 23; time_before = boost::posix_time::microsec_clock::local_time(); store->add_reading(sensor1, timestamp, reading); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Add 1st reading: " << seconds << " s" << std::endl; timestamp -= 3000; time_before = boost::posix_time::microsec_clock::local_time(); store->add_reading(sensor1, timestamp, reading); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Add 2nd reading: " << seconds << " s" << std::endl; klio::readings_t readings; for (size_t i = 0; i < num_readings; i++) { timestamp = tc->get_timestamp() - i; reading = 23; klio::reading_t foo(timestamp, reading); readings.insert(foo); } time_before = boost::posix_time::microsec_clock::local_time(); store->add_readings(sensor1, readings); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Add " << num_readings << " readings: " << seconds << " s" << std::endl; if (!auto_flush) { time_before = boost::posix_time::microsec_clock::local_time(); store->flush(); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Flushing " << num_readings << " readings: " << seconds << " s" << std::endl; } if (!auto_commit) { time_before = boost::posix_time::microsec_clock::local_time(); store->commit_transaction(); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Committing " << num_readings << " readings: " << seconds << " s" << std::endl; } time_before = boost::posix_time::microsec_clock::local_time(); store->get_sensors_by_external_id(sensor1->external_id()); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Get sensors by external id: " << seconds << " s" << std::endl; time_before = boost::posix_time::microsec_clock::local_time(); store->get_all_readings(sensor1); time_after = boost::posix_time::microsec_clock::local_time(); elapsed_time = time_after - time_before; seconds = ((double) elapsed_time.total_microseconds()) / 1000000; std::cout << "Performance Test - RedisStore - " << "Get " << num_readings << " readings: " << seconds << " s" << std::endl; store->dispose(); } catch (klio::StoreException const& ex) { std::cout << "Caught invalid exception: " << ex.what() << std::endl; BOOST_FAIL("Unexpected store exception occurred during sensor test"); store->dispose(); } } catch (std::exception const& ex) { BOOST_FAIL("Unexpected exception occurred during sensor test"); } }