Ignore:
Timestamp:
Sep 3, 2014, 5:42:55 PM (5 years ago)
Author:
linmengl
Message:

modify perf.py; add an interactive perf data viewer; add make target 'perf_icgrep' and 'viewer';

Location:
icGREP/icgrep-devel/performance
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/performance/ground_truth.json

    r4126 r4128  
    1717    "mark_twain": {
    1818        "_awyer_or_inn": 639,
    19         "a----b": 8584,
     19        "quoted_sentence0-30": 5540,
    2020        "....ing_": 4483,
    2121        "line16-20": 4874,
    2222        "^Twain": 100,
    23         "Huck_or_Finn_": 83,
    24         "quoted_sentence0-30": 5540,
     23        "a----b": 8584,
    2524        "Tom_near_river": 2,
    2625        "af_hnaf_hn": 61719,
     
    2827        "Twain": 2373,
    2928        "Tom_or_Huck": 2644,
     29        "Huck_or_Finn_": 83,
    3030        "___ing": 81350,
    3131        "__Tom_or_Huck": 2644,
  • icGREP/icgrep-devel/performance/perf.py

    r4126 r4128  
    11from subprocess import *
    22from collections import *
    3 import csv
    4 import StringIO
    53import os.path
    64import sys
     
    97import json
    108import re
    11 
    12 # run several times and get the average, use perf -r
     9import ipdb
     10import time
     11
     12# run several times and get the average perf data; use perf -r
    1313RUNS = 1
    1414
     
    1919ground_truth_file = 'ground_truth.json'
    2020
    21 is_verbose = False
    22 is_reground = False
    2321
    2422def escape_quotes(e):
     
    5149
    5250
     51def check_count_result(found_string, truth_number):
     52    #this regex is designed for icgrep, other program may need more regex
     53    m = re.match(r'Matching Lines:(\d+)', found_string)
     54    if m:
     55        if int(m.group(1)) != truth_number:
     56            print "Correctness check error: {0} : {1}".format(file_des, exp_des)
     57        return
     58
     59    #regex for grep
     60    m = re.match(r'(\d+)', found_string)
     61    if m:
     62        if int(m.group(1)) != truth_number:
     63            print "Correctness check error: {0} : {1}".format(file_des, exp_des)
     64        return
     65
     66    print "Warning: '{0}' and '{1}' may not match".format(found_string, truth_number)
     67
     68
    5369def execute(execution):
     70    if args.verbose:
     71        print "Executing: regex {0} on file {1}".format(execution.expression.description,
     72                                                        execution.file.description)
     73
    5474    gen_ground_truth(execution)
    5575
     
    139159    res_file = open(outputpath + '/output.txt')
    140160    found = res_file.read().strip()
    141     #this regex is designed for icgrep, other program may need more regex
    142     m = re.match(r'Matching Lines:(\d+)', found)
    143     if m:
    144         if int(m.group(1)) != ground_truth[file_des][exp_des]:
    145             print "Correctness check error: {0} : {1}".format(file_des, exp_des)
     161    check_count_result(found, ground_truth[file_des][exp_des])
    146162
    147163    return int(output[startpos:endpos])
     
    223239expressions.append(Expression(r"""["']|"|'|&#0*3[49];|&#x0*2[27];""", 'xquote', ('gml',)))
    224240
    225 
    226241#expressions.append(Expression('(^|[^A-Z0-9:])([A-F0-9]{1,4}:){7}[A-F0-9]{1,4}($|[^A-Z0-9:])', 'IPv6', ('reb',)))
    227242
    228 programs = ['icgrep']
    229 #
    230243#stats = ['cycles:u', 'instructions:u', 'cache-misses:u', 'L1-dcache-load-misses:u', 'L1-dcache-store-misses:u', 'L1-dcache-prefetch-misses:u', 'L1-icache-load-misses:u']
    231244stats = ['cycles:u','instructions:u']
    232245
    233 
    234 typeargument=False
    235 if len(sys.argv)>1:
    236         type=sys.argv[1]
    237         typeargument=True
    238 
    239 for file in files:
    240         for expression in expressions:
    241                 match = False
    242                 for type1 in file.types:
    243                         for type2 in expression.types:
    244                                 if type1 == type2:
    245                                         if typeargument:
    246                                                 if type1==type:
    247                                                         match = True
    248                                         else:
    249                                                 match = True
    250                 if match:
    251                         for program in programs:
    252                                 for stat in stats:
    253                                         executions.append(Execution(stat, program, file, expression))
    254 csv_output = StringIO.StringIO()
    255 writer = csv.writer(csv_output)
     246#init perf result, which is a dict,
     247#perf[program][file][expression][stat] = cycles/instructions etc.
     248perf = {}
    256249
    257250log_file = open('perflog.txt', 'w')
    258251log_file.close()
     252
     253def init_executions():
     254    for file in files:
     255        for expression in expressions:
     256            match = False
     257            for type1 in file.types:
     258                for type2 in expression.types:
     259                    if type1 == type2:
     260                        match = True
     261            if match:
     262                for stat in stats:
     263                    executions.append(Execution(stat, args.program,
     264                                                file, expression))
    259265
    260266if __name__ == "__main__":
     
    263269    parser.add_argument("-r", "--reground", help="regenerate groundtruth (grep) results", action="store_true")
    264270    parser.add_argument("-v", "--verbose", help="more output", action="store_true")
     271    parser.add_argument("program", help="program to test performance", choices=["icgrep", "grep", "etc."])
    265272    args = parser.parse_args()
    266     is_reground = args.reground
    267     is_verbose = args.verbose
    268 
    269     if not os.path.isfile(ground_truth_file) or is_reground:
     273
     274    if not os.path.isfile(ground_truth_file) or args.reground:
    270275        f = open(ground_truth_file,'w')
    271276        f.close()
     
    273278        ground_truth = json.load(fp = open(ground_truth_file, 'r'))
    274279
     280    init_executions()
     281
    275282    for execution in executions:
    276             calc = execute(execution)
    277             writer.writerow((execution.file.description, execution.expression.description, execution.program, execution.stat, calc))
    278 
    279     print csv_output.getvalue()
     283        calc = execute(execution)
     284
     285        file_des = execution.file.description
     286        exp_des = execution.expression.description
     287        program_des = execution.program
     288        stat = execution.stat
     289
     290        if program_des not in perf:
     291            perf[program_des] = {}
     292        if file_des not in perf[program_des]:
     293            perf[program_des][file_des] = {}
     294        if exp_des not in perf[program_des][file_des]:
     295            perf[program_des][file_des][exp_des] = {}
     296
     297        perf[program_des][file_des][exp_des][stat] = calc
    280298
    281299    #dump ground truth
    282300    json.dump(obj=ground_truth, fp=open(ground_truth_file, 'w'), indent=4, separators=(',', ': '))
     301
     302    #dump perf result
     303    print "Please input a name for perf data (press Enter to use default={0}): ".format(args.program)
     304    name = raw_input()
     305    if name.strip() == '':
     306        name = args.program
     307
     308    perf_file = name + time.strftime("-%Y%m%d-%H%M%S") + "-perf.json"
     309    json.dump(obj=perf, fp=open(perf_file, 'w'), indent =4, separators=(',', ': '))
     310    print "Perf result dumped to {0}.".format(perf_file)
  • icGREP/icgrep-devel/performance/perfoutput

    r4126 r4128  
    1 # started on Wed Sep  3 12:57:59 2014
     1# started on Wed Sep  3 17:41:16 2014
    22
    3 316528257,instructions:u
     3316228129,instructions:u
Note: See TracChangeset for help on using the changeset viewer.