From: Chris Koeritz Date: Thu, 10 Oct 2013 15:54:11 +0000 (-0400) Subject: handy timing apps for set effective user id and launching an application. X-Git-Tag: 2.140.90~906 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=5db4e2efe637e314bf1e54610a0d0ae3458be322;p=feisty_meow.git handy timing apps for set effective user id and launching an application. --- diff --git a/nucleus/applications/utilities/makefile b/nucleus/applications/utilities/makefile index 3b24f7a4..bb32d469 100644 --- a/nucleus/applications/utilities/makefile +++ b/nucleus/applications/utilities/makefile @@ -9,7 +9,7 @@ ifeq "$(OMIT_VERSIONS)" "" endif LOCAL_LIBS_USED = application basis configuration filesystem loggers mathematics nodes processes textual timely structures TARGETS = await_app_exit.exe bytedump.exe checker.exe dirtree.exe ini_edit.exe mdate.exe \ - splitter.exe + splitter.exe time_set_effective_id.exe time_running_app.exe include cpp/rules.def diff --git a/nucleus/applications/utilities/time_running_app.cpp b/nucleus/applications/utilities/time_running_app.cpp new file mode 100644 index 00000000..7e61906b --- /dev/null +++ b/nucleus/applications/utilities/time_running_app.cpp @@ -0,0 +1,89 @@ +/* + * Name : time_running_app + * Author : Chris Koeritz + * Purpose: + * + * A simple test of how long it takes to run a fairly heavy application. + * + * Copyright (c) 2003-$now By Author. This program is free software; you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either version 2 of + * the License or (at your option) any later version. This is online at: + * http://www.fsf.org/copyleft/gpl.html + * Please send any updates to: fred@gruntose.com + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace application; +using namespace basis; +using namespace loggers; +using namespace filesystem; +using namespace textual; +using namespace timely; + +#undef BASE_LOG +#define BASE_LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print)) +#undef LOG +#define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(to_print)) + +class time_running_app : public application_shell +{ +public: + time_running_app() : application_shell() {} + DEFINE_CLASS_NAME("time_running_app"); + int execute(); +}; + +int time_running_app::execute() +{ + FUNCDEF("execute"); + SETUP_COMBO_LOGGER; + + int test_runs = 10000; + + time_stamp start; // start of test. + astring bins = environment::get("FEISTY_MEOW_DIR") + "/production/binaries"; + astring app = bins + "/example_application"; + // save real stdout. + int real_stdout = dup(1); + // dump app's output. + freopen("/dev/null", "w", stdout); + for (int i = 0; i < test_runs; i++) { + // run the app; sorry about the relative path; change to this dir first. + int ret = system(app.s()); + if (ret != 0) { + // restore real stdout. + dup2(real_stdout, 1); + LOG(astring("got an error running the app: ") + app); + exit(1); + } + } + time_stamp completion_time; // end of test. + // restore real stdout. + dup2(real_stdout, 1); + + double durat = completion_time.value() - start.value(); + double secs = durat / 1000.0; // convert to seconds. + LOG(a_sprintf("test run took %0.2f milliseconds or %0.2f seconds or %0.2f minutes.", durat, secs, secs / 60.0)); + LOG(a_sprintf("individual call takes %0.0f milliseconds.", durat / double(test_runs))); + + return 0; +} + +HOOPLE_MAIN(time_running_app, ) + +#ifdef __BUILD_STATIC_APPLICATION__ + // static dependencies found by buildor_gen_deps.sh: +#endif // __BUILD_STATIC_APPLICATION__ + diff --git a/nucleus/applications/utilities/time_set_effective_id.cpp b/nucleus/applications/utilities/time_set_effective_id.cpp new file mode 100644 index 00000000..21a7c59d --- /dev/null +++ b/nucleus/applications/utilities/time_set_effective_id.cpp @@ -0,0 +1,84 @@ +/* + * Name : time_set_effective_id + * Author : Chris Koeritz + * Purpose: + * + * A simple test of how long it takes to call set effective id on Unix. + * For this to really work as designed, it should be run as root. + * + * Copyright (c) 2003-$now By Author. This program is free software; you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either version 2 of + * the License or (at your option) any later version. This is online at: + * http://www.fsf.org/copyleft/gpl.html + * Please send any updates to: fred@gruntose.com + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace application; +using namespace basis; +using namespace loggers; +using namespace filesystem; +using namespace textual; +using namespace timely; + +#undef BASE_LOG +#define BASE_LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print)) +#undef LOG +#define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(to_print)) + +class time_set_effective_id : public application_shell +{ +public: + time_set_effective_id() : application_shell() {} + DEFINE_CLASS_NAME("time_set_effective_id"); + int execute(); +}; + +int time_set_effective_id::execute() +{ + FUNCDEF("execute"); + SETUP_COMBO_LOGGER; + + int test_runs = 1000000; + + time_stamp start; // start of test. + for (int i = 0; i < test_runs; i++) { + // set effective id to fred. + int ret = seteuid(1008); + if (ret != 0) { + LOG("failure to change effective user id to normal user."); + exit(1); + } + // set effective id to root. + ret = seteuid(0); + if (ret != 0) { + LOG("failure to change effective user id to root."); + exit(1); + } + } + time_stamp completion_time; // end of test. + + double durat = completion_time.value() - start.value(); + double secs = durat / 1000.0; // convert to seconds. + LOG(a_sprintf("test run took %0.2f milliseconds or %0.2f seconds or %0.2f minutes.", durat, secs, secs / 60.0)); + // divide by two because we're doing two calls above. + LOG(a_sprintf("individual call takes %0.0f milliseconds.", durat / double(test_runs) / 2.0)); + + return 0; +} + +HOOPLE_MAIN(time_set_effective_id, ) + +#ifdef __BUILD_STATIC_APPLICATION__ + // static dependencies found by buildor_gen_deps.sh: +#endif // __BUILD_STATIC_APPLICATION__ +