|
| 1 | +#A Python module for offline analysis of the provenance database |
| 2 | +#Executed as a script it performs some rudimentary analysis |
| 3 | +import provdb_python.provdb_interact as pdb |
| 4 | +import provdb_python.provdb_analyze as pa |
| 5 | +import pymargo |
| 6 | +from pymargo.core import Engine |
| 7 | +import json |
| 8 | +import sys |
| 9 | +import copy |
| 10 | +from cmd import Cmd |
| 11 | +import glob |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +def provdb_viz_validate(args): |
| 16 | + if(len(args) != 2): |
| 17 | + print("Arguments: <nshards> <viz output dir>") |
| 18 | + sys.exit(0) |
| 19 | + nshards = int(args[0]) |
| 20 | + viz_dir=args[1] |
| 21 | + |
| 22 | + with Engine('na+sm', pymargo.server) as engine: |
| 23 | + db = pdb.provDBinterface(engine, r'provdb.%d.unqlite', nshards) |
| 24 | + |
| 25 | + dkeys = ['rid','pid','fid','io_step'] |
| 26 | + index=pa.generateIndex(db, dkeys, 'anomalies') |
| 27 | + print(index) |
| 28 | + index_sets = {} |
| 29 | + for k in dkeys: |
| 30 | + index_sets[k] = {} |
| 31 | + for v in index[k].keys(): |
| 32 | + index_sets[k][v] = set(index[k][v]) |
| 33 | + |
| 34 | + print(index_sets) |
| 35 | + |
| 36 | + files=glob.glob("%s/pserver_output_stats_*.json" % viz_dir) |
| 37 | + |
| 38 | + fail=False |
| 39 | + for f in files: |
| 40 | + print(f) |
| 41 | + fp = open(f) |
| 42 | + v = json.load(fp) |
| 43 | + fp.close() |
| 44 | + |
| 45 | + if 'anomaly_metrics' in v: |
| 46 | + for anom_group in v['anomaly_metrics']: |
| 47 | + print(anom_group) |
| 48 | + fid=str(anom_group['fid']) |
| 49 | + pid=str(anom_group['app']) |
| 50 | + rid=str(anom_group['rank']) |
| 51 | + new_data = anom_group['new_data'] |
| 52 | + nanom=int(new_data['count']['accumulate']) |
| 53 | + iostep_start=int(new_data['first_io_step']) |
| 54 | + iostep_end=int(new_data['last_io_step']) |
| 55 | + print("%d anomalies in [%s,%s] on (%s,%s,%s)" % (nanom,iostep_start,iostep_end,pid,rid,fid)) |
| 56 | + |
| 57 | + if pid not in index_sets['pid'].keys(): |
| 58 | + print("Could not find any anomalies for this pid!") |
| 59 | + continue |
| 60 | + if rid not in index_sets['rid'].keys(): |
| 61 | + print("Could not find any anomalies for this rid!") |
| 62 | + continue |
| 63 | + if fid not in index_sets['fid'].keys(): |
| 64 | + print("Could not find any anomalies for this fid!") |
| 65 | + continue |
| 66 | + |
| 67 | + iosets = [] |
| 68 | + for i in range(iostep_start,iostep_end+1): |
| 69 | + if(str(i) in index_sets['io_step'].keys()): |
| 70 | + iosets.append(index_sets['io_step'][str(i)]) |
| 71 | + if(len(iosets)==0): |
| 72 | + print("Could not find any anomalies in this time window!") |
| 73 | + continue |
| 74 | + |
| 75 | + |
| 76 | + aset = index_sets['rid'][rid] & index_sets['fid'][fid] & index_sets['pid'][pid] |
| 77 | + acount=0 |
| 78 | + for i in iosets: |
| 79 | + bset = aset & i |
| 80 | + acount += len(bset) |
| 81 | + print("Found %d anomalies matching these keys" % acount) |
| 82 | + if acount != nanom: |
| 83 | + print("!!INVALID: Mismatch in number of anomalies: found %d, expected %d" % (acount,nanom) ) |
| 84 | + print("All anomalies in this time window:") |
| 85 | + for i in range(iostep_start,iostep_end+1): |
| 86 | + if(str(i) in index_sets['io_step'].keys()): |
| 87 | + print("IO step %d" % i) |
| 88 | + for anom in index_sets['io_step'][str(i)]: |
| 89 | + print(anom, pa.summarizeEvent(pa.getEventByID(db,index,anom))) |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + fail=True |
| 94 | + if(fail): |
| 95 | + print("Validation FAILED") |
| 96 | + else: |
| 97 | + print("Validation passed") |
| 98 | + |
| 99 | + del db |
| 100 | + engine.finalize() |
0 commit comments