Skip to content

Commit

Permalink
fix(flamegraph): Dispatch candidates using goroutine
Browse files Browse the repository at this point in the history
By dispatching candidates using a goroutine, we can immediately start reading
the results of the readjobs instead of waiting until all candidates have been
dispatched.
  • Loading branch information
Zylphrex committed Sep 4, 2024
1 parent 67e9107 commit d9282a4
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions internal/flamegraph/flamegraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,37 +483,39 @@ func GetFlamegraphFromCandidates(
results := make(chan storageutil.ReadJobResult, numCandidates)
defer close(results)

dispatchSpan := span.StartChild("dispatch candidates")
dispatchSpan.SetData("transaction_candidates", len(transactionProfileCandidates))
dispatchSpan.SetData("continuous_candidates", len(continuousProfileCandidates))

for _, candidate := range transactionProfileCandidates {
jobs <- profile.ReadJob{
Ctx: ctx,
OrganizationID: organizationID,
ProjectID: candidate.ProjectID,
ProfileID: candidate.ProfileID,
Storage: storage,
Result: results,
go func() {
dispatchSpan := span.StartChild("dispatch candidates")
dispatchSpan.SetData("transaction_candidates", len(transactionProfileCandidates))
dispatchSpan.SetData("continuous_candidates", len(continuousProfileCandidates))

for _, candidate := range transactionProfileCandidates {
jobs <- profile.ReadJob{
Ctx: ctx,
OrganizationID: organizationID,
ProjectID: candidate.ProjectID,
ProfileID: candidate.ProfileID,
Storage: storage,
Result: results,
}
}
}

for _, candidate := range continuousProfileCandidates {
jobs <- chunk.ReadJob{
Ctx: ctx,
OrganizationID: organizationID,
ProjectID: candidate.ProjectID,
ProfilerID: candidate.ProfilerID,
ChunkID: candidate.ChunkID,
TransactionID: candidate.TransactionID,
ThreadID: candidate.ThreadID,
Start: candidate.Start,
End: candidate.End,
Storage: storage,
Result: results,
for _, candidate := range continuousProfileCandidates {
jobs <- chunk.ReadJob{
Ctx: ctx,
OrganizationID: organizationID,
ProjectID: candidate.ProjectID,
ProfilerID: candidate.ProfilerID,
ChunkID: candidate.ChunkID,
TransactionID: candidate.TransactionID,
ThreadID: candidate.ThreadID,
Start: candidate.Start,
End: candidate.End,
Storage: storage,
Result: results,
}
}
}
dispatchSpan.Finish()
dispatchSpan.Finish()
}()

var flamegraphTree []*nodetree.Node

Expand Down

0 comments on commit d9282a4

Please sign in to comment.