Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: experimental/webtry/webtry.go

Issue 312373002: Add metrics reporting to SkFiddle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix linking Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 package main 1 package main
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "crypto/md5" 5 "crypto/md5"
6 "database/sql" 6 "database/sql"
7 "encoding/base64" 7 "encoding/base64"
8 "encoding/binary" 8 "encoding/binary"
9 "encoding/json" 9 "encoding/json"
10 "flag" 10 "flag"
11 "fmt" 11 "fmt"
12 htemplate "html/template" 12 htemplate "html/template"
13 "image" 13 "image"
14 _ "image/gif" 14 _ "image/gif"
15 _ "image/jpeg" 15 _ "image/jpeg"
16 "image/png" 16 "image/png"
17 "io/ioutil" 17 "io/ioutil"
18 "log" 18 "log"
19 "math/rand" 19 "math/rand"
20 "net"
20 "net/http" 21 "net/http"
21 "os" 22 "os"
22 "os/exec" 23 "os/exec"
23 "path/filepath" 24 "path/filepath"
24 "regexp" 25 "regexp"
25 "strings" 26 "strings"
26 "text/template" 27 "text/template"
27 "time" 28 "time"
28 ) 29 )
29 30
30 import ( 31 import (
31 "github.com/fiorix/go-web/autogzip" 32 "github.com/fiorix/go-web/autogzip"
32 _ "github.com/go-sql-driver/mysql" 33 _ "github.com/go-sql-driver/mysql"
33 _ "github.com/mattn/go-sqlite3" 34 _ "github.com/mattn/go-sqlite3"
35 "github.com/rcrowley/go-metrics"
34 ) 36 )
35 37
36 const ( 38 const (
37 RESULT_COMPILE = `../../experimental/webtry/safec++ -DSK_GAMMA_SRGB -DSK _GAMMA_APPLY_TO_A8 -DSK_SCALAR_TO_FLOAT_EXCLUDED -DSK_ALLOW_STATIC_GLOBAL_INITIA LIZERS=1 -DSK_SUPPORT_GPU=0 -DSK_SUPPORT_OPENCL=0 -DSK_FORCE_DISTANCEFIELD_FONTS =0 -DSK_SCALAR_IS_FLOAT -DSK_CAN_USE_FLOAT -DSK_SAMPLES_FOR_X -DSK_BUILD_FOR_UNI X -DSK_USE_POSIX_THREADS -DSK_SYSTEM_ZLIB=1 -DSK_DEBUG -DSK_DEVELOPER=1 -I../../ src/core -I../../src/images -I../../tools/flags -I../../include/config -I../../i nclude/core -I../../include/pathops -I../../include/pipe -I../../include/effects -I../../include/ports -I../../src/sfnt -I../../include/utils -I../../src/utils -I../../include/images -g -fno-exceptions -fstrict-aliasing -Wall -Wextra -Winit -self -Wpointer-arith -Wno-unused-parameter -m64 -fno-rtti -Wnon-virtual-dtor -c ../../../cache/%s.cpp -o ../../../cache/%s.o` 39 RESULT_COMPILE = `../../experimental/webtry/safec++ -DSK_GAMMA_SRGB -DSK _GAMMA_APPLY_TO_A8 -DSK_SCALAR_TO_FLOAT_EXCLUDED -DSK_ALLOW_STATIC_GLOBAL_INITIA LIZERS=1 -DSK_SUPPORT_GPU=0 -DSK_SUPPORT_OPENCL=0 -DSK_FORCE_DISTANCEFIELD_FONTS =0 -DSK_SCALAR_IS_FLOAT -DSK_CAN_USE_FLOAT -DSK_SAMPLES_FOR_X -DSK_BUILD_FOR_UNI X -DSK_USE_POSIX_THREADS -DSK_SYSTEM_ZLIB=1 -DSK_DEBUG -DSK_DEVELOPER=1 -I../../ src/core -I../../src/images -I../../tools/flags -I../../include/config -I../../i nclude/core -I../../include/pathops -I../../include/pipe -I../../include/effects -I../../include/ports -I../../src/sfnt -I../../include/utils -I../../src/utils -I../../include/images -g -fno-exceptions -fstrict-aliasing -Wall -Wextra -Winit -self -Wpointer-arith -Wno-unused-parameter -m64 -fno-rtti -Wnon-virtual-dtor -c ../../../cache/%s.cpp -o ../../../cache/%s.o`
38 » LINK = `../../experimental/webtry/safec++ -m64 -lstdc++ -lm -o ../../../inout/%s -Wl,--start-group ../../../cache/%s.o obj/experimental/webtry /webtry.main.o obj/gyp/libflags.a libskia_images.a libskia_core.a libskia_effect s.a obj/gyp/libjpeg.a obj/gyp/libetc1.a obj/gyp/libwebp_dec.a obj/gyp/libwebp_de mux.a obj/gyp/libwebp_dsp.a obj/gyp/libwebp_enc.a obj/gyp/libwebp_utils.a libski a_utils.a libskia_opts.a libskia_opts_ssse3.a libskia_ports.a libskia_sfnt.a -Wl ,--end-group -lpng -lz -lgif -lpthread -lfontconfig -ldl -lfreetype` 40 » LINK = `../../experimental/webtry/safec++ -m64 -lstdc++ -lm -o ../../../inout/%s -Wl,--start-group ../../../cache/%s.o obj/experimental/webtry /webtry.main.o obj/gyp/libflags.a libskia_images.a libskia_core.a libskia_effect s.a obj/gyp/libjpeg.a obj/gyp/libetc1.a obj/gyp/libSkKTX.a obj/gyp/libwebp_dec.a obj/gyp/libwebp_demux.a obj/gyp/libwebp_dsp.a obj/gyp/libwebp_enc.a obj/gyp/lib webp_utils.a libskia_utils.a libskia_opts.a libskia_opts_ssse3.a libskia_ports.a libskia_sfnt.a -Wl,--end-group -lpng -lz -lgif -lpthread -lfontconfig -ldl -lfr eetype`
39 41
40 DEFAULT_SAMPLE = `void draw(SkCanvas* canvas) { 42 DEFAULT_SAMPLE = `void draw(SkCanvas* canvas) {
41 SkPaint p; 43 SkPaint p;
42 p.setColor(SK_ColorRED); 44 p.setColor(SK_ColorRED);
43 p.setAntiAlias(true); 45 p.setAntiAlias(true);
44 p.setStyle(SkPaint::kStroke_Style); 46 p.setStyle(SkPaint::kStroke_Style);
45 p.setStrokeWidth(10); 47 p.setStrokeWidth(10);
46 48
47 canvas->drawLine(20, 20, 100, 100, p); 49 canvas->drawLine(20, 20, 100, 100, p);
48 }` 50 }`
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 "butterfly", "bush", "dew", "dust", "field", "fire", "flower", " firefly", 107 "butterfly", "bush", "dew", "dust", "field", "fire", "flower", " firefly",
106 "feather", "grass", "haze", "mountain", "night", "pond", "darkne ss", 108 "feather", "grass", "haze", "mountain", "night", "pond", "darkne ss",
107 "snowflake", "silence", "sound", "sky", "shape", "surf", "thunde r", 109 "snowflake", "silence", "sound", "sky", "shape", "surf", "thunde r",
108 "violet", "water", "wildflower", "wave", "water", "resonance", " sun", 110 "violet", "water", "wildflower", "wave", "water", "resonance", " sun",
109 "wood", "dream", "cherry", "tree", "fog", "frost", "voice", "pap er", 111 "wood", "dream", "cherry", "tree", "fog", "frost", "voice", "pap er",
110 "frog", "smoke", "star", 112 "frog", "smoke", "star",
111 } 113 }
112 114
113 gitHash = "" 115 gitHash = ""
114 gitInfo = "" 116 gitInfo = ""
117
118 requestsCounter = metrics.NewRegisteredCounter("requests", metrics.Defau ltRegistry)
115 ) 119 )
116 120
117 // flags 121 // flags
118 var ( 122 var (
119 useChroot = flag.Bool("use_chroot", false, "Run the compiled code in the schroot jail.") 123 useChroot = flag.Bool("use_chroot", false, "Run the compiled code in the schroot jail.")
120 port = flag.String("port", ":8000", "HTTP service address (e.g., ': 8000')") 124 port = flag.String("port", ":8000", "HTTP service address (e.g., ': 8000')")
121 ) 125 )
122 126
123 // lineNumbers adds #line numbering to the user's code. 127 // lineNumbers adds #line numbering to the user's code.
124 func LineNumbers(c string) string { 128 func LineNumbers(c string) string {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // Ping the database to keep the connection fresh. 277 // Ping the database to keep the connection fresh.
274 go func() { 278 go func() {
275 c := time.Tick(1 * time.Minute) 279 c := time.Tick(1 * time.Minute)
276 for _ = range c { 280 for _ = range c {
277 if err := db.Ping(); err != nil { 281 if err := db.Ping(); err != nil {
278 log.Printf("ERROR: Database failed to respond: % q\n", err) 282 log.Printf("ERROR: Database failed to respond: % q\n", err)
279 } 283 }
280 } 284 }
281 }() 285 }()
282 286
287 metrics.RegisterRuntimeMemStats(metrics.DefaultRegistry)
288 go metrics.CaptureRuntimeMemStats(metrics.DefaultRegistry, 1*time.Minute )
289
290 // Start reporting metrics.
291 // TODO(jcgregorio) We need a centrialized config server for storing thi ngs
mtklein 2014/06/06 02:50:50 Is there any sort of public GNS/BNS/Chubby in GCE
jcgregorio 2014/06/06 12:50:45 Turns out we can fetch files from Git via Gitiles,
292 // like the IP address of the Graphite monitor.
293 addr, _ := net.ResolveTCPAddr("tcp", "10.240.159.195:2003")
294 go metrics.Graphite(metrics.DefaultRegistry, 1*time.Minute, "webtry", ad dr)
295
283 writeOutAllSourceImages() 296 writeOutAllSourceImages()
284 } 297 }
285 298
286 func writeOutAllSourceImages() { 299 func writeOutAllSourceImages() {
287 // Pull all the source images from the db and write them out to inout. 300 // Pull all the source images from the db and write them out to inout.
288 rows, err := db.Query("SELECT id, image, create_ts FROM source_images OR DER BY create_ts DESC") 301 rows, err := db.Query("SELECT id, image, create_ts FROM source_images OR DER BY create_ts DESC")
289 302
290 if err != nil { 303 if err != nil {
291 log.Printf("ERROR: Failed to open connection to SQL server: %q\n ", err) 304 log.Printf("ERROR: Failed to open connection to SQL server: %q\n ", err)
292 panic(err) 305 panic(err)
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 739
727 func cleanCompileOutput(s, hash string) string { 740 func cleanCompileOutput(s, hash string) string {
728 old := "../../../cache/" + hash + ".cpp:" 741 old := "../../../cache/" + hash + ".cpp:"
729 log.Printf("INFO: replacing %q\n", old) 742 log.Printf("INFO: replacing %q\n", old)
730 return strings.Replace(s, old, "usercode.cpp:", -1) 743 return strings.Replace(s, old, "usercode.cpp:", -1)
731 } 744 }
732 745
733 // mainHandler handles the GET and POST of the main page. 746 // mainHandler handles the GET and POST of the main page.
734 func mainHandler(w http.ResponseWriter, r *http.Request) { 747 func mainHandler(w http.ResponseWriter, r *http.Request) {
735 log.Printf("Main Handler: %q\n", r.URL.Path) 748 log.Printf("Main Handler: %q\n", r.URL.Path)
749 requestsCounter.Inc(1)
736 if r.Method == "GET" { 750 if r.Method == "GET" {
737 code := DEFAULT_SAMPLE 751 code := DEFAULT_SAMPLE
738 source := 0 752 source := 0
739 match := directLink.FindStringSubmatch(r.URL.Path) 753 match := directLink.FindStringSubmatch(r.URL.Path)
740 var hash string 754 var hash string
741 if len(match) == 2 && r.URL.Path != "/" { 755 if len(match) == 2 && r.URL.Path != "/" {
742 hash = match[1] 756 hash = match[1]
743 if db == nil { 757 if db == nil {
744 http.NotFound(w, r) 758 http.NotFound(w, r)
745 return 759 return
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) 863 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler))
850 864
851 // Resources are served directly 865 // Resources are served directly
852 // TODO add support for caching/etags/gzip 866 // TODO add support for caching/etags/gzip
853 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) 867 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./"))))
854 868
855 // TODO Break out /c/ as it's own handler. 869 // TODO Break out /c/ as it's own handler.
856 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) 870 http.HandleFunc("/", autogzip.HandleFunc(mainHandler))
857 log.Fatal(http.ListenAndServe(*port, nil)) 871 log.Fatal(http.ListenAndServe(*port, nil))
858 } 872 }
OLDNEW
« experimental/webtry/templates/template.cpp ('K') | « experimental/webtry/templates/template.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698