a98bb168a7c75217c6b89081790ecbea241556d8
[feisty_meow.git] / core / applications / load_test_tools / memory_hog.cpp
1 //////////////
2 // Name   : memory_hog
3 // Author : Chris Koeritz
4 //////////////
5 // Copyright (c) 2012-$now By Author.  This program is free software; you can
6 // redistribute it and/or modify it under the terms of the GNU General Public
7 // License as published by the Free Software Foundation:
8 //     http://www.gnu.org/licenses/gpl.html
9 // or under the terms of the GNU Library license:
10 //     http://www.gnu.org/licenses/lgpl.html
11 // at your preference.  Those licenses describe your legal rights to this
12 // software, and no other rights or warranties apply.
13 // Please send updates for this code to: fred@gruntose.com -- Thanks, fred.
14 //////////////
15
16 //! This application lives to grub up lots of memory.
17 /*!
18   You can specify how much memory the application should consume.
19   Occasionally it will riffle through its hamstered away memory to try to
20   ensure that it stays in real memory rather than virtual memory.
21 */
22
23 #include <application/hoople_main.h>
24 #include <application/command_line.h>
25 #include <application/singleton_application.h>
26 #include <basis/enhance_cpp.h>
27 #include <loggers/program_wide_logger.h>
28 #include <structures/static_memory_gremlin.h>
29 #include <unit_test/unit_base.h>
30
31 using namespace application;
32 using namespace basis;
33 using namespace loggers;
34 //using namespace processes;
35 using namespace structures;
36 using namespace unit_test;
37
38 const int MEMORY_CHECKING_INTERVAL = 0.5 * SECOND_ms;
39   // this many milliseconds elapses between checks on shutdown conditions.
40
41 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
42   // define a macro that will send diagnostic output to the app's logger.
43
44 //////////////
45
46 class application_example : virtual public unit_base, virtual public application_shell
47 {
48 public:
49   application_example();
50   ~application_example();
51
52   DEFINE_CLASS_NAME("application_example");
53
54   virtual void handle_timer();
55     //!< called by timer events from anchor window.
56
57   virtual void handle_startup();
58     //!< begins our service's activity.
59
60   virtual void handle_shutdown();
61     //!< catches the graceful shutdown so our objects get closed normally.
62
63   virtual int execute();
64     //!< the root of the program's activity.
65
66   void print_instructions();
67     //!< describes the available command line options for the ULS.
68
69 private:
70   singleton_application _app_lock;  //!< our inter-application synchronizer.
71 };
72
73 //////////////
74
75 application_example::application_example()
76 : application_shell(),
77   _app_lock(static_class_name())
78 {}
79
80 application_example::~application_example()
81 {}
82
83 void application_example::handle_startup()
84 {
85   FUNCDEF("handle_startup");
86   LOG("starting up now.");
87 }
88
89 void application_example::handle_shutdown()
90 {
91   FUNCDEF("handle_shutdown");
92   LOG("shutting down now.");
93 }
94
95 void application_example::handle_timer()
96 {
97   FUNCDEF("handle_timer");
98   LOG("timer blip.");
99 }
100
101 int application_example::execute()
102 {
103   FUNCDEF("execute");
104   command_line cmds(_global_argc, _global_argv);
105
106 LOG(a_sprintf("cmd line has %d entries", cmds.entries()));
107
108
109 //  ASSERT_EQUAL(astring(class_name()), astring("application_example"),
110 //      "simple application name check");
111
112 //  return final_report();
113   return 0;
114 }
115
116 //////////////
117
118 HOOPLE_MAIN(application_example, )
119