forked from MTSR/mapserver
render timing
This commit is contained in:
parent
50348775c3
commit
4edd6e2f83
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
mapserver
|
||||
world.mt
|
||||
output
|
||||
|
@ -50,7 +50,7 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
|
||||
|
||||
metadata := buf.Bytes()
|
||||
|
||||
log.WithFields(logrus.Fields{"metadata-length": len(metadata)}).Debug("Parsing metadata")
|
||||
log.WithFields(logrus.Fields{"metadata-length": len(metadata)}).Trace("Parsing metadata")
|
||||
|
||||
offset := 0
|
||||
version := metadata[offset]
|
||||
|
10
mapblockrenderer/logger.go
Normal file
10
mapblockrenderer/logger.go
Normal file
@ -0,0 +1,10 @@
|
||||
package mapblockrenderer
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log *logrus.Entry
|
||||
func init(){
|
||||
log = logrus.WithFields(logrus.Fields{"prefix": "mapblockrenderer"})
|
||||
}
|
@ -7,6 +7,8 @@ import (
|
||||
"image"
|
||||
"image/draw"
|
||||
"errors"
|
||||
"time"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type MapBlockRenderer struct {
|
||||
@ -33,6 +35,13 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB
|
||||
return nil, errors.New("Z does not line up")
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
defer func(){
|
||||
t := time.Now()
|
||||
elapsed := t.Sub(start)
|
||||
log.WithFields(logrus.Fields{"elapsed":elapsed}).Debug("Rendering completed")
|
||||
}()
|
||||
|
||||
upLeft := image.Point{0, 0}
|
||||
lowRight := image.Point{IMG_SIZE, IMG_SIZE}
|
||||
img := image.NewNRGBA(image.Rectangle{upLeft, lowRight})
|
||||
@ -98,5 +107,9 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB
|
||||
}
|
||||
}
|
||||
|
||||
if foundBlocks == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return img, nil
|
||||
}
|
||||
|
@ -5,14 +5,19 @@ import (
|
||||
"io/ioutil"
|
||||
"mapserver/coords"
|
||||
"testing"
|
||||
"fmt"
|
||||
"mapserver/testutils"
|
||||
"mapserver/db"
|
||||
"mapserver/colormapping"
|
||||
"mapserver/mapblockaccessor"
|
||||
"image/png"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSimpleRender(t *testing.T) {
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -38,9 +43,23 @@ func TestSimpleRender(t *testing.T) {
|
||||
}
|
||||
|
||||
r := NewMapBlockRenderer(cache, c)
|
||||
img, _ := r.Render(coords.NewMapBlockCoords(0, 10, 0), coords.NewMapBlockCoords(0, -1, 0))
|
||||
os.Mkdir("../output", 0755)
|
||||
|
||||
for x := -3; x < 3; x++ {
|
||||
for z := -3; z < 3; z++ {
|
||||
img, _ := r.Render(coords.NewMapBlockCoords(x, 10, z), coords.NewMapBlockCoords(x, -1, z))
|
||||
|
||||
if img != nil {
|
||||
f, _ := os.Create(fmt.Sprintf("../output/image_%d_%d.png", x, z))
|
||||
start := time.Now()
|
||||
png.Encode(f, img)
|
||||
f.Close()
|
||||
t := time.Now()
|
||||
elapsed := t.Sub(start)
|
||||
log.WithFields(logrus.Fields{"elapsed":elapsed}).Debug("Encoding completed")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
f, _ := os.Create("image.png")
|
||||
png.Encode(f, img)
|
||||
f.Close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user