(basePath string, collection *support.PprofCollection, dest *zip.Writer)
| 579 | } |
| 580 | |
| 581 | func writePprofCollection(basePath string, collection *support.PprofCollection, dest *zip.Writer) error { |
| 582 | // Define the pprof files to write with their extensions |
| 583 | files := map[string][]byte{ |
| 584 | "allocs.prof.gz": collection.Allocs, |
| 585 | "heap.prof.gz": collection.Heap, |
| 586 | "profile.prof.gz": collection.Profile, |
| 587 | "block.prof.gz": collection.Block, |
| 588 | "mutex.prof.gz": collection.Mutex, |
| 589 | "goroutine.prof.gz": collection.Goroutine, |
| 590 | "threadcreate.prof.gz": collection.Threadcreate, |
| 591 | "trace.gz": collection.Trace, |
| 592 | } |
| 593 | |
| 594 | // Write binary pprof files |
| 595 | for filename, data := range files { |
| 596 | if len(data) > 0 { |
| 597 | filePath := basePath + "/" + filename |
| 598 | f, err := dest.Create(filePath) |
| 599 | if err != nil { |
| 600 | return xerrors.Errorf("create pprof file %q: %w", filePath, err) |
| 601 | } |
| 602 | if _, err := f.Write(data); err != nil { |
| 603 | return xerrors.Errorf("write pprof file %q: %w", filePath, err) |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | // Write cmdline as text file |
| 609 | if collection.Cmdline != "" { |
| 610 | filePath := basePath + "/cmdline.txt" |
| 611 | f, err := dest.Create(filePath) |
| 612 | if err != nil { |
| 613 | return xerrors.Errorf("create cmdline file %q: %w", filePath, err) |
| 614 | } |
| 615 | if _, err := f.Write([]byte(collection.Cmdline)); err != nil { |
| 616 | return xerrors.Errorf("write cmdline file %q: %w", filePath, err) |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | if collection.Symbol != "" { |
| 621 | filePath := basePath + "/symbol.txt" |
| 622 | f, err := dest.Create(filePath) |
| 623 | if err != nil { |
| 624 | return xerrors.Errorf("create symbol file %q: %w", filePath, err) |
| 625 | } |
| 626 | if _, err := f.Write([]byte(collection.Symbol)); err != nil { |
| 627 | return xerrors.Errorf("write symbol file %q: %w", filePath, err) |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | return nil |
| 632 | } |
| 633 | |
| 634 | func humanizeAgentLogs(ls []codersdk.WorkspaceAgentLog) string { |
| 635 | var buf bytes.Buffer |
no test coverage detected