17
17
import itertools
18
18
import json
19
19
import os
20
+ import re
21
+ import subprocess
20
22
from typing import Final , List , Tuple
21
23
22
24
from rtlmeter import metrics
@@ -96,7 +98,16 @@ def _cppbuild(cgraph: CGraph, descr: CompileDescriptor, compileDir: str) -> CNod
96
98
step = "cppbuild"
97
99
98
100
def job () -> bool :
99
- cmd = ["make" , "-j" , str (len (CTX .usableCpus )), "-C" , "obj_dir" , "-f" , f"{ _PREFIX } .mk" ]
101
+ cmd = [
102
+ "make" ,
103
+ "-j" ,
104
+ str (len (CTX .usableCpus )),
105
+ "-C" ,
106
+ "obj_dir" ,
107
+ "-f" ,
108
+ f"{ _PREFIX } .mk" ,
109
+ "VM_PARALLEL_BUILDS=1" ,
110
+ ]
100
111
env = {"CCACHE_DEBUG" : "1" , "CCACHE_DEBUGLEVEL" : "1" }
101
112
# Run it
102
113
if runcmd (cmd , step , env ):
@@ -115,13 +126,37 @@ def job() -> bool:
115
126
if "Succeeded getting cached result" in fd .read ():
116
127
ccacheHits += 1
117
128
cData ["ccacheHit" ] = 100.0 * ccacheHits / max (objectFiles , 1 )
129
+ # Gather code size
130
+ with subprocess .Popen (
131
+ args = ["objdump" , "-w" , "-h" , os .path .join (compileDir , "obj_dir" , "Vsim__ALL.a" )],
132
+ stdout = subprocess .PIPE ,
133
+ stderr = subprocess .STDOUT ,
134
+ text = True ,
135
+ encoding = "utf-8" ,
136
+ ) as process :
137
+ assert process .stdout , "stdout is None"
138
+ filenameRe = re .compile (r"^Vsim.*?(Slow)?.o:" )
139
+ codesectionRe = re .compile (r"^\s*\d+\s+(\S+)\s+(\S+)\s+.*\bCODE\b.*" )
140
+ slowFile : bool = False
141
+ hotCodeSize : int = 0
142
+ for line in process .stdout :
143
+ if filenameMatch := filenameRe .match (line ):
144
+ slowFile = filenameMatch .group (1 ) is not None
145
+ continue
146
+ if slowFile :
147
+ continue
148
+ if codesectionMatch := codesectionRe .match (line ):
149
+ hotCodeSize += int (codesectionMatch .group (2 ), base = 16 )
150
+ cData ["codeSize" ] = hotCodeSize * 1e-6
151
+ # Result data
118
152
data = {descr .case : {step : cData }}
119
153
# Add combined 'verilate' + 'cppbuild'
120
154
with open ("_verilate/time.json" , "r" , encoding = "utf-8" ) as fd :
121
155
tData = json .load (fd )
122
156
for k , v in cData .items ():
123
- if (accumulate := metrics .metricDef (k ).accumulate ) is not None :
124
- tData [k ] = accumulate (tData [k ], v )
157
+ mDef = metrics .metricDef (k )
158
+ if (accumulate := mDef .accumulate ) is not None :
159
+ tData [k ] = accumulate (tData .get (k , mDef .identityValue ), v )
125
160
data [descr .case ]["compile" ] = tData
126
161
with open (f"_{ step } /metrics.json" , "w" , encoding = "utf-8" ) as fd :
127
162
json .dump (data , fd )
0 commit comments