handy timing apps for set effective user id and launching an application.
authorChris Koeritz <fred@gruntose.com>
Thu, 10 Oct 2013 15:54:11 +0000 (11:54 -0400)
committerChris Koeritz <fred@gruntose.com>
Thu, 10 Oct 2013 15:54:11 +0000 (11:54 -0400)
nucleus/applications/utilities/makefile
nucleus/applications/utilities/time_running_app.cpp [new file with mode: 0644]
nucleus/applications/utilities/time_set_effective_id.cpp [new file with mode: 0644]

index 3b24f7a4127132434d66e74665f01970f9394f12..bb32d46935104ad8fa2dfd2e24082188317efd9d 100644 (file)
@@ -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 (file)
index 0000000..7e61906
--- /dev/null
@@ -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 <basis/astring.h>
+#include <basis/environment.cpp>
+#include <basis/functions.h>
+#include <structures/set.h>
+#include <timely/time_stamp.h>
+#include <application/hoople_main.h>
+#include <loggers/console_logger.h>
+#include <loggers/file_logger.h>
+#include <structures/static_memory_gremlin.h>
+
+#include <stdio.h>
+
+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 (file)
index 0000000..21a7c59
--- /dev/null
@@ -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 <basis/functions.h>
+#include <basis/astring.h>
+#include <structures/set.h>
+#include <timely/time_stamp.h>
+#include <application/hoople_main.h>
+#include <loggers/console_logger.h>
+#include <loggers/file_logger.h>
+#include <structures/static_memory_gremlin.h>
+
+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__
+