grafana / pyroscope

Continuous Profiling Platform. Debug performance issues down to a single line of code
https://grafana.com/oss/pyroscope/
GNU Affero General Public License v3.0
10.13k stars 614 forks source link

How grafana determines profile type ? #3719

Open pyhita opened 2 hours ago

pyhita commented 2 hours ago

I sampled the heap memory information of a Java program through async-profiler and uploaded it to pyroscope through HTTP. The following is the uploaded code:

func main() {
    pyroscopeServer := "http://localhost:4040"
    applicationName := fmt.Sprintf("kante-test-test-sg{lang=java,env=test}")

    // Pprof file path
    pprofFilePath := fmt.Sprintf("/Users/kante.yang/pprof/java-propf")

    flameGraphData, err := fileutils.ReadFile(pprofFilePath)

    // Pyroscope URL
    pyroscopeURL := fmt.Sprintf("%s/ingest?name=%s", pyroscopeServer, applicationName)
    fmt.Println(applicationName)
    fmt.Println(pyroscopeURL)

    // Create the HTTP request
    req, err := createPythonJavaReq(flameGraphData, pyroscopeURL)
    if err != nil {
        fmt.Println("Error creating request:", err)
        return
    }

    // Send the request
    client := &http.Client{Timeout: 10 * time.Second}
    resp, err := client.Do(req)
    defer resp.Body.Close()
    if err != nil {
        fmt.Println("Error sending request:", err)
        return
    }

    // Check the response status
    if resp.StatusCode == http.StatusOK {
        fmt.Println("Profile data successfully sent to Pyroscope.")
    } else {
        fmt.Printf("Failed to send data. Status code: %d, Message: %s\n", resp.StatusCode, resp.Status)
    }
}

func createPythonJavaReq(rawProfileData []byte, url string) (*http.Request, error) {
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(rawProfileData))
    if err != nil {
        return nil, errors.Wrap(err, "create pyroscope request error")
    }
    req.Header.Set("Content-Type", "application/octet-stream")

    return req, nil
}

I originally thought that pyroscope would automatically parse the format of the data. In fact, it did this for the data generated by pprof. However, after this data was uploaded to pyroscope, it was parsed into cpu, as shown below: Image

I'm not sure why this happens, or can I specify the profiletype when uploading data using the http api?

pyhita commented 40 minutes ago

I use this command to generate java profile data: profiler.sh -o collapsed -e allocs