Browse Source

add stress level parameter to the testbench generation script

Ioannis Koutras 12 years ago
parent
commit
44c5186338
2 changed files with 49 additions and 12 deletions
  1. 1 0
      scripts/benchmark_template.c
  2. 48 12
      scripts/generate_c_testbench.py

+ 1 - 0
scripts/benchmark_template.c

@@ -1,4 +1,5 @@
 #include <dmmlib/dmmlib.h>
 #include <dmmlib/dmmlib.h>
+#include <dmmlib/debug.h>
 #include <string.h>
 #include <string.h>
 
 
 int main(void) {
 int main(void) {

+ 48 - 12
scripts/generate_c_testbench.py

@@ -5,7 +5,7 @@ import re
 import random
 import random
 import string
 import string
 
 
-def parse_memory_trace(input_file, output_file):
+def parse_memory_trace(input_file, stress_level, output_file):
     active_memory_requests = {}
     active_memory_requests = {}
 
 
     malloc_pattern = re.compile(r'dmmlib - m (0x\w+) (\d+)')
     malloc_pattern = re.compile(r'dmmlib - m (0x\w+) (\d+)')
@@ -22,8 +22,12 @@ def parse_memory_trace(input_file, output_file):
                 output_file.write(variable_declaration)
                 output_file.write(variable_declaration)
             new_line = ''.join(['    var_', active_memory_requests[malloc_match.group(1)], ' = malloc(', malloc_match.group(2), ');\n'])
             new_line = ''.join(['    var_', active_memory_requests[malloc_match.group(1)], ' = malloc(', malloc_match.group(2), ');\n'])
             output_file.write(new_line)
             output_file.write(new_line)
-            new_line = ''.join(['    var_', active_memory_requests[malloc_match.group(1)], ' = memset(var_', active_memory_requests[malloc_match.group(1)], ', 0, ', malloc_match.group(2), ');\n'])
-            output_file.write(new_line)
+            if stress_level > 0:
+                new_line = ''.join(['    var_', active_memory_requests[malloc_match.group(1)], ' = memset(var_', active_memory_requests[malloc_match.group(1)], ', 0, ', malloc_match.group(2), ');\n'])
+                output_file.write(new_line)
+            if stress_level > 1:
+                new_line = ''.join(['    get_raw_blocks(&systemallocator);\n'])
+                output_file.write(new_line)
 
 
         realloc_match = realloc_pattern.search(line)
         realloc_match = realloc_pattern.search(line)
         if realloc_match:
         if realloc_match:
@@ -31,10 +35,22 @@ def parse_memory_trace(input_file, output_file):
                 active_memory_requests[realloc_match.group(2)] = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
                 active_memory_requests[realloc_match.group(2)] = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
                 variable_declaration = ''.join(['    void *var_', active_memory_requests[realloc_match.group(2)], ';\n'])
                 variable_declaration = ''.join(['    void *var_', active_memory_requests[realloc_match.group(2)], ';\n'])
                 output_file.write(variable_declaration)
                 output_file.write(variable_declaration)
-            new_line = ''.join(['    var_', active_memory_requests[realloc_match.group(2)], ' = realloc(', realloc_match.group(1), ', ', realloc_match.group(3), ');\n'])
-            output_file.write(new_line)
-            new_line = ''.join(['    var_', active_memory_requests[realloc_match.group(2)], ' = memset(var_', active_memory_requests[realloc_match.group(2)], ', 0, ', realloc_match.group(3), ');\n'])
+            new_line = ''.join(['    var_',
+                active_memory_requests[realloc_match.group(2)],
+                ' = realloc(var_',
+                active_memory_requests[realloc_match.group(1)], ', ',
+                realloc_match.group(3), ');\n'])
             output_file.write(new_line)
             output_file.write(new_line)
+            if stress_level > 0:
+                new_line = ''.join(['    var_',
+                    active_memory_requests[realloc_match.group(2)],
+                    ' = memset(var_',
+                    active_memory_requests[realloc_match.group(2)], ', 0, ',
+                    realloc_match.group(3), ');\n'])
+                output_file.write(new_line)
+            if stress_level > 1:
+                new_line = ''.join(['    get_raw_blocks(&systemallocator);\n'])
+                output_file.write(new_line)
 
 
         memalign_match = memalign_pattern.search(line)
         memalign_match = memalign_pattern.search(line)
         if memalign_match:
         if memalign_match:
@@ -44,8 +60,12 @@ def parse_memory_trace(input_file, output_file):
                 output_file.write(variable_declaration)
                 output_file.write(variable_declaration)
             new_line = ''.join(['    posix_memalign(&var_', active_memory_requests[memalign_match.group(1)], ', ', memalign_match.group(2), ', ', memalign_match.group(3), ');\n'])
             new_line = ''.join(['    posix_memalign(&var_', active_memory_requests[memalign_match.group(1)], ', ', memalign_match.group(2), ', ', memalign_match.group(3), ');\n'])
             output_file.write(new_line)
             output_file.write(new_line)
-            new_line = ''.join(['    var_', active_memory_requests[memalign_match.group(1)], ' = memset(var_', active_memory_requests[memalign_match.group(1)], ', 0, ', memalign_match.group(3), ');\n'])
-            output_file.write(new_line)
+            if stress_level > 0:
+                new_line = ''.join(['    var_', active_memory_requests[memalign_match.group(1)], ' = memset(var_', active_memory_requests[memalign_match.group(1)], ', 0, ', memalign_match.group(3), ');\n'])
+                output_file.write(new_line)
+            if stress_level > 1:
+                new_line = ''.join(['    get_raw_blocks(&systemallocator);\n'])
+                output_file.write(new_line)
 
 
         free_match = free_pattern.search(line)
         free_match = free_pattern.search(line)
         if free_match:
         if free_match:
@@ -53,6 +73,9 @@ def parse_memory_trace(input_file, output_file):
                 new_line = ''.join(['    free(var_', active_memory_requests[free_match.group(1)], ');\n'])
                 new_line = ''.join(['    free(var_', active_memory_requests[free_match.group(1)], ');\n'])
                 del active_memory_requests[free_match.group(1)]
                 del active_memory_requests[free_match.group(1)]
                 output_file.write(new_line)
                 output_file.write(new_line)
+                if stress_level > 1:
+                    new_line = ''.join(['    get_raw_blocks(&systemallocator);\n'])
+                    output_file.write(new_line)
             else:
             else:
                 print "Warning: free call without an actual allocation beforehands"
                 print "Warning: free call without an actual allocation beforehands"
 
 
@@ -60,11 +83,15 @@ def parse_memory_trace(input_file, output_file):
 
 
 def main():
 def main():
     parser = argparse.ArgumentParser(
     parser = argparse.ArgumentParser(
-        description='''Generate a C file of dynamic memory operations from a dmmlib
-            trace''')
+        description='''Generate a C file of dynamic memory operations from a
+            dmmlib trace''')
     parser.add_argument('tracefile', type=argparse.FileType('rt'),
     parser.add_argument('tracefile', type=argparse.FileType('rt'),
         help='dmmlib trace from the application')
         help='dmmlib trace from the application')
-    parser.add_argument('-o', '--output', metavar='outputfile', type=argparse.FileType('wt'),
+    parser.add_argument('-s', '--stress', metavar='stresslevel',
+        type=int,
+        help='stress level, 0 for none, 1 for data and 2 for data and metadata')
+    parser.add_argument('-o', '--output', metavar='outputfile',
+        type=argparse.FileType('wt'),
         help='generated C file, will use output.c if not available')
         help='generated C file, will use output.c if not available')
 
 
     try:
     try:
@@ -75,10 +102,19 @@ def main():
     if args.output is None:
     if args.output is None:
         args.output = open('output.c', 'wt')
         args.output = open('output.c', 'wt')
 
 
+    if args.stress is None:
+        args.stress = 0
+
+    if args.stress < 0:
+        args.stress = 0
+
+    if args.stress > 2:
+        args.stress = 2
+
     template_file = open('benchmark_template.c', 'rt')
     template_file = open('benchmark_template.c', 'rt')
     for line in template_file:
     for line in template_file:
         if line == '$instructions\n':
         if line == '$instructions\n':
-            parse_memory_trace(args.tracefile, args.output)
+            parse_memory_trace(args.tracefile, args.stress, args.output)
         else:
         else:
             args.output.write(line)
             args.output.write(line)