feisty meow concerns codebase 2.140
time_running_app.cpp
Go to the documentation of this file.
1/*
2 * Name : time_running_app
3 * Author : Chris Koeritz
4 * Purpose:
5 *
6 * A simple test of how long it takes to run a fairly heavy application.
7 *
8 * Copyright (c) 2003-$now By Author. This program is free software; you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either version 2 of
11 * the License or (at your option) any later version. This is online at:
12 * http://www.fsf.org/copyleft/gpl.html
13 * Please send any updates to: fred@gruntose.com
14 */
15
16#include <basis/astring.h>
17#include <basis/environment.cpp>
18#include <basis/functions.h>
19#include <structures/set.h>
20#include <timely/time_stamp.h>
23#include <loggers/file_logger.h>
25
26#include <stdio.h>
27
28#ifdef __WIN32__
29 #include <io.h>
30#endif
31
32using namespace application;
33using namespace basis;
34using namespace loggers;
35using namespace filesystem;
36using namespace textual;
37using namespace timely;
38
39#undef BASE_LOG
40#define BASE_LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
41#undef LOG
42#define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
43
44class time_running_app : public application_shell
45{
46public:
47 time_running_app() : application_shell() {}
48 DEFINE_CLASS_NAME("time_running_app");
49 int execute();
50};
51
52int time_running_app::execute()
53{
54 FUNCDEF("execute");
56
57 int test_runs = 10000;
58
59 time_stamp start; // start of test.
60 astring bins = environment::get("$FEISTY_MEOW_BINARIES");
61 astring app = bins + "/example_application";
62 // save real stdout.
63 int real_stdout = dup(1);
64 // dump app's output.
65 freopen("/dev/null", "w", stdout);
66 for (int i = 0; i < test_runs; i++) {
67 // run the app; sorry about the relative path; change to this dir first.
68 int ret = system(app.s());
69 if (ret != 0) {
70 // restore real stdout.
71 dup2(real_stdout, 1);
72 LOG(astring("got an error running the app: ") + app);
73 exit(1);
74 }
75 }
76 time_stamp completion_time; // end of test.
77 // restore real stdout.
78 dup2(real_stdout, 1);
79
80 double durat = completion_time.value() - start.value();
81 double secs = durat / 1000.0; // convert to seconds.
82 LOG(a_sprintf("test run took %0.2f milliseconds or %0.2f seconds or %0.2f minutes.", durat, secs, secs / 60.0));
83 LOG(a_sprintf("individual call takes %0.0f milliseconds.", durat / double(test_runs)));
84
85 return 0;
86}
87
88HOOPLE_MAIN(time_running_app, )
89
90#ifdef __BUILD_STATIC_APPLICATION__
91 // static dependencies found by buildor_gen_deps.sh:
92 #include <algorithms/sorts.cpp>
97 #include <basis/astring.cpp>
99 #include <basis/environment.cpp>
100 #include <basis/guards.cpp>
101 #include <basis/mutex.cpp>
102 #include <basis/utf_conversion.cpp>
110 #include <filesystem/directory.cpp>
111 #include <filesystem/filename.cpp>
112 #include <loggers/combo_logger.cpp>
115 #include <loggers/file_logger.cpp>
118 #include <structures/checksums.cpp>
125 #include <textual/parser_bits.cpp>
127 #include <timely/earth_time.cpp>
128 #include <timely/time_stamp.cpp>
129#endif // __BUILD_STATIC_APPLICATION__
130
#define dup2
Definition Xos2defs.h:16
#define dup
Definition Xos2defs.h:15
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
application_shell()
constructs an application_shell to serve as the root of the program.
a_sprintf is a specialization of astring that provides printf style support.
Definition astring.h:440
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
Definition astring.h:113
static astring get(const astring &variable_name)
looks up the "variable_name" in the current environment variables.
Represents a point in time relative to the operating system startup time.
Definition time_stamp.h:38
time_representation value() const
returns the time_stamp in terms of the lower level type.
Definition time_stamp.h:61
#define SETUP_COMBO_LOGGER
a macro that retasks the program-wide logger as a combo_logger.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
#include <time.h>
#define LOG(to_print)