Skip to content

cmd/trace: generateTrace execute twice  #26861

@xuanjiazhen

Description

@xuanjiazhen

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions