mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-10-04 07:26:28 +08:00
enable memgrind
This commit is contained in:
3
Makefile
3
Makefile
@@ -130,6 +130,9 @@ mem: clean
|
||||
go test -run @ -bench . -memprofile mem.out -memprofilerate 1 -timeout 24h
|
||||
go tool pprof -lines -web -alloc_space *.test mem.out
|
||||
|
||||
memgrind:
|
||||
GO111MODULE=off go test -v -timeout 24h -tags libc.memgrind -xtags=libc.memgrind
|
||||
|
||||
memgrind:
|
||||
go test -v -timeout 24h -tags=libc.memgrind,cgobench -run Test[^T][^c][^l] -bench . -recs_per_sec_as_mbps 2>&1 | tee log-memgrind
|
||||
|
||||
|
59
all_test.go
59
all_test.go
@@ -110,8 +110,8 @@ var (
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
fmt.Printf("test binary compiled for %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
||||
|
||||
flag.Parse()
|
||||
libc.MemAuditStart()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -131,16 +131,11 @@ func tempDB(t testing.TB) (string, *sql.DB) {
|
||||
}
|
||||
|
||||
func TestScalar(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
|
||||
dir, db := tempDB(t)
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
os.RemoveAll(dir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
t1 := time.Date(2017, 4, 20, 1, 2, 3, 56789, time.UTC)
|
||||
@@ -204,15 +199,11 @@ func TestScalar(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlob(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
dir, db := tempDB(t)
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
os.RemoveAll(dir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
b1 := []byte(time.Now().String())
|
||||
@@ -260,7 +251,6 @@ func TestBlob(t *testing.T) {
|
||||
}
|
||||
|
||||
func benchmarkInsertMemory(b *testing.B, n int) {
|
||||
libc.MemAuditStart()
|
||||
db, err := sql.Open(driverName, "file::memory:")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
@@ -268,9 +258,6 @@ func benchmarkInsertMemory(b *testing.B, n int) {
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
b.ReportAllocs()
|
||||
@@ -315,7 +302,6 @@ func BenchmarkInsertMemory(b *testing.B) {
|
||||
var staticInt int
|
||||
|
||||
func benchmarkNextMemory(b *testing.B, n int) {
|
||||
libc.MemAuditStart()
|
||||
db, err := sql.Open(driverName, "file::memory:")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
@@ -323,9 +309,6 @@ func benchmarkNextMemory(b *testing.B, n int) {
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := db.Exec(`
|
||||
@@ -387,16 +370,12 @@ func BenchmarkNextMemory(b *testing.B) {
|
||||
|
||||
// https://gitlab.com/cznic/sqlite/issues/11
|
||||
func TestIssue11(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
const N = 6570
|
||||
dir, db := tempDB(t)
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
os.RemoveAll(dir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := db.Exec(`
|
||||
@@ -419,7 +398,6 @@ func TestIssue11(t *testing.T) {
|
||||
|
||||
// https://gitlab.com/cznic/sqlite/issues/12
|
||||
func TestMemDB(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
// Verify we can create out-of-the heap memory DB instance.
|
||||
db, err := sql.Open(driverName, "file::memory:")
|
||||
if err != nil {
|
||||
@@ -428,9 +406,6 @@ func TestMemDB(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
v := strings.Repeat("a", 1024)
|
||||
@@ -458,7 +433,6 @@ func TestMemDB(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConcurrentGoroutines(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
const (
|
||||
ngoroutines = 8
|
||||
nrows = 5000
|
||||
@@ -471,9 +445,6 @@ func TestConcurrentGoroutines(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
os.RemoveAll(dir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
db, err := sql.Open(driverName, filepath.Join(dir, "test.db"))
|
||||
@@ -570,7 +541,6 @@ func TestConcurrentGoroutines(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConcurrentProcesses(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
dir, err := ioutil.TempDir("", "sqlite-test-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -578,9 +548,6 @@ func TestConcurrentProcesses(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
os.RemoveAll(dir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
m, err := filepath.Glob(filepath.FromSlash("internal/mptest/*"))
|
||||
@@ -668,7 +635,6 @@ outer:
|
||||
|
||||
// https://gitlab.com/cznic/sqlite/issues/19
|
||||
func TestIssue19(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
const (
|
||||
drop = `
|
||||
drop table if exists products;
|
||||
@@ -702,9 +668,6 @@ INSERT INTO "products" ("id", "user_id", "name", "description", "created_at", "c
|
||||
|
||||
defer func() {
|
||||
os.RemoveAll(dir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
wd, err := os.Getwd()
|
||||
@@ -794,7 +757,6 @@ func mustExec(t *testing.T, db *sql.DB, sql string, args ...interface{}) sql.Res
|
||||
|
||||
// https://gitlab.com/cznic/sqlite/issues/20
|
||||
func TestIssue20(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
const TablePrefix = "gosqltest_"
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "")
|
||||
@@ -804,9 +766,6 @@ func TestIssue20(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
os.RemoveAll(tempDir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
db, err := sql.Open("sqlite", filepath.Join(tempDir, "foo.db"))
|
||||
@@ -860,7 +819,6 @@ func TestIssue20(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNoRows(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
tempDir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -877,9 +835,6 @@ func TestNoRows(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
stmt, err := db.Prepare("create table t(i);")
|
||||
@@ -896,7 +851,6 @@ func TestNoRows(t *testing.T) {
|
||||
|
||||
// https://gitlab.com/cznic/sqlite/-/issues/28
|
||||
func TestIssue28(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
tempDir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -904,9 +858,6 @@ func TestIssue28(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
os.RemoveAll(tempDir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
db, err := sql.Open("sqlite", filepath.Join(tempDir, "test.db"))
|
||||
@@ -929,7 +880,6 @@ func TestIssue28(t *testing.T) {
|
||||
|
||||
// https://gitlab.com/cznic/sqlite/-/issues/30
|
||||
func TestIssue30(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
tempDir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -937,9 +887,6 @@ func TestIssue30(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
os.RemoveAll(tempDir)
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
db, err := sql.Open("sqlite", filepath.Join(tempDir, "test.db"))
|
||||
@@ -999,7 +946,6 @@ Col 3: DatabaseTypeName "DATE", DecimalSize 0 0 false, Length 922337203685477580
|
||||
|
||||
// https://gitlab.com/cznic/sqlite/-/issues/35
|
||||
func TestTime(t *testing.T) {
|
||||
libc.MemAuditStart()
|
||||
types := []string{
|
||||
"DATE",
|
||||
"DATETIME",
|
||||
@@ -1018,9 +964,6 @@ func TestTime(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
for _, typ := range types {
|
||||
|
@@ -40,7 +40,6 @@ func makename(inMemory bool, driver string, e int) string {
|
||||
}
|
||||
|
||||
func benchmarkRead(b *testing.B, drivername, file string, n int) {
|
||||
libc.MemAuditStart()
|
||||
os.Remove(file)
|
||||
db, err := sql.Open(drivername, file)
|
||||
if err != nil {
|
||||
@@ -49,9 +48,6 @@ func benchmarkRead(b *testing.B, drivername, file string, n int) {
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := db.Exec(`
|
||||
@@ -131,7 +127,6 @@ func BenchmarkReading1(b *testing.B) {
|
||||
}
|
||||
|
||||
func benchmarkInsertComparative(b *testing.B, drivername, file string, n int) {
|
||||
libc.MemAuditStart()
|
||||
os.Remove(file)
|
||||
db, err := sql.Open(drivername, file)
|
||||
if err != nil {
|
||||
@@ -140,9 +135,6 @@ func benchmarkInsertComparative(b *testing.B, drivername, file string, n int) {
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
if err := libc.MemAuditReport(); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := db.Exec(`
|
||||
|
4
go.mod
4
go.mod
@@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/mattn/go-sqlite3 v1.14.6
|
||||
modernc.org/libc v0.0.0-20210217113501-b71739ce7053
|
||||
modernc.org/libc v0.0.0-20210217173042-ace5bf44f22f
|
||||
modernc.org/mathutil v1.2.2
|
||||
modernc.org/tcl v0.0.0-20210126195340-ef4fe8b071b1
|
||||
modernc.org/tcl v0.0.0-20210217173959-693baba442b7
|
||||
)
|
||||
|
10
go.sum
10
go.sum
@@ -9,15 +9,13 @@ golang.org/x/sys v0.0.0-20201126233918-771906719818 h1:f1CIuDlJhwANEC2MM87MBEVMr
|
||||
golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
modernc.org/httpfs v1.0.2 h1:4aw8F68gTwx7FWL/vEMjm/XaPwPL16MItkF/P9ziEPY=
|
||||
modernc.org/httpfs v1.0.2/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
|
||||
modernc.org/libc v0.0.0-20210126194511-2b2d365b45c2 h1:tt8AD7ptNzdjMF6llxq3Fr1qmaH5I2pheV/QYtSyhjE=
|
||||
modernc.org/libc v0.0.0-20210126194511-2b2d365b45c2/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
|
||||
modernc.org/libc v0.0.0-20210217113501-b71739ce7053 h1:tqwdWVp1JL8OhoaXR7kAiAZw9ml9DVVemn+eUMjID1A=
|
||||
modernc.org/libc v0.0.0-20210217113501-b71739ce7053/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
|
||||
modernc.org/libc v0.0.0-20210217173042-ace5bf44f22f h1:KpQ4RCk1PyU+5P/g8YFfUvWAdYgc8dNwPLn1fl68NNw=
|
||||
modernc.org/libc v0.0.0-20210217173042-ace5bf44f22f/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
|
||||
modernc.org/mathutil v1.1.1 h1:FeylZSVX8S+58VsyJlkEj2bcpdytmp9MmDKZkKx8OIE=
|
||||
modernc.org/mathutil v1.1.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||
modernc.org/mathutil v1.2.2 h1:+yFk8hBprV+4c0U9GjFtL+dV3N8hOJ8JCituQcMShFY=
|
||||
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||
modernc.org/memory v1.0.4 h1:utMBrFcpnQDdNsmM6asmyH/FM9TqLPS7XF7otpJmrwM=
|
||||
modernc.org/memory v1.0.4/go.mod h1:nV2OApxradM3/OVbs2/0OsP6nPfakXpi50C7dcoHXlc=
|
||||
modernc.org/tcl v0.0.0-20210126195340-ef4fe8b071b1 h1:yrRH+qqPVEG63zwK8OHUn13KmV8JIr0mYH+oJDK/+M4=
|
||||
modernc.org/tcl v0.0.0-20210126195340-ef4fe8b071b1/go.mod h1:3zmINXxWd0ou2yESOionCdpu77iJutiqQuf3K3EGtA0=
|
||||
modernc.org/tcl v0.0.0-20210217173959-693baba442b7 h1:lEZA6Oqu4pFUd5lbhtxtBOoengBdHco+Y+BvCCmfoPg=
|
||||
modernc.org/tcl v0.0.0-20210217173959-693baba442b7/go.mod h1:rhl17/YyI3O0rqM7iL26itCedrmuuXIDNvcinbsnLKM=
|
||||
|
Reference in New Issue
Block a user