예제 #1
0
파일: main.go 프로젝트: Redundancy/pprofit
func main() {
	var err error
	cmd := exec.Command("sampleapp.exe")

	if err != nil {
		log.Fatalf("Could not find and run sampleapp: %v", err)
	}

	if err = cmd.Start(); err != nil {
		log.Fatalf("failed to start sample app: %v", err)
	}
	defer cmd.Process.Kill()

	// Needed to just allow the sample app to start up
	// Better would be to check the status (http and exit code) until it's ready
	time.Sleep(time.Second)

	log.Println("Starting profile collection (this will take ~30 secs)")
	fetcher := &httpFetcher.HttpFetcher{}
	buffer, err := fetcher.GetProfile()
	log.Println("Done collecting profile")

	if err != nil {
		log.Fatal(err)
	}

	profile, err := pprofReader.ReadProfile(buffer)
	if err != nil {
		log.Fatalf("Error reading the profile: %v", err)
	}

	functions := profile.Samples.UniqueFunctions()
	pointerToNameMap, err := fetcher.GetFunctionNames(functions)

	if err != nil {
		log.Fatalf("Error getting function name symbols for profile: %v", err)
	}

	log.Println("Grinding callstack")
	crunchedProfile := &callgrinder.CPUProfile{}
	for _, sample := range profile.Samples {
		crunchedProfile.AddSample(
			sample.SampleCount,
			SampleFunctionsToIdentifiers(sample, pointerToNameMap)...,
		)
	}

	//PrintSamples(profile.Samples, pointerToNameMap)
	crunchedProfile.Print()
}
예제 #2
0
파일: fetch.go 프로젝트: Redundancy/pprofit
func Fetch(c *cli.Context) {
	fetcher := &httpFetcher.HttpFetcher{
		Server:          c.String("server"),
		Port:            uint(c.Int("port")),
		ProfileDuration: time.Duration(c.Int("duration")) * time.Second,
	}

	buffer, err := fetcher.GetProfile()

	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	profile, err := pprofReader.ReadProfile(buffer)
	if err != nil {
		log.Fatalf("Error reading the profile: %v", err)
		os.Exit(1)
	}

	functions := profile.Samples.UniqueFunctions()
	pointerToNameMap, err := fetcher.GetFunctionNames(functions)

	if err != nil {
		log.Fatalf("Error getting function name symbols for profile: %v", err)
		os.Exit(1)
	}

	crunchedProfile := &callgrinder.CPUProfile{}
	for _, sample := range profile.Samples {
		crunchedProfile.AddSample(
			sample.SampleCount,
			SampleFunctionsToIdentifiers(sample, pointerToNameMap)...,
		)
	}

	crunchedProfile.Print()
}