implified tests

This commit is contained in:
Kjell Hedstrom 2011-11-15 01:46:07 +01:00
parent bf2b9a622e
commit b3b5335b90
5 changed files with 115 additions and 124 deletions

View File

@ -107,20 +107,15 @@ ENDIF(WIN32)
#
#
# ---- Below g2log Performance -----
# create the the g2log MEAN_PERFORMANCE executable
add_executable(g2log-performance-mean test/main_mean.cpp test/performance.h)
set_target_properties(g2log-performance-mean PROPERTIES COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1")
target_link_libraries(g2log-performance-mean lib_activeobject lib_g2logger ${PLATFORM_LINK_LIBRIES})
# create the the g2log TWO_THREADS_MEAN_PERFORMANCE executable
add_executable(g2log-performance-2threads_mean test/main_2threads_mean.cpp test/performance.h)
set_target_properties(g2log-performance-2threads_mean PROPERTIES COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1")
target_link_libraries(g2log-performance-2threads_mean lib_activeobject lib_g2logger ${PLATFORM_LINK_LIBRIES})
add_executable(g2log-performance-threaded_mean test/main_threaded_mean.cpp test/performance.h)
set_target_properties(g2log-performance-threaded_mean PROPERTIES COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1")
target_link_libraries(g2log-performance-threaded_mean lib_activeobject lib_g2logger ${PLATFORM_LINK_LIBRIES})
# create the the g2log TWO_THREADS_WORST_CASE_PERFORMANCE executable
add_executable(g2log-performance-2threads_worst test/main_2threads_worst.cpp test/performance.h)
set_target_properties(g2log-performance-2threads_worst PROPERTIES COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1")
target_link_libraries(g2log-performance-2threads_worst lib_activeobject lib_g2logger ${PLATFORM_LINK_LIBRIES})
add_executable(g2log-performance-threaded_worst test/main_threaded_worst.cpp test/performance.h)
set_target_properties(g2log-performance-threaded_worst PROPERTIES COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1")
target_link_libraries(g2log-performance-threaded_worst lib_activeobject lib_g2logger ${PLATFORM_LINK_LIBRIES})
@ -129,24 +124,19 @@ IF(UNIX)
#
# ---- Below GOOGLE glog Performance -----
# create the the GOOGLE MEAN_PERFORMANCE executable
# Generate the DEFINE (for glog) needed to differentiate between the glog and the g2log test
add_executable(google_glog-performance-mean test/main_mean.cpp test/performance.h)
set_target_properties(google_glog-performance-mean PROPERTIES COMPILE_DEFINITIONS "GOOGLE_GLOG_PERFORMANCE=1")
target_link_libraries(google_glog-performance-mean lib_activeobject glog ${PLATFORM_LINK_LIBRIES})
add_executable(google_glog-performance-threaded_mean test/main_threaded_mean.cpp test/performance.h)
set_target_properties(google_glog-performance-threaded_mean PROPERTIES COMPILE_DEFINITIONS "GOOGLE_GLOG_PERFORMANCE=1")
target_link_libraries(google_glog-performance-threaded_mean lib_activeobject glog ${PLATFORM_LINK_LIBRIES})
# create the the GOOGLE MEAN_PERFORMANCE executable
add_executable(google_glog-performance-2threads_mean test/main_2threads_mean.cpp test/performance.h)
set_target_properties(google_glog-performance-2threads_mean PROPERTIES COMPILE_DEFINITIONS "GOOGLE_GLOG_PERFORMANCE=1")
target_link_libraries(google_glog-performance-2threads_mean lib_activeobject glog ${PLATFORM_LINK_LIBRIES})
add_executable(google_glog-performance-threaded_worst test/main_threaded_worst.cpp test/performance.h)
set_target_properties(google_glog-performance-threaded_worst PROPERTIES COMPILE_DEFINITIONS "GOOGLE_GLOG_PERFORMANCE=1")
target_link_libraries(google_glog-performance-threaded_worst lib_activeobject glog ${PLATFORM_LINK_LIBRIES})
# create the the GOOGLE MEAN_PERFORMANCE executable
add_executable(google_glog-performance-2threads_worst test/main_2threads_worst.cpp test/performance.h)
set_target_properties(google_glog-performance-2threads_worst PROPERTIES COMPILE_DEFINITIONS "GOOGLE_GLOG_PERFORMANCE=1")
target_link_libraries(google_glog-performance-2threads_worst lib_activeobject glog ${PLATFORM_LINK_LIBRIES})
# create the the TEST executable
add_executable(g2log-unit_test ../test_main/test_main.cpp test/test_io.cpp)
add_library(lib_test_logger ${LOG_SRC}/logworker.h ${LOG_SRC}/logworker.cpp ${LOG_SRC}/g2log.h ${LOG_SRC}/g2log.cpp ${LOG_SRC}/crashhandler.h ${LOG_SRC}/crashhandler.cpp)
add_library(lib_test_logger ${LOG_SRC}/logworker.h ${LOG_SRC}/logworker.cpp ${LOG_SRC}/g2log.h ${LOG_SRC}/g2log.cpp ${LOG_SRC}/crashhandler.h ${LOG_SRC}/crashhandler_unix.cpp)
set_target_properties(lib_test_logger PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(lib_test_logger PROPERTIES COMPILE_DEFINITIONS "YALLA=1")
target_link_libraries(lib_test_logger lib_activeobject)

View File

@ -1,67 +0,0 @@
/* *************************************************
// * Filename: g2log-main_mean.cpp
// * Created: 2011 by Kjell Hedström
// *
// * PUBLIC DOMAIN and Not copy-writed
// * ********************************************* */
// through CMakeLists.txt #define of GOOGLE_GLOG_PERFORMANCE and G2LOG_PERFORMANCE
#include "performance.h"
#include <thread>
#if defined(G2LOG_PERFORMANCE)
const std::string title = "G2LOG";
#elif defined(GOOGLE_GLOG_PERFORMANCE)
const std::string title = "GOOGLE__GLOG";
#else
const std::string title = not_defined_this_will_be_compiler_error;
#endif
const std::string g_prefix_log_name = title + "-performance-MEAN_LOG";
const std::string g_measurement_dump= "/tmp/" + g_prefix_log_name + "_RESULT.txt";
const std::string g_path = "/tmp/";
using namespace g2_test;
int main(int argc, char** argv)
{
std::ostringstream oss;
oss << "\n\n" << title << " performance MEAN times\n";
oss << "Running #: " << g_loop << " * " << g_iterations << " iterations of log entries" << std::endl; // worst mean case is about 10us per log entry
const size_t xtra_margin = 2;
oss << "*** It can take som time. Please wait: Approximate maximum wait time is: " << (long long) (g_iterations * 10 * xtra_margin / 1000000 ) << " seconds" << std::endl;
writeTextToFile(g_measurement_dump, oss.str(), kAppend);
oss.str(""); // clear the stream
#if defined(G2LOG_PERFORMANCE)
LogWorker* logger = new LogWorker(g_prefix_log_name, g_path);
g2::initializeLogging(logger);
#elif defined(GOOGLE_GLOG_PERFORMANCE)
google::InitGoogleLogging(argv[0]);
#endif
auto start_time = std::chrono::steady_clock::now();
doLogWrites(title);
auto application_end_time = std::chrono::steady_clock::now();
#if defined(G2LOG_PERFORMANCE)
delete logger; // will flush anything in the queue to file
#elif defined(GOOGLE_GLOG_PERFORMANCE)
google::ShutdownGoogleLogging();
#endif
auto worker_end_time = std::chrono::steady_clock::now();
auto application_time_us = std::chrono::duration_cast<microsecond>(application_end_time - start_time).count();
auto total_time_us = std::chrono::duration_cast<microsecond>(worker_end_time - start_time).count();
oss << "\n" << g_iterations << " log entries took: [" << total_time_us / 1000000 << " s] to write to disk"<< std::endl;
oss << "[Application: \t\t\t:" << application_time_us/1000 << " ms]" << std::endl;
oss << "[Background thread to finish\t:" << total_time_us/1000 << " ms]" << std::endl;
oss << "\nAverage time per log entry:" << std::endl;
oss << "[Application: " << application_time_us/g_iterations << " us]" << std::endl;
oss << "[Background+Application: " << total_time_us/g_iterations << " us]" << std::endl;
writeTextToFile(g_measurement_dump,oss.str(), kAppend);
std::cout << "Result can be found at:" << g_measurement_dump << std::endl;
return 0;
}

View File

@ -17,18 +17,34 @@ const std::string title = "GOOGLE__GLOG";
#error G2LOG_PERFORMANCE or GOOGLE_GLOG_PERFORMANCE was not defined
#endif
const std::string g_prefix_log_name = title + "-performance-2threads-MEAN_LOG";
const std::string g_measurement_dump= "/tmp/" + g_prefix_log_name + "_RESULT.txt";
const std::string g_path = "/tmp/";
using namespace g2_test;
int main(int argc, char** argv)
{
size_t number_of_threads =0;
if(argc == 2)
{
number_of_threads = atoi(argv[1]);
}
if(argc != 2 || number_of_threads == 0)
{
std::cerr << "USAGE is: " << argv[0] << " number_threads" << std::endl;
return 1;
}
std::ostringstream thread_count_oss;
thread_count_oss << number_of_threads;
const std::string g_prefix_log_name = title + "-performance-" + thread_count_oss.str() + "threads-MEAN_LOG";
const std::string g_measurement_dump= "/tmp/" + g_prefix_log_name + "_RESULT.txt";
std::ostringstream oss;
oss << "\n\n" << title << " performance 2 threads MEAN times\n";
oss << "\n\n" << title << " performance " << number_of_threads << " threads MEAN times\n";
oss << "Each thread running #: " << g_loop << " * " << g_iterations << " iterations of log entries" << std::endl; // worst mean case is about 10us per log entry
const size_t xtra_margin = 2;
oss << "*** It can take som time. Please wait: Approximate maximum wait time is: " << (long long) (g_iterations * 10 * xtra_margin / 1000000 ) << " seconds" << std::endl;
oss << "*** It can take som time. Please wait: Approximate wait time is: " <<number_of_threads* (long long) (g_iterations * 10 * xtra_margin / 1000000 ) << " seconds" << std::endl;
writeTextToFile(g_measurement_dump, oss.str(), kAppend);
oss.str(""); // clear the stream
@ -38,14 +54,26 @@ int main(int argc, char** argv)
#elif defined(GOOGLE_GLOG_PERFORMANCE)
google::InitGoogleLogging(argv[0]);
#endif
auto start_time = std::chrono::steady_clock::now();
// running both threads
std::thread t1(doLogWrites, title + "_T1");
std::thread t2(doLogWrites, title + "_T2");
t1.join();
t2.join();
std::thread* threads = new std::thread[number_of_threads];
// kiss: just loop, create threads, store them then join
// could probably do this more elegant with lambdas
for(size_t idx = 0; idx < number_of_threads; ++idx)
{
std::ostringstream count;
count << idx+1;
std::string thread_name = title + "_T" + count.str();
std::cout << "Creating thread: " << thread_name << std::endl;
threads[idx] = std::thread(doLogWrites,thread_name);
}
for(size_t idx = 0; idx < number_of_threads; ++idx)
{
threads[idx].join();
}
auto application_end_time = std::chrono::steady_clock::now();
delete [] threads;
#if defined(G2LOG_PERFORMANCE)
delete logger; // will flush anything in the queue to file
#elif defined(GOOGLE_GLOG_PERFORMANCE)
@ -60,8 +88,8 @@ int main(int argc, char** argv)
oss << "[Application(2threads):\t\t:" << application_time_us/1000 << " ms]" << std::endl;
oss << "[Background thread to finish\t:" << total_time_us/1000 << " ms]" << std::endl;
oss << "\nAverage time per log entry:" << std::endl;
oss << "[Application: " << application_time_us/g_iterations << " us]" << std::endl;
oss << "[Background+Application: " << total_time_us/g_iterations << " us]" << std::endl;
oss << "[Application: " << application_time_us/(number_of_threads*g_iterations) << " us]" << std::endl;
oss << "[Background+Application: " << total_time_us/(number_of_threads*g_iterations) << " us]" << std::endl;
writeTextToFile(g_measurement_dump,oss.str(), kAppend);
std::cout << "Result can be found at:" << g_measurement_dump << std::endl;

View File

@ -22,20 +22,37 @@ const std::string title = "GOOGLE__GLOG";
#error G2LOG_PERFORMANCE or GOOGLE_GLOG_PERFORMANCE was not defined
#endif
const std::string g_prefix_log_name = title + "-performance-2threads-WORST_LOG";
const std::string g_measurement_dump= "/tmp/" + g_prefix_log_name + "_RESULT.txt";
const std::string g_measurement_bucket_dump= "/tmp/" + g_prefix_log_name + "_RESULT_buckets.txt";
const std::string g_path = "/tmp/";
using namespace g2_test;
int main(int argc, char** argv)
{
size_t number_of_threads =0;
if(argc == 2)
{
number_of_threads = atoi(argv[1]);
}
if(argc != 2 || number_of_threads == 0)
{
std::cerr << "USAGE is: " << argv[0] << " number_threads" << std::endl;
return 1;
}
std::ostringstream thread_count_oss;
thread_count_oss << number_of_threads;
const std::string g_prefix_log_name = title + "-performance-" + thread_count_oss.str() + "threads-WORST_LOG";
const std::string g_measurement_dump= "/tmp/" + g_prefix_log_name + "_RESULT.txt";
const std::string g_measurement_bucket_dump= "/tmp/" + g_prefix_log_name + "_RESULT_buckets.txt";
std::ostringstream oss;
oss << "\n\n" << title << " performance 2 threads WORST (PEAK) times\n";
oss << "\n\n" << title << " performance " << number_of_threads << " threads WORST (PEAK) times\n";
oss << "Each thread running #: " << g_loop << " * " << g_iterations << " iterations of log entries" << std::endl; // worst mean case is about 10us per log entry
const size_t xtra_margin = 2;
oss << "*** It can take som time. Please wait: Approximate maximum wait time is: " << (long long) (g_iterations * 10 * xtra_margin / 1000000 ) << " seconds" << std::endl;
oss << "*** It can take som time. Please wait: Approximate wait time is: " << number_of_threads * (long long) (g_iterations * 10 * xtra_margin / 1000000 ) << " seconds" << std::endl;
writeTextToFile(g_measurement_dump, oss.str(), kAppend);
oss.str(""); // clear the stream
@ -46,18 +63,33 @@ int main(int argc, char** argv)
google::InitGoogleLogging(argv[0]);
#endif
std::vector<long long> t1_result;
std::vector<long long> t2_result;
t1_result.reserve(g_iterations);
t2_result.reserve(g_iterations);
std::thread* threads = new std::thread[number_of_threads];
std::vector<long long>* threads_result = new std::vector<long long>[number_of_threads];
// kiss: just loop, create threads, store them then join
// could probably do this more elegant with lambdas
for(size_t idx = 0; idx < number_of_threads; ++idx)
{
threads_result[idx].reserve(g_iterations);
}
auto start_time = std::chrono::steady_clock::now();
// running both threads
std::thread t1(measurePeakDuringLogWrites, "g2log_T1", std::ref(t1_result));
std::thread t2(measurePeakDuringLogWrites, "g2log_T2", std::ref(t2_result));
t1.join();
t2.join();
for(size_t idx = 0; idx < number_of_threads; ++idx)
{
std::ostringstream count;
count << idx+1;
std::string thread_name = title + "_T" + count.str();
std::cout << "Creating thread: " << thread_name << std::endl;
threads[idx] = std::thread(measurePeakDuringLogWrites,thread_name, std::ref(threads_result[idx]));
}
// wait for thread finishing
for(size_t idx = 0; idx < number_of_threads; ++idx)
{
threads[idx].join();
}
auto application_end_time = std::chrono::steady_clock::now();
delete [] threads;
#if defined(G2LOG_PERFORMANCE)
delete logger; // will flush anything in the queue to file
@ -70,21 +102,29 @@ int main(int argc, char** argv)
auto total_time_us = std::chrono::duration_cast<microsecond>(worker_end_time - start_time).count();
oss << "\n" << g_iterations << " log entries took: [" << total_time_us / 1000000 << " s] to write to disk"<< std::endl;
oss << "[Application(2threads+overhead time for measurement):\t" << application_time_us/1000 << " ms]" << std::endl;
oss << "[Application(" << number_of_threads << "_threads+overhead time for measurement):\t" << application_time_us/1000 << " ms]" << std::endl;
oss << "[Background thread to finish:\t\t\t\t" << total_time_us/1000 << " ms]" << std::endl;
oss << "\nAverage time per log entry:" << std::endl;
oss << "[Application: " << application_time_us/g_iterations << " us]" << std::endl;
oss << "[Application t1: worst took: " << (*std::max_element(t1_result.begin(), t1_result.end())) / 1000 << " ms]" << std::endl;
oss << "[Application t2: worst took: " << (*std::max_element(t2_result.begin(), t2_result.end())) / 1000 << " ms]" << std::endl;
oss << "[Application: " << application_time_us/(number_of_threads*g_iterations) << " us]" << std::endl;
for(size_t idx = 0; idx < number_of_threads; ++idx)
{
std::vector<long long>& t_result = threads_result[idx];
oss << "[Application t" << idx+1 << " worst took: " << (*std::max_element(t_result.begin(), t_result.end())) / 1000 << " ms]" << std::endl;
}
writeTextToFile(g_measurement_dump,oss.str(), kAppend);
std::cout << "Result can be found at:" << g_measurement_dump << std::endl;
// now split the result in buckets of 10ms each so that it's obvious how the peaks go
std::vector<long long> all_measurements;
all_measurements.reserve(t1_result.size() + t1_result.size());
all_measurements.insert(all_measurements.end(), t1_result.begin(), t1_result.end());
all_measurements.insert(all_measurements.end(), t2_result.begin(), t2_result.end());
all_measurements.reserve(g_iterations * number_of_threads);
for(size_t idx = 0; idx < number_of_threads; ++idx)
{
std::vector<long long>& t_result = threads_result[idx];
all_measurements.insert(all_measurements.end(), t_result.begin(), t_result.end());
}
delete [] threads_result; // finally get rid of them
std::sort (all_measurements.begin(), all_measurements.end());
std::map<size_t, size_t> value_amounts;
// for(long long& idx : all_measurements) --- didn't work?!