aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-05-16 14:32:32 +0200
committerKarel Kočí <cynerd@email.cz>2015-05-16 14:32:32 +0200
commit599690760476bf7c9c2be226c40cc70c813aa60d (patch)
tree2c7582e38c83ba00444813e2f9f84adcd30212b3 /scripts
parentf189512d1a531578a87a0743d8bc6422613a1e99 (diff)
downloadlinux-conf-perf-599690760476bf7c9c2be226c40cc70c813aa60d.tar.gz
linux-conf-perf-599690760476bf7c9c2be226c40cc70c813aa60d.tar.bz2
linux-conf-perf-599690760476bf7c9c2be226c40cc70c813aa60d.zip
Implement evaluate
Diffstat (limited to 'scripts')
-rw-r--r--scripts/boot.py2
-rwxr-xr-xscripts/evaluate.py115
-rw-r--r--scripts/parse_kconfig/output.c6
-rw-r--r--scripts/parse_kconfig/output.h3
-rw-r--r--scripts/parse_kconfig/parse.c2
-rw-r--r--scripts/solution.py2
-rw-r--r--scripts/utils.py20
7 files changed, 140 insertions, 10 deletions
diff --git a/scripts/boot.py b/scripts/boot.py
index d03504a..a055998 100644
--- a/scripts/boot.py
+++ b/scripts/boot.py
@@ -22,7 +22,7 @@ def boot():
sprc = subprocess.Popen(conf.boot_command,
stdout = subprocess.PIPE)
- with open(os.path.join(sf(conf.output_folder), utils.get_last_configuration()), "w") as f:
+ with open(os.path.join(sf(conf.output_folder), utils.get_last_configuration()), "a") as f:
for linen in sprc.stdout:
line = linen.decode('utf-8')
if conf.boot_output:
diff --git a/scripts/evaluate.py b/scripts/evaluate.py
new file mode 100755
index 0000000..436879d
--- /dev/null
+++ b/scripts/evaluate.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python3
+import os
+import sys
+
+import numpy.linalg as nplag
+
+from conf import conf
+from conf import sf
+import utils
+
+def reduce_matrix_remove_symbol(A, symrow, indx):
+ del symrow[indx]
+ for i in range(0, len(A)):
+ del A[i][indx]
+
+def reduce_matrix(A, symrow):
+ # Remove fixed symbols
+ i = len(A[0]) - 1
+ while i >= 0:
+ strue = False
+ sfalse = False
+ for y in range(0, len(A)):
+ if A[y][i] == 0:
+ sfalse = True
+ else:
+ strue = True
+ if (strue and not sfalse) or (sfalse and not strue):
+ reduce_matrix_remove_symbol(A, symrow, i)
+ i -= 1
+
+ # Remove duplicate symbols
+ i = len(A[0]) - 1
+ columns = []
+ while i >= 0:
+ column = []
+ for y in range(0, len(A)):
+ column.append(A[y][i])
+ if column in columns:
+ reduce_matrix_remove_symbol(A, symrow, i)
+ else:
+ columns.append(column)
+ i -= 1
+
+
+def evaluate():
+ print("Collect data...")
+ hashs = {}
+ for fl in os.listdir(sf(conf.result_folder)):
+ if os.path.isfile(os.path.join(sf(conf.result_folder), fl)):
+ hashs[fl] = [[], []]
+ try:
+ hashs.pop('NoConfig')
+ except KeyError:
+ pass
+
+ with open(sf(conf.config_map_file)) as f:
+ for line in f:
+ w = line.rstrip().split(sep=':')
+ if not w[0] or not w[0] in hashs:
+ continue
+ sol = utils.config_strtoint(w[1], False)
+ hashs[w[0]][0] = sol
+
+ for hash, data in hashs.items():
+ with open(os.path.join(sf(conf.result_folder), hash)) as f:
+ vec = []
+ for ln in f:
+ vec.append(float(ln))
+ hashs[hash][1] = vec
+
+ print('Build matrix...')
+ A = []
+ B = []
+ for hash,data in hashs.items():
+ A.append(data[0])
+ B.append(data[1])
+ symrow = []
+ for y in range(0, len(A[0])):
+ symrow.append([abs(A[0][y])])
+ for x in range(0, len(A)):
+ for y in range(0, len(A[0])):
+ if A[x][y] < 0:
+ A[x][y] = 0
+ else:
+ A[x][y] = 1
+
+ # Reduce matrix A
+ print('Simplify matrix...')
+ reduce_matrix(A, symrow)
+
+ for x in range(0, len(A)):
+ A[x].append(1)
+ symrow.append(0)
+
+ # Calculate value
+ print('Figuring values...')
+ R = nplag.lstsq(A, B)
+
+ # Print result
+ print('--------------------')
+ utils.build_symbol_map()
+ for i in range(0, len(R[0])):
+ if symrow[i] == 0:
+ print("Base", end=' ')
+ else:
+ for s in symrow[i]:
+ print(utils.smap[s], end=' ')
+ print("=", end=' ')
+ print(str(R[0][i]))
+
+
+#################################################################################
+
+if __name__ == '__main__':
+ evaluate()
diff --git a/scripts/parse_kconfig/output.c b/scripts/parse_kconfig/output.c
index 81debaf..f931ba2 100644
--- a/scripts/parse_kconfig/output.c
+++ b/scripts/parse_kconfig/output.c
@@ -31,9 +31,11 @@ void output_rules_endterm(void) {
}
// Functions for variable_count
-void output_write_variable_count(char *var_file, int count) {
+void output_write_variable_count(char *var_file, int count,
+ unsigned lastoption) {
FILE *f;
f = fopen(var_file, "w");
- fprintf(f, "%d", count);
+ fprintf(f, "%d\n", count);
+ fprintf(f, "%d", lastoption);
fclose(f);
}
diff --git a/scripts/parse_kconfig/output.h b/scripts/parse_kconfig/output.h
index 2950f7a..fb3a7cf 100644
--- a/scripts/parse_kconfig/output.h
+++ b/scripts/parse_kconfig/output.h
@@ -19,6 +19,7 @@ void output_rules_symbol(int id);
void output_rules_endterm(void);
// Functions for variable_count
-void output_write_variable_count(char *var_file, int count);
+void output_write_variable_count(char *var_file, int count,
+ unsigned lastoption);
#endif /* _OUTPUT_H_ */
diff --git a/scripts/parse_kconfig/parse.c b/scripts/parse_kconfig/parse.c
index d7c2353..b8aded2 100644
--- a/scripts/parse_kconfig/parse.c
+++ b/scripts/parse_kconfig/parse.c
@@ -66,7 +66,7 @@ int main(int argc, char **argv) {
cpy_dep();
output_write_variable_count(variable_count_file,
- gsymlist->lastsym - 1);
+ gsymlist->lastsym - 1, gsymlist->pos);
output_finish();
return 0;
diff --git a/scripts/solution.py b/scripts/solution.py
index 2eed129..930297b 100644
--- a/scripts/solution.py
+++ b/scripts/solution.py
@@ -114,7 +114,7 @@ def apply():
if not w[0]:
break
if not w[0] in solved:
- solution = utils.config_strtoint(w[1])
+ solution = utils.config_strtoint(w[1], True)
hash = w[0]
break
if not solution:
diff --git a/scripts/utils.py b/scripts/utils.py
index 74cc80c..9c83065 100644
--- a/scripts/utils.py
+++ b/scripts/utils.py
@@ -103,12 +103,24 @@ def hash_config(cf):
hsh = hashlib.md5(bytes(str, sys.getdefaultencoding()))
return hsh.hexdigest()
-def config_strtoint(str):
+def config_strtoint(str, full):
"""Reads list of configured symbols from string
"""
rtn = []
- for s in str.rstrip().split(sep=' '):
- rtn.append(int(s))
+ if full:
+ for s in str.rstrip().split(sep=' '):
+ rtn.append(int(s))
+ else:
+ count = 0
+ with open(sf(conf.variable_count_file)) as f:
+ f.readline()
+ count = int(f.readline())
+ for s in str.rstrip().split(sep=' '):
+ val = int(s)
+ if abs(val) <= count:
+ rtn.append(val)
+ else:
+ break;
try:
rtn.remove(0)
except ValueError:
@@ -120,7 +132,7 @@ def get_config_from_hash(hash):
for line in f:
w = line.rstrip().split(sep=':')
if w[0] == hash:
- return config_strtoint(w[1])
+ return config_strtoint(w[1], True)
return None
def get_last_configuration():