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

cmd/trace: generateTrace execute twice #26861

Closed
xuanjiazhen opened this issue Aug 8, 2018 · 4 comments
Closed

cmd/trace: generateTrace execute twice #26861

xuanjiazhen opened this issue Aug 8, 2018 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@xuanjiazhen
Copy link

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 8, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Aug 8, 2018
@hyangah
Copy link
Contributor

hyangah commented Aug 8, 2018

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

@xuanjiazhen
Copy link
Author

@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
	}

@ianlancetaylor ianlancetaylor modified the milestones: Go1.12, Go1.13 Dec 10, 2018
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@agnivade
Copy link
Contributor

The code is entirely different now. Please let us know if you are still seeing the problem at tip. Thanks.

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 22, 2019
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Nov 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

7 participants