From 803782902528b059af519b2777a3738a7c109ed9 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 12 Oct 2008 12:30:59 +0000 Subject: [PATCH] Added option '-b' for setting the buffer size used for the scheduling analysis. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27992 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/system/kernel/time_stats.cpp | 28 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/tests/system/kernel/time_stats.cpp b/src/tests/system/kernel/time_stats.cpp index e2ce169c91..9997988b7e 100644 --- a/src/tests/system/kernel/time_stats.cpp +++ b/src/tests/system/kernel/time_stats.cpp @@ -37,6 +37,8 @@ static const char* kUsage = "the user and kernel times of all threads that ran during that time.\n" "\n" "Options:\n" + " -b - When doing scheduling analysis: the size of the buffer\n" + " used (in MB)\n" " -h, --help - Print this usage info.\n" " -o - Print the results to file .\n" " -s - Also perform a scheduling analysis over the time the\n" @@ -212,12 +214,13 @@ wait_object_to_string(scheduling_analysis_wait_object* waitObject, char* buffer, static void -do_scheduling_analysis(bigtime_t startTime, bigtime_t endTime) +do_scheduling_analysis(bigtime_t startTime, bigtime_t endTime, + size_t bufferSize) { printf("\n"); // allocate a chunk of memory for the scheduling analysis - void* buffer = malloc(SCHEDULING_ANALYSIS_BUFFER_SIZE); + void* buffer = malloc(bufferSize); if (buffer == NULL) { fprintf(stderr, "Error: Failed to allocate memory for the scheduling " "analysis.\n"); @@ -228,7 +231,7 @@ do_scheduling_analysis(bigtime_t startTime, bigtime_t endTime) // do the scheduling analysis scheduling_analysis analysis; status_t error = _kern_analyze_scheduling(startTime, endTime, buffer, - SCHEDULING_ANALYSIS_BUFFER_SIZE, &analysis); + bufferSize, &analysis); if (error != B_OK) { fprintf(stderr, "Error: Scheduling analysis failed: %s\n", strerror(error)); @@ -359,7 +362,7 @@ do_scheduling_analysis(bigtime_t startTime, bigtime_t endTime) static void do_timing_analysis(int argc, const char* const* argv, bool schedulingAnalysis, - int outFD) + int outFD, size_t bufferSize) { // gather initial usage info thread_info initialUsage[MAX_THREADS]; @@ -478,7 +481,7 @@ do_timing_analysis(int argc, const char* const* argv, bool schedulingAnalysis, } if (schedulingAnalysis) - do_scheduling_analysis(startTime, endTime); + do_scheduling_analysis(startTime, endTime, bufferSize); } @@ -487,6 +490,7 @@ main(int argc, const char* const* argv) { const char* outputFile = NULL; bool schedulingAnalysis = false; + size_t bufferSize = SCHEDULING_ANALYSIS_BUFFER_SIZE; while (true) { static struct option sLongOptions[] = { @@ -496,11 +500,20 @@ main(int argc, const char* const* argv) }; opterr = 0; // don't print errors - int c = getopt_long(argc, (char**)argv, "+ho:s", sLongOptions, NULL); + int c = getopt_long(argc, (char**)argv, "+b:ho:s", sLongOptions, NULL); if (c == -1) break; switch (c) { + case 'b': + bufferSize = atol(optarg); + if (bufferSize < 1 || bufferSize > 1024) { + fprintf(stderr, "Error: Invalid buffer size. Should be " + "between 1 and 1024 MB\n"); + exit(1); + } + bufferSize *= 1024 * 1024; + break; case 'h': print_usage_and_exit(false); break; @@ -532,7 +545,8 @@ main(int argc, const char* const* argv) } } - do_timing_analysis(argc - optind, argv + optind, schedulingAnalysis, outFD); + do_timing_analysis(argc - optind, argv + optind, schedulingAnalysis, outFD, + bufferSize); return 0; }