File indexing completed on 2026-11-09 10:47:25
0001
0002 """segfault-study-auto.py — the nightly automatic study of traced signatures.
0003
0004 A traced signature that no finding reads and no study has been asked of
0005 is studied once, largest first, at most --limit a night, without
0006 waiting for a reproduction (swf-epicprod docs/SEGFAULT_DIAGNOSIS.md,
0007 Diagnosis; a reproduced signature is queued by the reconciliation). A
0008 frame a finding already reads is marked covered instead of studied. The
0009 study itself is the Diagnose message to the ops agent, whose trigger
0010 records the run on the signature.
0011
0012 Django-bootstrap standalone script, by hand::
0013
0014 cd /data/wenauseic/github/swf-monitor/src
0015 ../../swf-testbed/.venv/bin/python ../scripts/segfault-study-auto.py [--limit N] [--dry-run]
0016
0017 Prints one JSON line: the keys queued and the keys marked covered.
0018 """
0019 import argparse
0020 import json
0021 import os
0022 import sys
0023
0024 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0025 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0026 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0027
0028 import django
0029 django.setup()
0030
0031 from monitor_app.models import CrashSignature
0032 from monitor_app.segfaults import covering_finding, queue_traced_studies
0033
0034
0035 def main():
0036 ap = argparse.ArgumentParser(description=__doc__.split('\n\n')[0])
0037 ap.add_argument('--limit', type=int, default=3, help='studies queued per night')
0038 ap.add_argument('--dry-run', action='store_true', help='list the candidates, queue nothing')
0039 args = ap.parse_args()
0040 if args.dry_run:
0041 rows = []
0042 for sig in (CrashSignature.objects.filter(level='record')
0043 .exclude(status__in=('diagnosed', 'handed_off', 'fixed', 'accepted'))
0044 .order_by('-crashes')):
0045 if (sig.trace or {}).get('trace_status') != 'found' or (sig.data or {}).get('diagnosis'):
0046 continue
0047 f = covering_finding(sig)
0048 rows.append({'key': sig.key, 'crashes': sig.crashes,
0049 'frame': (sig.trace or {}).get('frame', '')[:60],
0050 'covered_by': f['fid'] if f else ''})
0051 print(json.dumps({'dry_run': True, 'candidates': rows, 'limit': args.limit}))
0052 return 0
0053 result = queue_traced_studies(args.limit)
0054 print(json.dumps(result))
0055 return 0
0056
0057
0058 if __name__ == '__main__':
0059 sys.exit(main())