|
1 | | -import { createReadStream, writeFile } from "fs-extra"; |
2 | | -import { LINE_ENDINGS, splitStreamAtSeparators } from "../common/split-stream"; |
3 | | - |
4 | 1 | /** |
5 | 2 | * Location information for a single pipeline invocation in the RA. |
6 | 3 | */ |
@@ -32,103 +29,3 @@ interface PredicateSymbol { |
32 | 29 | export interface SummarySymbols { |
33 | 30 | predicates: Record<string, PredicateSymbol>; |
34 | 31 | } |
35 | | - |
36 | | -// Tuple counts for Expr::Expr::getParent#dispred#f0820431#ff@76d6745o: |
37 | | -const NON_RECURSIVE_TUPLE_COUNT_REGEXP = |
38 | | - /^Evaluated relational algebra for predicate (?<predicateName>\S+) with tuple counts:$/; |
39 | | -// Tuple counts for Expr::Expr::getEnclosingStmt#f0820431#bf@923ddwj9 on iteration 0 running pipeline base: |
40 | | -const RECURSIVE_TUPLE_COUNT_REGEXP = |
41 | | - /^Evaluated relational algebra for predicate (?<predicateName>\S+) on iteration (?<iteration>\d+) running pipeline (?<pipeline>\S+) with tuple counts:$/; |
42 | | -const RETURN_REGEXP = /^\s*return /; |
43 | | - |
44 | | -/** |
45 | | - * Parse a human-readable evaluation log summary to find the location of the RA for each pipeline |
46 | | - * run. |
47 | | - * |
48 | | - * TODO: Once we're more certain about the symbol format, we should have the CLI generate this as it |
49 | | - * generates the human-readabe summary to avoid having to rely on regular expression matching of the |
50 | | - * human-readable text. |
51 | | - * |
52 | | - * @param summaryPath The path to the summary file. |
53 | | - * @param symbolsPath The path to the symbols file to generate. |
54 | | - */ |
55 | | -export async function generateSummarySymbolsFile( |
56 | | - summaryPath: string, |
57 | | - symbolsPath: string, |
58 | | -): Promise<void> { |
59 | | - const symbols = await generateSummarySymbols(summaryPath); |
60 | | - await writeFile(symbolsPath, JSON.stringify(symbols)); |
61 | | -} |
62 | | - |
63 | | -/** |
64 | | - * Parse a human-readable evaluation log summary to find the location of the RA for each pipeline |
65 | | - * run. |
66 | | - * |
67 | | - * @param fileLocation The path to the summary file. |
68 | | - * @returns Symbol information for the summary file. |
69 | | - */ |
70 | | -async function generateSummarySymbols( |
71 | | - summaryPath: string, |
72 | | -): Promise<SummarySymbols> { |
73 | | - const stream = createReadStream(summaryPath, { |
74 | | - encoding: "utf-8", |
75 | | - }); |
76 | | - try { |
77 | | - const lines = splitStreamAtSeparators(stream, LINE_ENDINGS); |
78 | | - |
79 | | - const symbols: SummarySymbols = { |
80 | | - predicates: {}, |
81 | | - }; |
82 | | - |
83 | | - let lineNumber = 0; |
84 | | - let raStartLine = 0; |
85 | | - let iteration = 0; |
86 | | - let predicateName: string | undefined = undefined; |
87 | | - let startLine = 0; |
88 | | - for await (const line of lines) { |
89 | | - if (predicateName === undefined) { |
90 | | - // Looking for the start of the predicate. |
91 | | - const nonRecursiveMatch = line.match(NON_RECURSIVE_TUPLE_COUNT_REGEXP); |
92 | | - if (nonRecursiveMatch) { |
93 | | - iteration = 0; |
94 | | - predicateName = nonRecursiveMatch.groups!.predicateName; |
95 | | - } else { |
96 | | - const recursiveMatch = line.match(RECURSIVE_TUPLE_COUNT_REGEXP); |
97 | | - if (recursiveMatch?.groups) { |
98 | | - predicateName = recursiveMatch.groups.predicateName; |
99 | | - iteration = parseInt(recursiveMatch.groups.iteration); |
100 | | - } |
101 | | - } |
102 | | - if (predicateName !== undefined) { |
103 | | - startLine = lineNumber; |
104 | | - raStartLine = lineNumber + 1; |
105 | | - } |
106 | | - } else { |
107 | | - const returnMatch = line.match(RETURN_REGEXP); |
108 | | - if (returnMatch) { |
109 | | - let symbol = symbols.predicates[predicateName]; |
110 | | - if (symbol === undefined) { |
111 | | - symbol = { |
112 | | - iterations: {}, |
113 | | - recursionSummaries: {}, |
114 | | - }; |
115 | | - symbols.predicates[predicateName] = symbol; |
116 | | - } |
117 | | - symbol.iterations[iteration] = { |
118 | | - startLine, |
119 | | - raStartLine, |
120 | | - raEndLine: lineNumber, |
121 | | - }; |
122 | | - |
123 | | - predicateName = undefined; |
124 | | - } |
125 | | - } |
126 | | - |
127 | | - lineNumber++; |
128 | | - } |
129 | | - |
130 | | - return symbols; |
131 | | - } finally { |
132 | | - stream.close(); |
133 | | - } |
134 | | -} |
0 commit comments