~kennylevinsen/drminspect

8913aa89f851fc86e1af84dad53713ce9f57d0d1 — Kenny Levinsen 9 months ago e4bfd99 master
Handle more inputs, highlight keywords
1 files changed, 16 insertions(+), 11 deletions(-)

M main.go
M main.go => main.go +16 -11
@@ 23,26 23,28 @@ outer:
	for {
		var block Block
		// Timestamp
		ts, err := buf.ReadSlice(' ')

		ts, err := buf.ReadSlice(']')
		if err != nil {
			if err != io.EOF {
				fmt.Fprintf(os.Stderr, "Read of timestamp failed: %v\n", err)
			}
			break
		}
		if ts[0] != '[' || ts[len(ts)-2] != ']' {
		if ts[0] != '[' || ts[len(ts)-1] != ']' {
			fmt.Fprintf(os.Stderr, "Invalid line start of line, skipping: '%s'\n", string(ts))
			buf.ReadLine()
			continue
		}
		// To lazy to deal with the '.'
		block.ts, err = strconv.ParseFloat(string(ts[1:len(ts)-2]), 64)
		block.ts, err = strconv.ParseFloat(strings.Trim(string(ts), "[] "), 64)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Could not parse timestamp: %v\n", err)
			buf.ReadLine()
			continue
		}
		

		buf.ReadByte()
		var prefix strings.Builder
		var module []byte
		for {


@@ 59,10 61,9 @@ outer:
			prefix.Write(module)
		}
		if prefix.Len() > 0 {
			prefixstr := prefix.String()
			block.prefix = prefixstr[0:len(prefixstr)-1]
			block.prefix = strings.Trim(prefix.String(), "[] ")
		}
		block.module = string(module[1:len(module)-2])
		block.module = strings.Trim(string(module), "[] ")

		logline, isPrefix, err := buf.ReadLine()
		if err != nil {


@@ 110,8 111,6 @@ func parseIoctl(line string) *Ioctl {
			ioctl.ret, _ = strconv.ParseInt(strings.Trim(part[4:], " ,"), 10, 64)
		case idx == len(parts) - 1:
			ioctl.command = part
		default:
			panic("Unexpected ioctl section: " + part)
		}
	}



@@ 121,6 120,7 @@ func parseIoctl(line string) *Ioctl {
type Commit struct {
	ioctl *Ioctl
	ret int64
	keyword string
	blocks []*Block
}



@@ 168,6 168,11 @@ func main() {
			}
		default:
			commit.blocks = append(commit.blocks, b)
			for _, keyword := range []string{"error", "failed", "busy"} {
				if strings.Contains(strings.ToLower(b.line), keyword) {
					commit.keyword = keyword
				}
			}
		}
	}
	if len(commit.blocks) > 0 {


@@ 178,9 183,9 @@ func main() {
		// List
		for idx, commit := range commits {
			if commit.ioctl == nil {
				fmt.Printf("%d: <no ioctl>: %d line(s)\n", idx, len(commit.blocks))
				fmt.Printf("%d: <no ioctl>: %d line(s) %s\n", idx, len(commit.blocks), commit.keyword)
			} else {
				fmt.Printf("%d: %s: %d line(s), %s (%d): %d\n", idx, commit.ioctl.command, len(commit.blocks), commit.ioctl.comm, commit.ioctl.pid, commit.ret)
				fmt.Printf("%d: %s: %d line(s), %s (%d): %d %s\n", idx, commit.ioctl.command, len(commit.blocks), commit.ioctl.comm, commit.ioctl.pid, commit.ret, commit.keyword)
			}
		}
	} else {