Skip to content

Instantly share code, notes, and snippets.

@VladRassokhin
Created July 16, 2019 13:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save VladRassokhin/271d577ebb5a218fcefcd14134a696f8 to your computer and use it in GitHub Desktop.
Packer vmware-iso profiling patch
Index: helper/communicator/step_connect.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- helper/communicator/step_connect.go (revision 2eb80a81e39d760c77b165863866bbc72a3c5861)
+++ helper/communicator/step_connect.go (date 1563282177973)
@@ -4,6 +4,9 @@
"context"
"fmt"
"log"
+ "os"
+ "runtime"
+ "runtime/pprof"
"time"
"github.com/hashicorp/packer/communicator/none"
@@ -60,6 +63,31 @@
func (s *StepConnect) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
+ cf, err := os.Create("/tmp/step-connect.cpu.gz")
+ if err != nil {
+ state.Put("error", fmt.Errorf("failed to create file: %v", err))
+ return multistep.ActionHalt
+ }
+ //noinspection GoUnhandledErrorResult
+ defer cf.Close()
+ err = pprof.StartCPUProfile(cf)
+ if err != nil {
+ state.Put("error", fmt.Errorf("failed to start profiling: %v", err))
+ return multistep.ActionHalt
+ }
+ defer pprof.StopCPUProfile()
+ defer func() {
+ mf, err := os.Create("/tmp/step-connect.mem.gz")
+ if err == nil {
+ //noinspection GoUnhandledErrorResult
+ defer mf.Close()
+ runtime.GC() // materialize all statistics
+ if err := pprof.WriteHeapProfile(mf); err != nil {
+ state.Put("error", fmt.Errorf("failed to write memory profile: %v", err))
+ }
+ }
+ }()
+
typeMap := map[string]multistep.Step{
"none": nil,
"ssh": &StepConnectSSH{
Index: command/plugin.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- command/plugin.go (revision 2eb80a81e39d760c77b165863866bbc72a3c5861)
+++ command/plugin.go (date 1563282177972)
@@ -89,6 +89,9 @@
sleepprovisioner "github.com/hashicorp/packer/provisioner/sleep"
windowsrestartprovisioner "github.com/hashicorp/packer/provisioner/windows-restart"
windowsshellprovisioner "github.com/hashicorp/packer/provisioner/windows-shell"
+
+ "net/http"
+ _ "net/http/pprof"
)
type PluginCommand struct {
@@ -231,6 +234,10 @@
server.RegisterPostProcessor(postProcessor)
}
+ if pluginType == "builder" && pluginName == "vmware-iso" {
+ go http.ListenAndServe("127.0.0.1:8990", nil)
+ }
+
server.Serve()
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment