appstats: Index | Files

package appstats

import ""

Package appstats profiles the RPC performance of Google App Engine applications.


To use this package, change your HTTP handler functions to use this signature:

func(appengine.Context, http.ResponseWriter, *http.Request)

Register them in the usual way, wrapping them with NewHandler.

Classic App Engine packages are available at


This is a small example using this package.

package main

import (


func init() {
	http.Handle("/", appstats.NewHandler(Main))

func Main(c context.Context, w http.ResponseWriter, r *http.Request) {
	// do stuff with c: datastore.Get(c, key, entity)


Use your app, and view the appstats interface at http://localhost:8080/_ah/stats/, or your production URL.


Refer to the variables section of the documentation:


In general, your app.yaml will not need to change. In the case of conflicting routes, add the following to your app.yaml:

- url: /_ah/stats/.*
  script: _go_app


Cost calculation is experimental. Currently it only includes write ops (read and small ops are TODO).


Package Files

appstats.go bytesize.go cost.go doc.go funcs.go handler.go html.go static.go types.go


var (
    // RecordFraction is the fraction of requests to record.
    // Set to a number between 0.0 (none) and 1.0 (all).
    RecordFraction float64 = 1.0

    // ShouldRecord is the function used to determine if recording will occur
    // for a given request. The default is to use RecordFraction.
    ShouldRecord = DefaultShouldRecord

    // ProtoMaxBytes is the amount of protobuf data to record.
    // Data after this is truncated.
    ProtoMaxBytes = 150

    // Namespace is the memcache namespace under which to store appstats data.
    Namespace = "__appstats__"

func DefaultShouldRecord Uses

func DefaultShouldRecord(r *http.Request) bool

DefaultShouldRecord will record a request based on RecordFraction.

func NewHandler Uses

func NewHandler(f func(context.Context, http.ResponseWriter, *http.Request)) http.Handler

NewHandler returns a new Handler that will execute f.

func NewHandlerFunc Uses

func NewHandlerFunc(f func(context.Context, http.ResponseWriter, *http.Request)) http.HandlerFunc

NewHandlerFunc returns a new HandlerFunc that will execute f.

func URL Uses

func URL(ctx context.Context) string

URL returns the appstats URL for the current request.

func WithContext Uses

func WithContext(ctx context.Context, method, path string, f func(context.Context))

WithContext enables profiling of functions without a corresponding request, as in the appengine/delay package. method and path may be empty.

Package appstats imports 21 packages (graph) and is imported by 40 packages. Updated 2017-02-09. Refresh now. Tools for package owners.