From: Chris Koeritz Date: Fri, 20 Jan 2012 04:17:54 +0000 (-0500) Subject: updated comments, memory hog run outline. X-Git-Tag: 2.140.90~1656^2~33 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=38bc4d6f3bb72ca72a984430552fd85ce06a074a;p=feisty_meow.git updated comments, memory hog run outline. --- diff --git a/core/applications/example_application/example_application.cpp b/core/applications/example_application/example_application.cpp index 767b4530..f82f2f78 100644 --- a/core/applications/example_application/example_application.cpp +++ b/core/applications/example_application/example_application.cpp @@ -65,8 +65,8 @@ public: virtual int execute(); //!< the root of the program's activity. - void print_instructions(); - //!< describes the available command line options for the ULS. + int print_instructions() { LOG("no instructions at this time."); return 1; } + //!< describes the available command line options for this program. private: singleton_application _app_lock; //!< our inter-application synchronizer. diff --git a/core/applications/load_test_tools/memory_hog.cpp b/core/applications/load_test_tools/memory_hog.cpp index a98bb168..ab24468b 100644 --- a/core/applications/load_test_tools/memory_hog.cpp +++ b/core/applications/load_test_tools/memory_hog.cpp @@ -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; } diff --git a/core/library/application/command_line.h b/core/library/application/command_line.h index 4addb392..989aac5d 100644 --- a/core/library/application/command_line.h +++ b/core/library/application/command_line.h @@ -88,9 +88,12 @@ class command_line public: command_line(int argc, char *argv[]); //!< takes command line parameters in the form of "argc" and "argv". - /*!< this is suitable for most C++ main programs. the first "argv" - string (element zero) is ignored because it is assumed that it is the program name. - these become available in the global variables _global_argc and _global_argv. */ + /*!< this is suitable for most C++ main programs. the first "argv" string (element zero) is + ignored because it is assumed that it is the program name. that means that the array of + command parameters here will be (argc - 1) in length, and that index zero of our array has + the first "real" parameter that was passed to the program (i.e., not it's name). + note that the unaltered command parameters of argc and argv become available in the global + variables _global_argc and _global_argv. */ command_line(const basis::astring &to_parse); //!< takes a string form of the command line.