Skip to content

Commit 1cff840

Browse files
committed
The MySQL way
1 parent 70aca04 commit 1cff840

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

dump.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"reflect"
10+
"runtime"
1011
"text/template"
1112
"time"
1213
)
@@ -47,7 +48,9 @@ type metaData struct {
4748
}
4849

4950
const (
50-
version = "0.4.1"
51+
// Version is exported for other builds
52+
Version = "0.4.1"
53+
5154
defaultMaxAllowedPacket = 4194304
5255
)
5356

@@ -113,9 +116,12 @@ const nullType = "NULL"
113116
// Dump data using struct
114117
func (data *Data) Dump() error {
115118
meta := metaData{
116-
DumpVersion: version,
119+
DumpVersion: Version,
120+
}
121+
122+
if data.MaxAllowedPacket == 0 {
123+
data.MaxAllowedPacket = defaultMaxAllowedPacket
117124
}
118-
data.initMaxPacketSize()
119125

120126
if err := meta.updateServerVersion(data.Connection); err != nil {
121127
return err
@@ -191,17 +197,6 @@ func (data *Data) getTemplates() (err error) {
191197
return
192198
}
193199

194-
func (data *Data) initMaxPacketSize() {
195-
if data.MaxAllowedPacket <= 0 {
196-
data.MaxAllowedPacket = defaultMaxAllowedPacket
197-
198-
var maxSize int
199-
if err := data.Connection.QueryRow("SELECT @@global.max_allowed_packet;").Scan(&maxSize); err == nil {
200-
data.MaxAllowedPacket = maxSize
201-
}
202-
}
203-
}
204-
205200
func (data *Data) getTables() ([]string, error) {
206201
tables := make([]string, 0)
207202

@@ -400,7 +395,17 @@ func (table *table) Stream() <-chan string {
400395
insert.WriteString(",")
401396
}
402397
b.WriteTo(&insert)
403-
b.Reset()
398+
399+
// debug
400+
var m runtime.MemStats
401+
runtime.ReadMemStats(&m)
402+
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
403+
fmt.Print("\tBuffer = ", bToMiB(uint64(insert.Len())), " MiB")
404+
fmt.Print("\tCapacity = ", bToMiB(uint64(insert.Cap())), " MiB")
405+
fmt.Print("\tAlloc = ", bToMiB(m.Alloc), " MiB")
406+
fmt.Print("\tTotalAlloc = ", bToMiB(m.TotalAlloc), " MiB")
407+
fmt.Print("\tSys = ", bToMiB(m.Sys), " MiB")
408+
fmt.Print("\tNumGC = ", m.NumGC, "\n")
404409
}
405410
if insert.Len() != 0 {
406411
insert.WriteString(";")
@@ -409,3 +414,7 @@ func (table *table) Stream() <-chan string {
409414
}()
410415
return valueOut
411416
}
417+
418+
func bToMiB(b uint64) uint64 {
419+
return b / 1024 / 1024
420+
}

0 commit comments

Comments
 (0)