Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/perf/process_stat_array.py

    rd00ce99 rb1a2c4a  
    11#!/usr/bin/python3
    22
    3 import argparse, json, math, os, sys, re
    4 from PIL import Image
    5 import numpy as np
     3import argparse, os, sys, re
    64
    75def dir_path(string):
     
    1311parser = argparse.ArgumentParser()
    1412parser.add_argument('--path', type=dir_path, default=".cfadata", help= 'paste path to biog.txt file')
    15 parser.add_argument('--out', type=argparse.FileType('w'), default=sys.stdout)
    1613
    1714try :
     
    2623counters = {}
    2724
    28 max_cpu = 0
    29 min_cpu = 1000000
    30 max_tsc = 0
    31 min_tsc = 18446744073709551615
    32 
    3325#open the files
    3426for filename in filenames:
     
    3931                with open(os.path.join(root, filename), 'r') as file:
    4032                        for line in file:
    41                                 raw = [int(x.strip()) for x in line.split(',')]
    42 
    43                                 ## from/to
    44                                 high = (raw[1] >> 32)
    45                                 low  = (raw[1] & 0xffffffff)
    46                                 data = [me, raw[0], high, low]
    47                                 max_cpu = max(max_cpu, high, low)
    48                                 min_cpu = min(min_cpu, high, low)
    49 
    50                                 ## number
    51                                 # high = (raw[1] >> 8)
    52                                 # low  = (raw[1] & 0xff)
    53                                 # data = [me, raw[0], high, low]
    54                                 # max_cpu = max(max_cpu, low)
    55                                 # min_cpu = min(min_cpu, low)
    56 
    57 
    58                                 max_tsc = max(max_tsc, raw[0])
    59                                 min_tsc = min(min_tsc, raw[0])
     33                                # data = [int(x.strip()) for x in line.split(',')]
     34                                data = [int(line.strip())]
     35                                data = [me, *data]
    6036                                merged.append(data)
    6137
    62         except Exception as e:
    63                 print(e)
     38        except:
    6439                pass
    6540
    66 
    67 print({"max-cpu": max_cpu, "min-cpu": min_cpu, "max-tsc": max_tsc, "min-tsc": min_tsc})
    6841
    6942# Sort by timestamp (the second element)
     
    7447merged.sort(key=takeSecond)
    7548
    76 json.dump({"values":merged, "max-cpu": max_cpu, "min-cpu": min_cpu, "max-tsc": max_tsc, "min-tsc": min_tsc}, args.out)
     49# for m in merged:
     50#       print(m)
    7751
    78 # vmin = merged[ 0][1]
    79 # vmax = float(merged[-1][1] - vmin) / 2500000000.0
    80 # # print(vmax)
     52single = []
     53curr = 0
    8154
    82 # bins = []
    83 # for _ in range(0, int(math.ceil(vmax * 10))):
    84 #       bins.append([0] * (32 * 32))
     55# merge the data
     56# for (me, time, value) in merged:
     57for (me, value) in merged:
     58        # check now much this changes
     59        old = counters[me]
     60        change = value - old
     61        counters[me] = value
    8562
    86 # # print(len(bins))
    87 # bins = np.array(bins)
     63        # add change to the current
     64        curr = curr + change
     65        single.append( value )
    8866
    89 # rejected = 0
    90 # highest  = 0
     67        pass
    9168
    92 # for x in merged:
    93 #       b = int(float(x[1] - vmin) / 250000000.0)
    94 #       from_ = x[2]
    95 #       if from_ < 0 or from_ > 32:
    96 #               rejected += 1
    97 #               continue;
    98 #       to_   = x[3]
    99 #       if to_ < 0 or to_ > 32:
    100 #               rejected += 1
    101 #               continue;
    102 #       idx = (to_ * 32) + from_
    103 #       bins[b][idx] = bins[b][idx] + 1
    104 #       highest = max(highest, bins[b][idx])
    105 
    106 # bins = np.array(map(lambda x: np.int8(x * 255.0 / float(highest)), bins))
    107 
    108 # print([highest, rejected])
    109 # print(bins.shape)
    110 
    111 # im = Image.fromarray(bins)
    112 # im.save('test.png')
    113 
    114 # vmax = merged[-1][1]
    115 
    116 # diff = float(vmax - vmin) / 2500000000.0
    117 # print([vmin, vmax])
    118 # print([vmax - vmin, diff])
    119 
    120 # print(len(merged))
    121 
    122 # for b in bins:
    123 #       print(b)
    124 
    125 # single = []
    126 # curr = 0
    127 
    128 # # merge the data
    129 # # for (me, time, value) in merged:
    130 # for (me, value) in merged:
    131 #       # check now much this changes
    132 #       old = counters[me]
    133 #       change = value - old
    134 #       counters[me] = value
    135 
    136 #       # add change to the current
    137 #       curr = curr + change
    138 #       single.append( value )
    139 
    140 #       pass
    141 
    142 # print(single)
     69print(single)
    14370
    14471# single = sorted(single)[:len(single)-100]
Note: See TracChangeset for help on using the changeset viewer.