Skip to content

wip #134

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

wip #134

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
12 changes: 6 additions & 6 deletions CREDITS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ SOFTWARE.



github.com/containerd/[email protected]
====================================
github.com/containerd/[email protected]-0.20230313162750-1ae8d489ac81
==================================================================


Apache License
Expand Down Expand Up @@ -471,7 +471,7 @@ SOFTWARE.



github.com/muesli/[email protected]20230316100256-276c6243b2f6
github.com/muesli/[email protected]20211031195517-c9f0611b6c70
=========================================================

MIT License
Expand Down Expand Up @@ -633,7 +633,7 @@ SOFTWARE.



golang.org/x/sync@v0.6.0
golang.org/x/sync@v0.7.0
========================

Copyright (c) 2009 The Go Authors. All rights reserved.
Expand Down Expand Up @@ -666,7 +666,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



golang.org/x/sys@v0.18.0
golang.org/x/sys@v0.19.0
========================

Copyright (c) 2009 The Go Authors. All rights reserved.
Expand Down Expand Up @@ -699,7 +699,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



golang.org/x/term@v0.18.0
golang.org/x/term@v0.19.0
=========================

Copyright (c) 2009 The Go Authors. All rights reserved.
Expand Down
90 changes: 90 additions & 0 deletions cmd/lockfinder/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package main

import (
"bufio"
"flag"
"fmt"
"os"
"regexp"
"strings"
)

func main() {
if err := run(); err != nil {
panic(err)
}
}

var logfile = flag.String("logfile", "mutex.log", "path to mutex.log file to consider")

func run() error {
flag.Parse()

file, err := os.Open(*logfile)
if err != nil {
return err
}
defer file.Close()

l := &lockfinder{
m: map[string]string{},
}

scn := bufio.NewScanner(file)
for scn.Scan() {
l.handleLine(scn.Text())
}
if err := scn.Err(); err != nil {
return err
}

fmt.Println(l.report())
return nil
}

type lockfinder struct {
m map[string]string
}

var re = regexp.MustCompile(`(?P<Date>.{25}) \[(?P<Lock>.+)](?P<Fn>.*) (?P<Op>.*s) lock$`)

func (l *lockfinder) handleLine(line string) error {
match := re.FindStringSubmatch(line)
if len(match) == 0 {
return nil
}
lock, fn, op := match[re.SubexpIndex("Lock")], match[re.SubexpIndex("Fn")], match[re.SubexpIndex("Op")]
switch op {
case "seeks":
case "receives":
l.m[lock] = fn
case "releases":
l.m[lock] = ""
}
return nil
}

type Operation int

const (
unknownOperation Operation = iota
OperationGotLock
OperationSeeksLock
OperationUnlocks
)

func (l *lockfinder) report() string {
var buf strings.Builder
fmt.Fprintf(&buf, "report\n")
for lock, fn := range l.m {
if fn != "" {
fmt.Fprintf(&buf, "- %s is held by %s\n", lock, fn)
}
}
for lock, fn := range l.m {
if fn == "" {
fmt.Fprintf(&buf, "- %s is not held\n", lock)
}
}
return buf.String()
}
66 changes: 66 additions & 0 deletions cmd/messagestringer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import (
"flag"
"go/ast"
"go/parser"
"go/token"
"os"
"path/filepath"
"strings"
)

var (
file = flag.String("file", os.Getenv("GOFILE"), "the file to search for msg types")
prefix = flag.String("prefix", "msg", "a prefix; types whose names have this prefix will be generated")
)

func main() {
flag.Parse()
if err := run(); err != nil {
panic(err)
}
}

func run() error {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, *file, nil, 0)
if err != nil {
return err
}

var (
packageName string
ts []string
)
ast.Inspect(f, func(n ast.Node) bool {
switch n := n.(type) {
case *ast.File:
packageName = n.Name.String()
case *ast.TypeSpec:
name := n.Name.String()
if strings.HasPrefix(name, *prefix) {
ts = append(ts, name)
}
}
return true
})

var b strings.Builder
b.WriteString("// Code generated by \"messagestringer -file=" + *file + " -prefix=" + *prefix + "\"; DO NOT EDIT.\n\n")
b.WriteString("package " + packageName + "\n\n")
b.WriteString("import \"fmt\"\n\n")
for _, t := range ts {
b.WriteString("func (msg " + t + ") String() string {\n")
b.WriteString("\treturn fmt.Sprintf(\"[" + t + " %#v]\", msg)\n")
b.WriteString("}\n\n")
}

outputName := strings.TrimSuffix(*file, filepath.Ext(*file))
outputFilename := outputName + "_msgstrings.go"
if err := os.WriteFile(outputFilename, []byte(b.String()), 0644); err != nil {
return err
}

return nil
}
33 changes: 0 additions & 33 deletions cmd/run/first.go

This file was deleted.

17 changes: 0 additions & 17 deletions cmd/run/first_test.go

This file was deleted.

Loading
Loading