updated comments, memory hog run outline.
[feisty_meow.git] / core / applications / load_test_tools / memory_hog.cpp
index a98bb168a7c75217c6b89081790ecbea241556d8..ab24468bc8be50aa708f2b5bee725ba634db7b1f 100644 (file)
@@ -38,6 +38,7 @@ using namespace unit_test;
 const int MEMORY_CHECKING_INTERVAL = 0.5 * SECOND_ms;
   // this many milliseconds elapses between checks on shutdown conditions.
 
+#define BASE_LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
   // define a macro that will send diagnostic output to the app's logger.
 
@@ -63,7 +64,7 @@ public:
   virtual int execute();
     //!< the root of the program's activity.
 
-  void print_instructions();
+  int print_instructions();
     //!< describes the available command line options for the ULS.
 
 private:
@@ -80,6 +81,27 @@ application_example::application_example()
 application_example::~application_example()
 {}
 
+int application_example::print_instructions()
+{
+  FUNCDEF("print_instructions");
+  BASE_LOG("\
+\nUsage: memory_hog {memorySize}\n\
+\n\
+  This application will consume a requested amount of memory until either\n\
+(1) the applications is interrupted or terminated, or (2) the application\n\
+is no longer given memory when it requests it (whether due to account limits\n\
+or to a lack of remaining allocatable memory), or (3) the requested amount\n\
+has been allocated.\n\
+  The application will then sit back idly and occasionally riffle through its\n\
+big bag of memory in an attempt to keep most of it in physical memory rather\n\
+than virtual memory.\n\
+  This is not a hostile act unless used unwisely; this program is intended\n\
+to get an unloaded machine into a predictable memory state.\n\
+  **DO NOT use this program without system administrator permission.**"
+);
+  return 1;
+}
+
 void application_example::handle_startup()
 {
   FUNCDEF("handle_startup");
@@ -105,11 +127,46 @@ int application_example::execute()
 
 LOG(a_sprintf("cmd line has %d entries", cmds.entries()));
 
+  if (cmds.entries() < 1) {
+    BASE_LOG("You need to provide a number on the command line....");
+    return print_instructions();
+  }
+
+  astring size_as_text = cmds.get(0).text();
+
+LOG(a_sprintf("hoo hah!  got a text thingy of: %s", size_as_text.s()));
+
+  if (size_as_text.find('.') < 0) {
+    // we don't see this as floating point, but we will move on as if it's
+    // an integer and can become floating point.
+    size_as_text += ".0";
+  }
+
+  double how_fat = size_as_text.convert(double(0.0));
+
+LOG(a_sprintf("got a number from user of: %f", how_fat));
+
+//okay, now that we've got that handled,
+// we want to have a hash table of byte arrays.
+//   int hash or whatever?  we want it indexable and fast access on a unique id.
+// that will be our consumption tactic.
+// we will allocate some chunk size in the byte arrays.  maybe max of a meg.
+// then we just add as many byte arrays as we need to to get to the requested amount.
+// don't just allocate them all at the same size; vary it a bunch, like say 20% of
+//   our maximum allotance.
+// so randomly pull memory until we get what we want.
+// if we get a memory failure, slack off until we can try to get more.
+// if we cannot get memory within certain number of failures, report this and bail out.
+//   we do not want to crash the machine.
+// once we've got our memory, start playing with it.
+// every so often,
+//   pick a random number of items to play with,
+//     go to each item (which is a byte array),
+//       pick a random segment of the byte array to look at,
+//         read the contents of the memory there.  that's it, nothing stressful.
+// repeat the memory play until forever.
+//   enhancement, allow them to provide a run time.  time out after that elapses.
 
-//  ASSERT_EQUAL(astring(class_name()), astring("application_example"),
-//      "simple application name check");
-
-//  return final_report();
   return 0;
 }