Skip to content

Commit 851fc33

Browse files
committed
Not sure
1 parent 88024b3 commit 851fc33

File tree

7 files changed

+94
-13
lines changed

7 files changed

+94
-13
lines changed

etc/samples.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/latest/owid-covid-latest.csv
2+
https://raw.githubusercontent.com/robert-koch-institut/COVID-19-Impfungen_in_Deutschland/master/Aktuell_Deutschland_Landkreise_COVID-19-Impfungen.csv
23
https://raw.githubusercontent.com/robert-koch-institut/COVID-19-Impfungen_in_Deutschland/master/Aktuell_Deutschland_Bundeslaender_COVID-19-Impfungen.csv
34
https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv
45
https://people.sc.fsu.edu/~jburkardt/data/csv/airtravel.csv

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/hashicorp/go-multierror v1.1.1
1010
github.com/mattn/go-sqlite3 v1.14.8
1111
github.com/rjeczalik/notify v0.9.2
12+
github.com/xuri/excelize/v2 v2.4.1
1213
golang.org/x/text v0.3.7
1314
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
1415
)
@@ -19,7 +20,6 @@ require (
1920
github.com/richardlehane/mscfb v1.0.3 // indirect
2021
github.com/richardlehane/msoleps v1.0.1 // indirect
2122
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 // indirect
22-
github.com/xuri/excelize/v2 v2.4.1 // indirect
2323
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
2424
golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect
2525
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
22
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962/go.mod h1:kC29dT1vFpj7py2OvG1khBdQpo3kInWP+6QipLbdngo=
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
45
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
56
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
67
github.com/djthorpe/go-errors v1.0.2 h1:kZuNLhb6Yo1iNHaenGa9s5CpRbOG6KxbUtrME4LrAkk=
@@ -24,6 +25,7 @@ github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0
2425
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
2526
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
2627
github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
28+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2729
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2830
github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj3nKI=
2931
github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
@@ -33,6 +35,7 @@ github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w
3335
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
3436
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3537
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
38+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
3639
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
3740
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 h1:EpI0bqf/eX9SdZDwlMmahKM+CDBgNbsXMhsN28XrM8o=
3841
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
@@ -43,6 +46,7 @@ golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPh
4346
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
4447
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
4548
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
49+
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
4650
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
4751
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
4852
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=

pkg/sqlite3/pool.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Pool struct {
4545
ctx context.Context
4646
cancel context.CancelFunc
4747
n int32
48+
q *profilearray
4849
}
4950

5051
////////////////////////////////////////////////////////////////////////////////
@@ -119,6 +120,11 @@ func OpenPool(config PoolConfig, errs chan<- error) (*Pool, error) {
119120
p.Pool.Put(conn)
120121
}
121122

123+
// If trace is enabled, create a profile array
124+
if config.Trace {
125+
p.q = NewProfileArray(0, 0, 0)
126+
}
127+
122128
// Return success
123129
return p, nil
124130
}
@@ -132,6 +138,12 @@ func (p *Pool) Close() error {
132138
p.cancel()
133139
p.Wait()
134140

141+
// Close tracing
142+
if p.q != nil {
143+
p.q.Close()
144+
p.q = nil
145+
}
146+
135147
// Return success
136148
return nil
137149
}
@@ -219,6 +231,18 @@ func (p *Pool) Put(conn SQConnection) {
219231
}
220232
}
221233

234+
// Return up to n slow queries
235+
func (p *Pool) SlowQueries(n int) []SQSlowQuery {
236+
if p.q == nil {
237+
return nil
238+
}
239+
results := make([]SQSlowQuery, 0, intMax(0, n))
240+
for _, q := range p.q.SlowQueries(n) {
241+
results = append(results, q)
242+
}
243+
return results
244+
}
245+
222246
////////////////////////////////////////////////////////////////////////////////
223247
// PRIVATE METHODS
224248

@@ -372,13 +396,7 @@ func (p *Pool) attachCreate(path string) error {
372396

373397
// Trace
374398
func (p *Pool) trace(c *Conn, s *sqlite3.Statement, ns int64) {
375-
fmt.Printf("TRACE %q => %v\n", s, time.Duration(ns)*time.Nanosecond)
376-
}
377-
378-
// maxInt32 returns the maximum of two values
379-
func maxInt32(a, b int32) int32 {
380-
if a > b {
381-
return a
399+
if p.q != nil {
400+
p.q.Add(s.SQL(), time.Duration(ns)*time.Nanosecond)
382401
}
383-
return b
384402
}

pkg/sqlite3/util.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sqlite3
33
import (
44
"strconv"
55
"strings"
6+
"time"
67
)
78

89
////////////////////////////////////////////////////////////////////////////////
@@ -45,10 +46,42 @@ func stringToBool(v string) bool {
4546
}
4647
}
4748

48-
// intMax returns the maximum of two ints
49+
// intMax returns the maximum of two int values
4950
func intMax(a, b int) int {
5051
if a > b {
5152
return a
5253
}
5354
return b
5455
}
56+
57+
// intMin returns the minimum of two int values
58+
func intMin(a, b int) int {
59+
if a < b {
60+
return a
61+
}
62+
return b
63+
}
64+
65+
// maxInt32 returns the maximum of two int32 values
66+
func maxInt32(a, b int32) int32 {
67+
if a > b {
68+
return a
69+
}
70+
return b
71+
}
72+
73+
// durationMin returns the minimum of two time.Duration values
74+
func durationMin(a, b time.Duration) time.Duration {
75+
if a < b {
76+
return a
77+
}
78+
return b
79+
}
80+
81+
// durationMax returns the maximum of two time.Duration values
82+
func durationMax(a, b time.Duration) time.Duration {
83+
if a > b {
84+
return a
85+
}
86+
return b
87+
}

plugin/sqlite3/handlers.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,11 @@ func (p *plugin) ServeTable(w http.ResponseWriter, req *http.Request) {
247247
}
248248
defer p.Put(conn)
249249

250-
// Check for schema
250+
// Check for schema and table
251251
if !stringSliceContainsElement(conn.Schemas(), params[0]) {
252252
router.ServeError(w, http.StatusNotFound, "Schema not found", strconv.Quote(params[0]))
253253
return
254-
}
255-
if !stringSliceContainsElement(conn.Tables(params[0]), params[1]) {
254+
} else if !stringSliceContainsElement(conn.Tables(params[0]), params[1]) {
256255
router.ServeError(w, http.StatusNotFound, "Table not found", strconv.Quote(params[1]))
257256
return
258257
}

sqlite.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"reflect"
66
"strings"
7+
"time"
78
)
89

910
const (
@@ -45,6 +46,10 @@ type SQPool interface {
4546
// the maximum instantly, it will settle to this value over time. Set as value
4647
// zero to disable opening new connections
4748
SetMax(int32)
49+
50+
// SlowQueries returns the slowest N queries if tracing is switched on, returns
51+
// nil if no tracing has been turned on
52+
SlowQueries(n int) []SQSlowQuery
4853
}
4954

5055
// SQConnection is an sqlite connection to one or more databases
@@ -137,6 +142,27 @@ type SQAuth interface {
137142
CanExec(context.Context, SQAuthFlag, string, ...string) error
138143
}
139144

145+
// SQSlowQuery returns a profile for a query
146+
type SQSlowQuery interface {
147+
// Return the query text
148+
SQL() string
149+
150+
// Return the minimum query time
151+
Min() time.Duration
152+
153+
// Return the maximum query time
154+
Max() time.Duration
155+
156+
// Return the mean average query time
157+
Mean() time.Duration
158+
159+
// Return the number of samples
160+
Count() int
161+
162+
// Return the period over which the samples were taken
163+
Delta() time.Duration
164+
}
165+
140166
///////////////////////////////////////////////////////////////////////////////
141167
// GLOBALS
142168

0 commit comments

Comments
 (0)