github.com/jgbaldwinbrown/perf@v0.1.1/analysis/localperf/app.go (about)

     1  // Copyright 2017 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Localperf runs an HTTP server for benchmark analysis.
     6  //
     7  // Usage:
     8  //
     9  //	localperf [-addr address] [-storage url] [-base_dir ../appengine]
    10  package main
    11  
    12  import (
    13  	"flag"
    14  	"fmt"
    15  	"log"
    16  	"net/http"
    17  	"os"
    18  
    19  	"golang.org/x/perf/analysis/app"
    20  	"golang.org/x/perf/internal/basedir"
    21  	"golang.org/x/perf/storage"
    22  )
    23  
    24  var (
    25  	addr       = flag.String("addr", "localhost:8080", "serve HTTP on `address`")
    26  	storageURL = flag.String("storage", "https://perfdata.golang.org", "storage server base `url`")
    27  	baseDir    = flag.String("base_dir", basedir.Find("golang.org/x/perf/analysis/appengine"), "base `directory` for templates")
    28  )
    29  
    30  func usage() {
    31  	fmt.Fprintf(os.Stderr, `Usage of localperf:
    32  	localperf [flags]
    33  `)
    34  	flag.PrintDefaults()
    35  	os.Exit(2)
    36  }
    37  
    38  func main() {
    39  	log.SetPrefix("localperf: ")
    40  	flag.Usage = usage
    41  	flag.Parse()
    42  	if flag.NArg() != 0 {
    43  		flag.Usage()
    44  	}
    45  
    46  	if *baseDir == "" {
    47  		log.Print("base_dir is required and could not be automatically found")
    48  		flag.Usage()
    49  	}
    50  
    51  	app := &app.App{
    52  		StorageClient: &storage.Client{BaseURL: *storageURL},
    53  		BaseDir:       *baseDir,
    54  	}
    55  	app.RegisterOnMux(http.DefaultServeMux)
    56  
    57  	log.Printf("Listening on %s", *addr)
    58  
    59  	log.Fatal(http.ListenAndServe(*addr, nil))
    60  }