Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable filter using regex #312

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func printStats(hirSchema *hir.Schema, hir bool, mir bool, air bool) {
for j := 0; j < len(schemas); j++ {
row[j+1] = ith.summary(schemas[j])
}

tbl.SetRow(i, row...)
}
//
Expand Down
16 changes: 12 additions & 4 deletions pkg/cmd/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"math"
"os"
"strings"
"regexp"

"github.com/consensys/go-corset/pkg/trace"
"github.com/consensys/go-corset/pkg/util"
Expand Down Expand Up @@ -63,23 +63,30 @@ func init() {
traceCmd.Flags().UintP("end", "e", math.MaxUint, "filter out this and all following rows")
traceCmd.Flags().Uint("max-width", 32, "specify maximum display width for a column")
traceCmd.Flags().StringP("out", "o", "", "Specify output file to write trace")
traceCmd.Flags().StringP("filter", "f", "", "Filter columns beginning with prefix")
traceCmd.Flags().StringP("filter", "f", "", "Filter columns matching regex")
}

// Construct a new trace containing only those columns from the original who
// name begins with the given prefix.
func filterColumns(cols []trace.RawColumn, prefix string) []trace.RawColumn {
func filterColumns(cols []trace.RawColumn, regex string) []trace.RawColumn {
r, err := regexp.Compile(regex)
// Check for error
if err != nil {
panic(err)
}
//
ncols := make([]trace.RawColumn, 0)
// Now create the columns.
for i := 0; i < len(cols); i++ {
name := trace.QualifiedColumnName(cols[i].Module, cols[i].Name)
if strings.HasPrefix(name, prefix) {
if r.MatchString(name) {
ncols = append(ncols, cols[i])
}
}
// Done
return ncols
}

func printTrace(start uint, end uint, max_width uint, cols []trace.RawColumn) {
n := uint(len(cols))
height := min(maxHeightColumns(cols), end) - start
Expand Down Expand Up @@ -119,6 +126,7 @@ func listColumns(tr []trace.RawColumn) {
for j := 0; j < len(colSummarisers); j++ {
row[j+1] = colSummarisers[j].summary(tr[i])
}

tbl.SetRow(i, row...)
}
//
Expand Down
6 changes: 2 additions & 4 deletions pkg/test/ir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,12 @@ func checkTrace(t *testing.T, inputs []trace.RawColumn, expand bool, id traceId,
// Process what happened versus what was supposed to happen.
if !accepted && id.expected {
//table.PrintTrace(tr)
msg := fmt.Sprintf("Trace rejected incorrectly (%s, %s.accepts, line %d with padding %d): %s",
t.Errorf("Trace rejected incorrectly (%s, %s.accepts, line %d with padding %d): %s",
id.ir, id.test, id.line, id.padding, errs)
t.Errorf(msg)
} else if accepted && !id.expected {
//printTrace(tr)
msg := fmt.Sprintf("Trace accepted incorrectly (%s, %s.rejects, line %d with padding %d)",
t.Errorf("Trace accepted incorrectly (%s, %s.rejects, line %d with padding %d)",
id.ir, id.test, id.line, id.padding)
t.Errorf(msg)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/trace/array_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ func (p *ArrayTrace) String() string {

id.WriteString(jth.String())
}

id.WriteString("}")
}
}

id.WriteString("}")
//
return id.String()
Expand Down
1 change: 1 addition & 0 deletions pkg/trace/json/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func ToJsonString(columns []trace.RawColumn) string {
jth := data.Get(j)
builder.WriteString(jth.String())
}

builder.WriteString("]")
}
//
Expand Down
1 change: 1 addition & 0 deletions pkg/trace/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func printHorizontalRule(widths []int) {
for i := 0; i < w; i++ {
fmt.Print("-")
}

fmt.Print("-+")
}

Expand Down
Loading