Copyright 2017, OpenCensus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package zpages

import (
	
	
	
	
	
	

	
	
)

var (
	fs                = internal.FS(false)
	templateFunctions = template.FuncMap{
		"count":    countFormatter,
		"ms":       msFormatter,
		"rate":     rateFormatter,
		"datarate": dataRateFormatter,
		"even":     even,
		"traceid":  traceIDFormatter,
	}
	headerTemplate       = parseTemplate("header")
	summaryTableTemplate = parseTemplate("summary")
	statsTemplate        = parseTemplate("rpcz")
	tracesTableTemplate  = parseTemplate("traces")
	footerTemplate       = parseTemplate("footer")
)

func ( string) *template.Template {
	,  := fs.Open("/templates/" +  + ".html")
	if  != nil {
		log.Panicf("%v: %v", , )
	}
	defer .Close()
	,  := ioutil.ReadAll()
	if  != nil {
		log.Panicf("%v: %v", , )
	}
	return template.Must(template.New().Funcs(templateFunctions).Parse(string()))
}

func ( uint64) string {
	if  <= 0 {
		return " "
	}
	var  float64
	var  string

	if  >= 1e18 {
		 = float64() / 1e18
		 = " E "
	} else if  >= 1e15 {
		 = float64() / 1e15
		 = " P "
	} else if  >= 1e12 {
		 = float64() / 1e12
		 = " T "
	} else if  >= 1e9 {
		 = float64() / 1e9
		 = " G "
	} else if  >= 1e6 {
		 = float64() / 1e6
		 = " M "
	}

	if  != 0 {
		return fmt.Sprintf("%1.3f%s", , )
	}
	return fmt.Sprint()
}

func ( time.Duration) string {
	if  == 0 {
		return "0"
	}
	if  < 10*time.Millisecond {
		return fmt.Sprintf("%.3f", float64()*1e-6)
	}
	return strconv.Itoa(int( / time.Millisecond))
}

func ( float64) string {
	return fmt.Sprintf("%.3f", )
}

func ( float64) string {
	return fmt.Sprintf("%.3f", /1e6)
}

func ( traceRow) template.HTML {
	 := .SpanContext
	if  == (trace.SpanContext{}) {
		return ""
	}
	 := "black"
	if .TraceOptions.IsSampled() {
		 = "blue"
	}
	if .ParentSpanID != (trace.SpanID{}) {
		return template.HTML(fmt.Sprintf(`trace_id: <b style="color:%s">%s</b> span_id: %s parent_span_id: %s`, , .TraceID, .SpanID, .ParentSpanID))
	}
	return template.HTML(fmt.Sprintf(`trace_id: <b style="color:%s">%s</b> span_id: %s`, , .TraceID, .SpanID))
}

func ( int) bool {
	return %2 == 0