From ef5c2ca3374b574393f549d37b01a5b87774dd35 Mon Sep 17 00:00:00 2001 From: Robert Janetzko Date: Sun, 10 Apr 2022 21:27:37 +0000 Subject: [PATCH] profile --- .gitignore | 2 ++ go.mod | 2 +- go.sum | 4 ++-- main.go | 12 +++++++++++- model/world.go | 13 +++++++++++-- sample.sh | 4 ++++ 6 files changed, 31 insertions(+), 6 deletions(-) create mode 100755 sample.sh diff --git a/.gitignore b/.gitignore index 1c95a08..c18348f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ region*.xml legendsbrowser +*.pprof +*.png \ No newline at end of file diff --git a/go.mod b/go.mod index a0dc5d9..a1702bc 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,5 @@ go 1.18 require ( github.com/gorilla/mux v1.8.0 github.com/iancoleman/strcase v0.2.0 - github.com/sa-/slicefunk v0.1.2 + github.com/pkg/profile v1.6.0 ) diff --git a/go.sum b/go.sum index 942fad2..ff24b51 100644 --- a/go.sum +++ b/go.sum @@ -2,5 +2,5 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= -github.com/sa-/slicefunk v0.1.2 h1:uTQiyKCTwc0RKNxXmG6NNlm3J1LF2hKmLgtf9kRAld4= -github.com/sa-/slicefunk v0.1.2/go.mod h1:k0abNpV9EW8LIPl2+Hc9RiKsojKmsUhNNGFyMpjMTCI= +github.com/pkg/profile v1.6.0 h1:hUDfIISABYI59DyeB3OTay/HxSRwTQ8rB/H83k6r5dM= +github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18= diff --git a/main.go b/main.go index 36e4540..fb1c2e8 100644 --- a/main.go +++ b/main.go @@ -5,16 +5,26 @@ import ( "legendsbrowser/model" "legendsbrowser/server" "net/http" + _ "net/http/pprof" + "runtime" "github.com/gorilla/mux" + "github.com/pkg/profile" ) var world model.World func main() { + defer profile.Start(profile.MemProfile).Stop() + go func() { + http.ListenAndServe(":8081", nil) + }() + fmt.Println("Hallo Welt!") - world.Load("region1-00152-01-01-legends.xml") + // world.Load("region1-00152-01-01-legends.xml") + world.Load("region2-00195-01-01-legends.xml") + runtime.GC() world.Process() model.ListOtherElements(&world.HistoricalEvents) diff --git a/model/world.go b/model/world.go index 7075972..98436c6 100644 --- a/model/world.go +++ b/model/world.go @@ -3,7 +3,7 @@ package model import ( "encoding/xml" "fmt" - "io/ioutil" + "io" "os" "reflect" ) @@ -36,6 +36,10 @@ type World struct { EntityMap map[int]*Entity } +var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ CueaaaaceeeiiiAAEaAooouuyOU faiounN ") + +// var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñÑ ") + func (w *World) Load(file string) { xmlFile, err := os.Open(file) if err != nil { @@ -45,9 +49,14 @@ func (w *World) Load(file string) { fmt.Println("Successfully Opened users.xml") defer xmlFile.Close() - byteValue, _ := ioutil.ReadAll(xmlFile) + byteValue, _ := io.ReadAll(xmlFile) fmt.Println(len(byteValue)) + copy(byteValue[30:35], []byte("UTF-8")) + for i := range byteValue { + byteValue[i] = cp437[byteValue[i]] + } + err = xml.Unmarshal(byteValue, w) if err != nil { fmt.Println(err) diff --git a/sample.sh b/sample.sh new file mode 100755 index 0000000..0354ef0 --- /dev/null +++ b/sample.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +curl http://localhost:8081/debug/pprof/heap > heap.0.pprof +go tool pprof heap.0.pprof \ No newline at end of file