Skip to content

Commit

Permalink
fix xgo tool trace
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed May 16, 2024
1 parent 243d375 commit 3e5cf48
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cmd/xgo/runtime_gen/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"
)

const VERSION = "1.0.34"
const REVISION = "d73b24dafc105fe4610e9130b0db429892961b80+1"
const NUMBER = 215
const VERSION = "1.0.35"
const REVISION = "53b18b05f3c84c33887d7373607183daff63ce03+1"
const NUMBER = 216

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
64 changes: 55 additions & 9 deletions cmd/xgo/trace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,61 @@ import (
)

func Main(args []string) {
if len(args) == 0 {
var files []string
var port string
n := len(args)
for i := 0; i < n; i++ {
arg := args[i]
if arg == "--" {
files = append(files, args[i+1:]...)
break
}
if arg == "--port" {
if i+1 >= n {
fmt.Fprintf(os.Stderr, "--port requires arg\n")
os.Exit(1)
}
port = arg
continue
} else if strings.HasPrefix(arg, "--port=") {
port = strings.TrimPrefix(arg, "--port=")
continue
}
if !strings.HasPrefix(arg, "-") {
files = append(files, arg)
continue
}
fmt.Fprintf(os.Stderr, "unrecognized flag: %s\n", arg)
os.Exit(1)
}
if len(files) == 0 {
fmt.Fprintf(os.Stderr, "requires file\n")
os.Exit(1)
}
file := args[0]
serveFile(file)
if len(files) != 1 {
fmt.Fprintf(os.Stderr, "xgo tool trace requires exactly 1 file, given: %v", files)
os.Exit(1)
}
file := files[0]
if port == "" {
port = os.Getenv("PORT")
}
err := serveFile(port, file)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}

}

func serveFile(file string) {
func serveFile(portStr string, file string) error {
stat, err := os.Stat(file)
if err != nil {
return err
}
if stat.IsDir() {
return fmt.Errorf("expect a trace file, given dir: %s", file)
}
server := http.NewServeMux()
server.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
defer func() {
Expand Down Expand Up @@ -80,28 +126,28 @@ func serveFile(file string) {
})
var autoIncrPort bool
var port int
portStr := os.Getenv("PORT")
if portStr == "" {
port = 7070
autoIncrPort = true
} else {
parsePort, err := strconv.ParseInt(portStr, 10, 64)
if err != nil {
panic(fmt.Errorf("bad port: %s", portStr))
return fmt.Errorf("bad port: %s", portStr)
}
port = int(parsePort)
}
err := netutil.ServePort(port, autoIncrPort, 500*time.Millisecond, func(port int) {
url := fmt.Sprintf("http://localhost:%s", portStr)
err = netutil.ServePort(port, autoIncrPort, 500*time.Millisecond, func(port int) {
url := fmt.Sprintf("http://localhost:%d", port)
fmt.Printf("Server listen at %s\n", url)

openURL(url)
}, func(port int) error {
return http.ListenAndServe(fmt.Sprintf(":%d", port), server)
})
if err != nil {
panic(err)
return err
}
return nil
}

func openURL(url string) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import "fmt"

const VERSION = "1.0.34"
const REVISION = "d73b24dafc105fe4610e9130b0db429892961b80+1"
const NUMBER = 215
const VERSION = "1.0.35"
const REVISION = "53b18b05f3c84c33887d7373607183daff63ce03+1"
const NUMBER = 216

func getRevision() string {
revSuffix := ""
Expand Down
6 changes: 3 additions & 3 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"
)

const VERSION = "1.0.34"
const REVISION = "d73b24dafc105fe4610e9130b0db429892961b80+1"
const NUMBER = 215
const VERSION = "1.0.35"
const REVISION = "53b18b05f3c84c33887d7373607183daff63ce03+1"
const NUMBER = 216

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down

0 comments on commit 3e5cf48

Please sign in to comment.