Skip to content

Commit

Permalink
read PxL from file
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo committed Nov 29, 2023
1 parent 16a1386 commit aea7b5d
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,13 @@ import (
"context"
"fmt"
"io"
"os"

"px.dev/pxapi"
"px.dev/pxapi/errdefs"
"px.dev/pxapi/types"
)

// Define PxL script with one table output.
var (
pxl = `
import px
# Look at the http_events.
df = px.DataFrame(table='http_events')
# Grab the command line from the metadata.
df.cmdline = px.upid_to_cmdline(df.upid)
# Limit to the first 10.
df = df.head(10)
px.display(df)`
)

func main() {
// Create a Pixie client with local standalonePEM listening address
ctx := context.Background()
Expand All @@ -38,19 +22,30 @@ func main() {
if err != nil {
panic(err)
}

// Create a connection to the host.
hostID := "localhost"
vz, err := client.NewVizierClient(ctx, hostID)
if err != nil {
panic(err)
}

// Create TableMuxer to accept results table.
tm := &tableMux{}

// Read PxL script from file
content, err := os.ReadFile("./config/config.pxl")
if err != nil {
panic(err)
}
pxl := string(content)

// Execute the PxL script.
resultSet, err := vz.ExecuteScript(ctx, pxl, tm)
if err != nil && err != io.EOF {
panic(err)
}

// Receive the PxL script results.
defer resultSet.Close()
if err := resultSet.Stream(); err != nil {
Expand All @@ -60,6 +55,7 @@ func main() {
fmt.Printf("Got error : %+v, while streaming\n", err)
}
}

// Get the execution stats for the script execution.
stats := resultSet.Stats()
fmt.Printf("Execution Time: %v\n", stats.ExecutionTime)
Expand Down

0 comments on commit aea7b5d

Please sign in to comment.