Changeset d00ce99


Ignore:
Timestamp:
Sep 23, 2021, 11:56:00 AM (2 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
master
Children:
ec421636
Parents:
1cc7689
Message:

Several improvements to process_stat_array

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/perf/process_stat_array.py

    r1cc7689 rd00ce99  
    11#!/usr/bin/python3
    22
    3 import argparse, os, sys, re
     3import argparse, json, math, os, sys, re
     4from PIL import Image
     5import numpy as np
    46
    57def dir_path(string):
     
    1113parser = argparse.ArgumentParser()
    1214parser.add_argument('--path', type=dir_path, default=".cfadata", help= 'paste path to biog.txt file')
     15parser.add_argument('--out', type=argparse.FileType('w'), default=sys.stdout)
    1316
    1417try :
     
    2326counters = {}
    2427
     28max_cpu = 0
     29min_cpu = 1000000
     30max_tsc = 0
     31min_tsc = 18446744073709551615
     32
    2533#open the files
    2634for filename in filenames:
     
    3139                with open(os.path.join(root, filename), 'r') as file:
    3240                        for line in file:
    33                                 # data = [int(x.strip()) for x in line.split(',')]
    34                                 data = [int(line.strip())]
    35                                 data = [me, *data]
     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])
    3660                                merged.append(data)
    3761
    38         except:
     62        except Exception as e:
     63                print(e)
    3964                pass
    4065
     66
     67print({"max-cpu": max_cpu, "min-cpu": min_cpu, "max-tsc": max_tsc, "min-tsc": min_tsc})
    4168
    4269# Sort by timestamp (the second element)
     
    4774merged.sort(key=takeSecond)
    4875
    49 # for m in merged:
    50 #       print(m)
     76json.dump({"values":merged, "max-cpu": max_cpu, "min-cpu": min_cpu, "max-tsc": max_tsc, "min-tsc": min_tsc}, args.out)
    5177
    52 single = []
    53 curr = 0
     78# vmin = merged[ 0][1]
     79# vmax = float(merged[-1][1] - vmin) / 2500000000.0
     80# # print(vmax)
    5481
    55 # merge the data
    56 # for (me, time, value) in merged:
    57 for (me, value) in merged:
    58         # check now much this changes
    59         old = counters[me]
    60         change = value - old
    61         counters[me] = value
     82# bins = []
     83# for _ in range(0, int(math.ceil(vmax * 10))):
     84#       bins.append([0] * (32 * 32))
    6285
    63         # add change to the current
    64         curr = curr + change
    65         single.append( value )
     86# # print(len(bins))
     87# bins = np.array(bins)
    6688
    67         pass
     89# rejected = 0
     90# highest  = 0
    6891
    69 print(single)
     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)
    70143
    71144# single = sorted(single)[:len(single)-100]
Note: See TracChangeset for help on using the changeset viewer.