├── README.md
├── .gitmodules
├── miniprofiler_martini
├── miniprofiler_martini.go
└── doc.go
├── miniprofiler
├── templates.go
├── context.go
├── doc.go
├── types.go
├── miniprofiler.go
└── static.go
├── example
└── main.go
├── miniprofiler_revel
├── miniprofiler_revel.go
└── doc.go
├── miniprofiler_traffic
├── miniprofiler_traffic.go
└── doc.go
├── miniprofiler_beego
├── miniprofiler_beego.go
└── doc.go
├── miniprofiler_gocraftweb
├── miniprofiler_gocraftweb.go
└── doc.go
├── miniprofiler_gae
├── doc.go
└── miniprofiler_gae.go
├── sql
└── sql.go
└── redis
└── redis.go
/README.md:
--------------------------------------------------------------------------------
1 | go
2 | ==
3 |
4 | A simple but effective mini-profiler for Go websites
5 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "ui"]
2 | path = ui
3 | url = git@github.com:MiniProfiler/ui.git
4 |
--------------------------------------------------------------------------------
/miniprofiler_martini/miniprofiler_martini.go:
--------------------------------------------------------------------------------
1 | package miniprofiler_martini
2 |
3 | import (
4 | "net/http"
5 | "strings"
6 |
7 | "github.com/MiniProfiler/go/miniprofiler"
8 | "github.com/codegangsta/martini"
9 | )
10 |
11 | type Timer interface {
12 | miniprofiler.Timer
13 | }
14 |
15 | func Profiler() martini.Handler {
16 | return func(c martini.Context, w http.ResponseWriter, r *http.Request) {
17 | if strings.HasPrefix(r.URL.Path, miniprofiler.PATH) {
18 | miniprofiler.MiniProfilerHandler(w, r)
19 | return
20 | }
21 | p := miniprofiler.NewProfile(w, r, r.URL.Path)
22 | c.MapTo(p, (*Timer)(nil))
23 | c.Next()
24 | p.Finalize()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/miniprofiler/templates.go:
--------------------------------------------------------------------------------
1 | package miniprofiler
2 |
3 | import (
4 | "html/template"
5 | "io/ioutil"
6 | "strings"
7 | )
8 |
9 | var includePartialHtmlTmpl = parseInclude("include", "/include.partial.html")
10 | var shareHtmlTmpl = parseInclude("share", "/share.html")
11 |
12 | func parseInclude(name string, fname string) *template.Template {
13 | f, err := webFS.Open(fname)
14 | if err != nil {
15 | panic(err)
16 | }
17 | t, err := ioutil.ReadAll(f)
18 | if err != nil {
19 | panic(err)
20 | }
21 | f.Close()
22 | s := string(t)
23 | s = strings.Replace(s, "{", "{{.", -1)
24 | s = strings.Replace(s, "}", "}}", -1)
25 | return template.Must(template.New(name).Parse(s))
26 | }
27 |
--------------------------------------------------------------------------------
/example/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 |
7 | _ "code.google.com/p/go-sqlite/go1/sqlite3"
8 | "github.com/MiniProfiler/go/miniprofiler"
9 | "github.com/MiniProfiler/go/redis"
10 | "github.com/MiniProfiler/go/sql"
11 | )
12 |
13 | func Index(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) {
14 | db, _ := sql.Open("sqlite3", ":memory:")
15 | db.ExecTimer(t, "create table x(a, b, c)")
16 | db.ExecTimer(t, "insert into x (1, 2, 4), (3, 5, 6)")
17 | db.QueryTimer(t, "select * from x")
18 | t.Step("redissss", func(t miniprofiler.Timer) {
19 | conn, _ := redis.Dial("tcp", ":6379")
20 | defer conn.Close()
21 | conn.DoTimer(t, "set", "tes t", "value")
22 | conn.SendTimer(t, "get", "test t")
23 | })
24 | fmt.Fprintf(w, `
%v`, t.Includes())
25 | }
26 |
27 | func main() {
28 | miniprofiler.TrivialMilliseconds = 0
29 | http.Handle("/", miniprofiler.NewHandler(Index))
30 | fmt.Println("serving")
31 | http.ListenAndServe(":8080", nil)
32 | }
33 |
--------------------------------------------------------------------------------
/miniprofiler_revel/miniprofiler_revel.go:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013 Matt Jibson
3 | *
4 | * Permission to use, copy, modify, and distribute this software for any
5 | * purpose with or without fee is hereby granted, provided that the above
6 | * copyright notice and this permission notice appear in all copies.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 | */
16 |
17 | package miniprofiler_revel
18 |
19 | import (
20 | "strings"
21 |
22 | "github.com/MiniProfiler/go/miniprofiler"
23 | "github.com/revel/revel"
24 | )
25 |
26 | func Filter(c *revel.Controller, fc []revel.Filter) {
27 | ok := miniprofiler.Enable(c.Request.Request)
28 | if ok && strings.HasPrefix(c.Request.Request.URL.Path, miniprofiler.PATH) {
29 | miniprofiler.MiniProfilerHandler(c.Response.Out, c.Request.Request)
30 | return
31 | }
32 | p := miniprofiler.NewProfile(c.Response.Out, c.Request.Request, c.Action)
33 | c.Args["miniprofiler"] = p
34 | if ok {
35 | c.RenderArgs["miniprofiler"] = p.Includes()
36 | }
37 | fc[0](c, fc[1:])
38 | if ok {
39 | p.SetName(c.Action)
40 | p.Finalize()
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/miniprofiler_martini/doc.go:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013 Matt Jibson
3 | *
4 | * Permission to use, copy, modify, and distribute this software for any
5 | * purpose with or without fee is hereby granted, provided that the above
6 | * copyright notice and this permission notice appear in all copies.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 | */
16 |
17 | /*
18 | Package miniprofiler_martini is a simple but effective mini-profiler for martini.
19 |
20 | To use this package, import:
21 |
22 | import mmp "github.com/MiniProfiler/go/miniprofiler_martini"
23 |
24 | Add the middleware:
25 |
26 | m.Use(mmp.Profiler())
27 |
28 | Now a mmp.Timer object is available via the injector. Call p.Includes() like
29 | normal and add it to your template.
30 |
31 | Example
32 |
33 | func main() {
34 | m := martini.Classic()
35 | m.Use(mmp.Profiler())
36 | m.Get("/", func(p mmp.Timer, r *http.Request) string {
37 | return fmt.Sprintf("%v", p.Includes())
38 | })
39 | m.Run()
40 | }
41 |
42 | See the miniprofiler package docs about further usage: http://godoc.org/github.com/MiniProfiler/go/miniprofiler.
43 | */
44 | package miniprofiler_martini
45 |
--------------------------------------------------------------------------------
/miniprofiler_traffic/miniprofiler_traffic.go:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013 Matt Jibson
3 | *
4 | * Permission to use, copy, modify, and distribute this software for any
5 | * purpose with or without fee is hereby granted, provided that the above
6 | * copyright notice and this permission notice appear in all copies.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 | */
16 |
17 | package miniprofiler_traffic
18 |
19 | import (
20 | "strings"
21 |
22 | "github.com/MiniProfiler/go/miniprofiler"
23 | "github.com/pilu/traffic"
24 | )
25 |
26 | type Middleware struct{}
27 |
28 | func (c *Middleware) ServeHTTP(w traffic.ResponseWriter, r *traffic.Request, next traffic.NextMiddlewareFunc) {
29 | ok := miniprofiler.Enable(r.Request)
30 | if ok && strings.HasPrefix(r.Request.URL.Path, miniprofiler.PATH) {
31 | miniprofiler.MiniProfilerHandler(w, r.Request)
32 | return
33 | }
34 | p := miniprofiler.NewProfile(w, r.Request, r.URL.Path)
35 | w.SetVar("miniprofiler", p.Includes())
36 | w.SetVar("miniprofiler_timer", p)
37 | if nextMiddleware := next(); nextMiddleware != nil {
38 | nextMiddleware.ServeHTTP(w, r, next)
39 | }
40 | if ok {
41 | p.Finalize()
42 | }
43 | return
44 | }
45 |
--------------------------------------------------------------------------------
/miniprofiler_beego/miniprofiler_beego.go:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013 Matt Jibson
3 | *
4 | * Permission to use, copy, modify, and distribute this software for any
5 | * purpose with or without fee is hereby granted, provided that the above
6 | * copyright notice and this permission notice appear in all copies.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 | */
16 |
17 | package miniprofiler_beego
18 |
19 | import (
20 | "strings"
21 |
22 | "github.com/MiniProfiler/go/miniprofiler"
23 | "github.com/astaxie/beego/context"
24 | )
25 |
26 | func BeforeRouter(c *context.Context) {
27 | ok := miniprofiler.Enable(c.Request)
28 | if ok && strings.HasPrefix(c.Request.URL.Path, miniprofiler.PATH) {
29 | miniprofiler.MiniProfilerHandler(c.ResponseWriter, c.Request)
30 | return
31 | }
32 | p := miniprofiler.NewProfile(c.ResponseWriter, c.Request, c.Request.URL.Path)
33 | c.Input.Data["__miniprofiler"] = p
34 | if ok {
35 | c.Input.Data["miniprofiler"] = p.Includes()
36 | }
37 | }
38 |
39 | func AfterExec(c *context.Context) {
40 | d, present := c.Input.Data["__miniprofiler"]
41 | if !present {
42 | return
43 | }
44 | p, ok := d.(*miniprofiler.Profile)
45 | if ok {
46 | p.Finalize()
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/miniprofiler_gocraftweb/miniprofiler_gocraftweb.go:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013 Matt Jibson
3 | *
4 | * Permission to use, copy, modify, and distribute this software for any
5 | * purpose with or without fee is hereby granted, provided that the above
6 | * copyright notice and this permission notice appear in all copies.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 | */
16 |
17 | package miniprofiler_gocraftweb
18 |
19 | import (
20 | "html/template"
21 | "strings"
22 |
23 | "github.com/MiniProfiler/go/miniprofiler"
24 | "github.com/gocraft/web"
25 | )
26 |
27 | type MiniProfilerContext struct {
28 | MiniProfilerTemplate template.HTML
29 | MiniProfilerTimer miniprofiler.Timer
30 | }
31 |
32 | func (c *MiniProfilerContext) MiniProfileMiddleware(rw web.ResponseWriter, r *web.Request, next web.NextMiddlewareFunc) {
33 | ok := miniprofiler.Enable(r.Request)
34 | if ok && strings.HasPrefix(r.Request.URL.Path, miniprofiler.PATH) {
35 | miniprofiler.MiniProfilerHandler(rw, r.Request)
36 | return
37 | }
38 | p := miniprofiler.NewProfile(rw, r.Request, r.URL.Path)
39 | c.MiniProfilerTemplate = p.Includes()
40 | c.MiniProfilerTimer = p
41 | next(rw, r)
42 | if ok {
43 | p.Finalize()
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/miniprofiler_revel/doc.go:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013 Matt Jibson
3 | *
4 | * Permission to use, copy, modify, and distribute this software for any
5 | * purpose with or without fee is hereby granted, provided that the above
6 | * copyright notice and this permission notice appear in all copies.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 | */
16 |
17 | /*
18 | Package miniprofiler_revel is a simple but effective mini-profiler for revel.
19 |
20 | To use this package, in init.go, import:
21 |
22 | import mpr "github.com/MiniProfiler/go/miniprofiler_revel"
23 |
24 | and add mpr.Filter above revel.RouterFilter:
25 |
26 | revel.Filters = []revel.Filter{
27 | revel.PanicFilter,
28 | mpr.Filter,
29 | revel.RouterFilter,
30 | ...
31 |
32 | Add {{.miniprofiler}} to your footer template right before