Ejemplo n.º 1
0
func Process(in io.Reader, out io.Writer) error {
	goroutines, err := stack.ParseDump(in, out)
	if err != nil {
		return err
	}
	buckets := stack.SortBuckets(stack.Bucketize(goroutines, true))
	srcLen, pkgLen := CalcLengths(buckets)
	for _, bucket := range buckets {
		extra := ""
		created := bucket.CreatedBy.Func.PkgDotName()
		if created != "" {
			if srcName := bucket.CreatedBy.SourceLine(); srcName != "" {
				created += " @ " + srcName
			}
			extra += ansi.LightBlack + " [Created by " + created + "]"
		}
		c := ansi.White
		if bucket.First() && len(buckets) > 1 {
			c = ansi.LightMagenta
		}

		fmt.Fprintf(out, "%s%d: %s%s%s\n", c, len(bucket.Routines), bucket.State, extra, ansi.Reset)
		fmt.Fprintf(out, "%s\n", PrettyStack(&bucket.Signature, srcLen, pkgLen))
	}
	return err
}
Ejemplo n.º 2
0
func processStackTrace(data string) string {
	out := &bytes.Buffer{}
	goroutines, err := stack.ParseDump(bytes.NewBufferString(data), out)
	if err != nil || len(goroutines) == 0 {
		return data
	}
	buckets := stack.SortBuckets(stack.Bucketize(goroutines, true))
	srcLen, pkgLen := calcLengths(buckets)
	for _, bucket := range buckets {
		extra := ""
		created := bucket.CreatedBy.Func.PkgDotName()
		if created != "" {
			if srcName := bucket.CreatedBy.SourceLine(); srcName != "" {
				created += " @ " + srcName
			}
			extra += " [Created by " + created + "]"
		}

		fmt.Fprintf(out, "%d: %s%s\n", len(bucket.Routines), bucket.State, extra)
		fmt.Fprintf(out, "%s\n", prettyStack(&bucket.Signature, srcLen, pkgLen))
	}
	return out.String()
}