sed Part IV · Module 11 · Synthesis and STA Automation
Timing Report Extraction and Cleanup
This is the last pure-sed artifact in the track, and the one where the temptation to overreach is strongest. A timing report looks like a table: columns, numbers, a verdict per path. It is extremely tempting to keep adding commands until sed is counting violations and totalling slack. This chapter does the opposite. sed's job here is to extract the section you want and shape it into something a program can read — and then to stop, because the moment a question involves comparing numbers it belongs to awk, for the reason Chapter 8.4 measured: sed has no arithmetic at all. The chapter ends at the handoff and shows it working.
Intermediate18 min readsedPart IVSTATiming Reportsawk
Part IV · Module 11 · Chapter 11.3 · Timing Report Extraction and Cleanup
1. The Report
wc -l sta/timing.rpt 34 sta/timing.rptsed -n '1,14p' sta/timing.rpt****************************************
Report : timing
Design : top
Version: R-2020.09
****************************************
Startpoint: u_alu/rd_data_reg[3]
(rising edge-triggered flip-flop clocked by clk)
Endpoint: u_fifo/wr_ptr_reg[0]
(rising edge-triggered flip-flop clocked by clk)
Path Group: clk
Path Type : max
Point Incr PathThirty-four lines containing a banner, blank lines, two path blocks, column padding aligned for a terminal, and — somewhere in there — the two numbers anybody actually wants.
2. Three Jobs, in Order
1. EXTRACT the section you care about
2. CLEAN drop what no parser needs, collapse the padding
3. SHAPE one record per line, fields a program can split
— then stop. Arithmetic is awk's.3. Step 1 — Extract, and Mind the Reopening
The registered extraction takes a path block:
sed -n '/^Startpoint/,/^[[:space:]]*slack/p' sta/timing.rpt | head -14Startpoint: u_alu/rd_data_reg[3]
(rising edge-triggered flip-flop clocked by clk)
Endpoint: u_fifo/wr_ptr_reg[0]
(rising edge-triggered flip-flop clocked by clk)
Path Group: clk
Path Type : max
Point Incr Path
------------------------------------------------------------
clock clk (rise edge) 0.000 0.000
u_alu/rd_data_reg[3]/CK 0.000 0.000
u_alu/rd_data_reg[3]/Q 0.182 0.182
u_fifo/wr_ptr_reg[0]/D 1.660 1.842
data arrival time 1.842That is the first block, and head -14 is doing some of the work. Without it:
sed -n '/^Startpoint/,/^[[:space:]]*slack/p' sta/timing.rpt | wc -l 24Twenty-four lines of a thirty-four-line report. The range reopened at the second Startpoint, exactly as Chapter 4.4 measured, so this is "every path block" rather than "the first one" — and on a report that is mostly path blocks, that is nearly everything.
It did do a real job: the banner and the trailing lines are gone. But if you wanted one block, this is not it. The options, from Chapter 4.4:
/^Startpoint/,/slack/p every block (what the registered command does)
1,/slack/p the FIRST block only — a number start cannot reopen
/^Startpoint/,+8p a fixed-size block, if the shape is reliableFor a report, "every block" is usually what you want. It is worth knowing it is what you are getting.
4. Step 2 — Clean
Two commands, and they belong together:
sed -e '/^[[:space:]]*$/d' -e 's/[[:space:]]\{2,\}/ /g' sta/timing.rpt | head -12****************************************
Report : timing
Design : top
Version: R-2020.09
****************************************
Startpoint: u_alu/rd_data_reg[3]
(rising edge-triggered flip-flop clocked by clk)
Endpoint: u_fifo/wr_ptr_reg[0]
(rising edge-triggered flip-flop clocked by clk)
Path Group: clk
Path Type : max
Point Incr PathThe blank lines are gone and every run of padding has collapsed to a single space. Point Incr Path is now three fields rather than three columns at fixed offsets.
Both halves matter and for different reasons. Dropping blanks stops a parser having to skip them and makes "one record per line" true. Squeezing padding is what turns a visual table into something splittable — Chapter 8.1 noted awk's default field separator already handles runs of whitespace, so this is not for awk's benefit; it is for anything with a stricter separator, and for making the result readable in a diff.
Note what the cleanup does not do: the banner is still there. Cleaning and extracting are separate steps, and this command only cleans.
5. Step 3 — Shape It Into Records
Here is the whole point of the chapter. The registered extraction pulls the verdict and the number out of every slack line:
sed -n -E 's/^[[:space:]]*slack \((MET|VIOLATED)\)[[:space:]]*(-?[0-9.]+).*/\1 \2/p' sta/timing.rptMET 0.258
VIOLATED -0.110Thirty-four lines of report, two rows of two fields. That is a machine-readable summary of the whole file, and it is the right place for sed to stop.
Reading the pattern:
^[[:space:]]* the slack line is indented
slack \((MET|VIOLATED)\) literal parens around a captured verdict -> \1
[[:space:]]* the column padding
(-?[0-9.]+) an optionally negative number -> \2
.* anything else on the line, discardedThree details worth naming, each from earlier in the track:
-Eis right here for the alternation, and the parentheses aroundMET|VIOLATEDgroup while\(\)are literal — Chapter 4.1's inversion, and the opposite dialect choice from Chapter 11.1, where the text was full of+.-?makes the minus sign optional, which is how-0.110and0.258both parse. Omit it and the violated path does not match at all — section 7 measures what that costs.-nwith thepflag means only lines that matched are printed, so the banner, the path details and the blank lines never appear. Chapter 5.1's filter idiom doing the extraction and the shaping in one command.
6. Then Stop — the Handoff to awk
The obvious next questions are arithmetic:
How many paths are violated?
What is the worst slack?
What is the total negative slack?None of those is a sed job, and Chapter 8.4 measured why in the sharpest possible way: to a text tool, -0.110 sorts after 1.842, because string order is not numeric order. sed has no arithmetic, no comparison of magnitudes, and no concept of a number at all.
What it has produced is exactly what awk wants:
sed -n -E 's/^[[:space:]]*slack \((MET|VIOLATED)\)[[:space:]]*(-?[0-9.]+).*/\1 \2/p' sta/timing.rpt \
| awk '{ n++; if ($1 == "VIOLATED") v++ } END { printf "%d paths, %d violated\n", n, v+0 }'2 paths, 1 violatedTwo stages, two jobs. sed turned an unparseable report into records; awk counted them. Chapter 8.1's division of labour, on the artifact where it matters most.
Extending the awk side costs nothing:
worst slack awk 'NR==1 || $2<w { w=$2 } END { print w }'
total negative awk '$2<0 { t+=$2 } END { printf "%.3f\n", t }'
violated only awk '$1=="VIOLATED" { print $2 }'Each of those is a one-line change to the second stage. Doing any of them in sed would mean a loop, a hold space, and string arithmetic that cannot represent a negative number — the point at which Chapter 8.4 says the job has outgrown the tool.
7. Think It Through
1. sed -n '/^Startpoint/,/slack/p' report.rpt on a report with forty paths. How many blocks do you get?
All forty. A pattern range reopens each time its start matches — Chapter 4.4 — so this means "every block". For the first only, start the range at a line number: 1,/slack/p. Section 3 measured 24 of 34 lines from a two-path report.
2. Why does the shaping pattern need -? and what happens without it?
-? allows an optional leading minus so -0.110 is captured whole. Drop it and the violated path vanishes from the output entirely:
sed -n -E 's/^[[:space:]]*slack \((MET|VIOLATED)\)[[:space:]]*([0-9.]+).*/\1 \2/p' sta/timing.rptMET 0.258One record instead of two. [0-9.]+ cannot match the -, so the whole pattern fails on that line and -n means nothing is printed for it. The violated path — the only one anybody cares about — is silently absent, and every downstream count is short by one.
That is precisely the failure the record-count check in section 5 exists to catch: two startpoints, one record.
3. Your extraction returns 38 records from a 40-path report. What do you do?
Find the two that did not match before trusting any of the 38. grep -c '^Startpoint' gives the expected count; then grep 'slack' report.rpt | grep -v -E 'slack \((MET|VIOLATED)\)' shows the slack lines your pattern does not describe — usually a third verdict word or a differently formatted number.
4. Why is squeezing the padding not needed for awk, and when is it needed?
awk's default field separator already splits on runs of whitespace, as Chapter 8.1 measured — the sed stage there was byte-for-byte redundant. It is needed when the consumer has a stricter separator (-F'[ ]', a CSV reader), or when the output will be read by a human in a diff, where collapsed padding stops a widened column showing as a change on every line.
5. Write the pipeline that reports the worst slack in the report.
The same sed, then awk 'NR==1 || $2<w { w=$2; } END { print w }'. The sed stage is unchanged — that is the property worth noticing. Once the report is records, every new question is a change to the second stage only.
6. When should you not be parsing the report at all?
When the tool is still open and can answer directly. A report_timing -json or a Tcl query returns values; the text report is a rendering of those values with the columns aligned and the numbers already rounded. Chapter 8.4 section 7 makes that the first question. Parsing is for reports from runs that have finished, or tools you cannot script.
8. Summary
- sed's job on a timing report is to extract and shape, then stop.
- A pattern range reopens, so
/^Startpoint/,/slack/pmeans every block — 24 lines of a 31-line report. Use1,/slack/pfor the first only. - Clean with two commands: drop blank lines, collapse runs of whitespace. The first makes "one record per line" true; the second makes the line splittable and the diff readable.
- Cleaning is not extracting — the cleanup command leaves the banner in place.
- The shaping command is the payoff: 34 lines became
MET 0.258andVIOLATED -0.110, two records of two fields. -?is load-bearing. Without it the violated path produces no record at all — one row instead of two, and the only path anybody cares about is the missing one.- Count records against path blocks. Two startpoints, two records; a shortfall means some slack lines are formatted differently and are silently missing.
- Hand the arithmetic to awk.
2 paths, 1 violatedin one more stage, and every further question is a change to that stage only. - If the tool can still answer, ask the tool. A report is a rendering; a Tcl query or JSON output gives values.
That closes Module 11 and the implementation half of Part IV. Across Modules 9 to 11 the same four steps have recurred on every artifact — audit, count, scope, verify — applied to filelists, RTL, run scripts, logs, synthesis setup, constraints and reports. Module 12 — Engineering Case Studies and Review is the last module in the track: two migrations carried out end to end, one incident reconstructed from its diff, and the review reasoning that decides whether a mass edit should be approved.
Where this fits
Part of the sed curriculum.
