#!/usr/bin/env python3
import sys
import re

def remove_find(regex, s):
    '''removes content in *match* object from string *s*
    
    returns string without find'''
    m = re.search(regex, s)
    if m:
        start,end = m.span()
        return (s[:start]+s[end:]).strip()
    return s.strip()

if __name__ == '__main__':
    # 1. test arguments
    args = ' '.join(sys.argv[1:])
    
    args = remove_find(r'-O -g (:?CLOCK|MEM) -[cC] S0:0', args)
    args = remove_find(r'-m', args)
    args = remove_find(r'[a-zA-Z\-0-9/\._]+\.likwid_marked(:? [0-9]+(:?\.[0-9]+)?)+$', args)
    args = remove_find(r'-f', args)
    
    if len(args) > 0:
        print('Could not remove all arguments. Remaining:', args)
        sys.exit(1)
    
    # 2. return static output
    # From phinally$ likwid-perfctr -f -O -g MEM -C S0:0 -m 
    #                examples/kernels/2d-5pt.likwid_marked 1000 1000 10.0
    print('''STATIC DUMMY STATIC DUMMY STATIC DUMMY
--------------------------------------------------------------------------------
CPU name:       Intel(R) Xeon(R) CPU E5-2660 v2 @ 2.20GHz
CPU type:       Intel Xeon IvyBridge EN/EP/EX processor
CPU stepping:   4
********************************************************************************
Hardware Thread Topology
********************************************************************************
Sockets:                2
Cores per socket:       10
Threads per core:       2
--------------------------------------------------------------------------------
HWThread        Thread          Core            Socket          Available
0               0               0               0               *
1               0               1               0               *
2               0               2               0               *
3               0               3               0               *
4               0               4               0               *
5               0               8               0               *
6               0               9               0               *
7               0               10              0               *
8               0               11              0               *
9               0               12              0               *
10              0               0               1               *
11              0               1               1               *
12              0               2               1               *
13              0               3               1               *
14              0               4               1               *
15              0               8               1               *
16              0               9               1               *
17              0               10              1               *
18              0               11              1               *
19              0               12              1               *
20              1               0               0               *
21              1               1               0               *
22              1               2               0               *
23              1               3               0               *
24              1               4               0               *
25              1               8               0               *
26              1               9               0               *
27              1               10              0               *
28              1               11              0               *
29              1               12              0               *
30              1               0               1               *
31              1               1               1               *
32              1               2               1               *
33              1               3               1               *
34              1               4               1               *
35              1               8               1               *
36              1               9               1               *
37              1               10              1               *
38              1               11              1               *
39              1               12              1               *
--------------------------------------------------------------------------------
Socket 0:               ( 0 20 1 21 2 22 3 23 4 24 5 25 6 26 7 27 8 28 9 29 )
Socket 1:               ( 10 30 11 31 12 32 13 33 14 34 15 35 16 36 17 37 18 38 19 39 )
--------------------------------------------------------------------------------
********************************************************************************
Cache Topology
********************************************************************************
Level:                  1
Size:                   32 kB
Cache groups:           ( 0 20 ) ( 1 21 ) ( 2 22 ) ( 3 23 ) ( 4 24 ) ( 5 25 ) ( 6 26 ) ( 7 27 ) ( 8 28 ) ( 9 29 ) ( 10 30 ) ( 11 31 ) ( 12 32 ) ( 13 33 ) ( 14 34 ) ( 15 35 ) ( 16 36 ) ( 17 37 ) ( 18 38 ) ( 19 39 )
--------------------------------------------------------------------------------
Level:                  2
Size:                   256 kB
Cache groups:           ( 0 20 ) ( 1 21 ) ( 2 22 ) ( 3 23 ) ( 4 24 ) ( 5 25 ) ( 6 26 ) ( 7 27 ) ( 8 28 ) ( 9 29 ) ( 10 30 ) ( 11 31 ) ( 12 32 ) ( 13 33 ) ( 14 34 ) ( 15 35 ) ( 16 36 ) ( 17 37 ) ( 18 38 ) ( 19 39 )
--------------------------------------------------------------------------------
Level:                  3
Size:                   25 MB
Cache groups:           ( 0 20 1 21 2 22 3 23 4 24 5 25 6 26 7 27 8 28 9 29 ) ( 10 30 11 31 12 32 13 33 14 34 15 35 16 36 17 37 18 38 19 39 )
--------------------------------------------------------------------------------
********************************************************************************
NUMA Topology
********************************************************************************
NUMA domains:           2
--------------------------------------------------------------------------------
Domain:                 0
Processors:             ( 0 20 1 21 2 22 3 23 4 24 5 25 6 26 7 27 8 28 9 29 )
Distances:              10 21
Free memory:            29023.3 MB
Total memory:           32734.2 MB
--------------------------------------------------------------------------------
Domain:                 1
Processors:             ( 10 30 11 31 12 32 13 33 14 34 15 35 16 36 17 37 18 38 19 39 )
Distances:              21 10
Free memory:            30676.9 MB
Total memory:           32768 MB
--------------------------------------------------------------------------------
STATIC DUMMY STATIC DUMMY STATIC DUMMY''')

    # 3. exit with 0
    sys.exit(0)