The -return_string argument directs the output of a report_* command to a Tcl string rather than to stdout. The string can be assigned to a Tcl variable, and parsed or otherwise processed.
set rpt [report_timing -return_string]
After the string has been assigned to a variable, Tcl provides many useful commands for processing the string in a number of ways:
-
append string [arg1 arg2 ... argN] - Appends the specified
argsto the end ofstring. -
format formatString [arg1 arg2 ... argN] - Returns a formatted string generated to match the format
specified by the
formatStringtemplate. The template must be specified using % conversion specifiers as used insprintf. The additional arguments,args, provide values to be substituted into the formatted string. -
reg exp [switches] exp string - Returns 1 if the regular expression,
exp, matches all or part ofstring, 0 otherwise. The-nocaseswitch can be specified to ignore character case when matching. -
string matchpatternstring - Returns 1 if the
globpatternmatchesstring, 0 otherwise. -
scanstringformatString[varName1varName2...] - Extracts values from the specified
stringinto variables,varName, applying theformatStringusing % conversion specifiers as insscanfbehavior. If novarNamesare specified,scanreturns the list of values tostdout -
string rangestringfirst last - Returns the range of characters from
stringspecified by character indicesfirstthroughlastinclusive. -
string comparestring1string2 - Performs a lexicographical comparison of two strings, and
returns -1 if
string1comes beforestring2, 0 if they are the same, and 1 ifstring1comes afterstring2. -
string laststring1string2 - Return the character index in
string2of the last occurrence ofstring1. Returns -1 ifstring1is not found instring2. -
string lengthstring - Returns the number of characters in
string.
The following example assigns the results of the report_timing command to the $report Tcl variable, using -return_string. The string is processed to extract the
start point, end point, path group and path type of each path. After the
path information is extracted, a summary of that path is printed to the Tcl
Console.
# Capture return string of timing report, and assign variables
set report [report_timing -return_string -max_paths 10]
set startPoint {}
set endPoint {}
set pathGroup {}
set pathType {}
# Write the header for string output
puts [format " %-12s %-12s %-20s -> %-20s" "Path Type" "Path Group" "Start Point" "End Point"]
puts [format " %-12s %-12s %-20s -> %-20s" "---------" "----------" "-----------" "---------"]
# Split the return string into multiple lines to allow line by line processing
foreach line [split $report \n] {
if {[regexp -nocase -- {^\s*Source:\s*([^[:blank:]]+)((\s+\(?)|$)} $line - startPoint]} {
} elseif {[regexp -nocase -- {^\s*Destination:\s*([^[:blank:]]+)((\s+\(?)|$)} $line - endPoint]} {
} elseif {[regexp -nocase -- {^\s*Path Group:\s*([^[:blank:]]+)\s*$} $line - pathGroup]} {
} elseif {[regexp -nocase -- {^\s*Path Type:\s*([^[:blank:]]+)((\s+\(?)|$)} $line - pathType]} {
puts [format " %-12s %-12s %-20s -> %-20s" $pathType $pathGroup $startPoint $endPoint]
}
}
An example output from the code is:
Path Type Path Group Start Point -> End Point
--------- ---------- ----------- -> ---------
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[0]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[10]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[11]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[12]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[13]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[14]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[15]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[16]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[17]
Setup bftClk ingressLoop[0]/ram/CLKBWRCLK -> transformLoop[0].ct/xOutReg_reg/A[18]