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

cmd/trace: generateTrace execute twice #26861

Open
xuanjiazhen opened this Issue Aug 8, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@xuanjiazhen

xuanjiazhen commented Aug 8, 2018

the func generateTrace in go1.10.3

https://github.com/golang/go/blob/go1.10.3/src/cmd/trace/main.go line 124

log.Print("Serializing trace...")
	params := &traceParams{
		parsed:  res,
		endTime: int64(1<<63 - 1),
	}
	data, err := generateTrace(params)   //first 
	if err != nil {
		dief("%v\n", err)
	}

https://github.com/golang/go/blob/go1.10.3/src/cmd/trace/trace.go line 183

if goids := r.FormValue("goid"); goids != "" {
		// If goid argument is present, we are rendering a trace for this particular goroutine.
		goid, err := strconv.ParseUint(goids, 10, 64)
		if err != nil {
			log.Printf("failed to parse goid parameter '%v': %v", goids, err)
			return
		}
		analyzeGoroutines(res.Events)
		g := gs[goid]
		params.gtrace = true
		params.startTime = g.StartTime
		params.endTime = g.EndTime
		params.maing = goid
		params.gs = trace.RelatedGoroutines(res.Events, goid)
	}

	data, err := generateTrace(params)  //second

I got a 90M traceout file.when I run go tool trace traceout.out ,this func will executed more than 10 seconds. When I click on the link (view trace (0s-xxxxxs)), I will wait another 10 seconds. It will be executed again with the same params. It only makes sense when goid!="".

when I changed the generateTrace func's return value to a global varible,the web browser speed improved significantly.

Is this designed to be this or a negligence? Is it better to change the return value to a global variable?

@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Aug 8, 2018

@hyangah

This comment has been minimized.

Contributor

hyangah commented Aug 8, 2018

The corresponding code path was changed a lot recently, so no longer relevant to Go1.12.

@xuanjiazhen

This comment has been minimized.

xuanjiazhen commented Aug 10, 2018

@hyangah
This problem seems to exist in another form on the latest branch. Although the situation is somewhat different, it is still twice.And The new change seems to make it difficult to solve this problem.
https://github.com/golang/go/blob/master/src/cmd/trace/main.go

        log.Print("Splitting trace...")
	ranges = splitTrace(res)
	reportMemoryUsage("after spliting trace")
	debug.FreeOSMemory()

https://github.com/golang/go/blob/master/src/cmd/trace/trace.go line 288

func splitTrace(res trace.ParseResult) []Range {
	params := &traceParams{
		parsed:  res,
		endTime: math.MaxInt64,
	}
	s, c := splittingTraceConsumer(100 << 20) // 100M
	if err := generateTrace(params, c); err != nil {    //first
		dief("%v\n", err)
	}
	return s.Ranges
}

https://github.com/golang/go/blob/master/src/cmd/trace/trace.go line 267

if err := generateTrace(params, c); err != nil {
		log.Printf("failed to generate trace: %v", err)
		return
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment