optimise os tracking
optimise memory tracking add panel_stats_routes_perf_head phrase
This commit is contained in:
parent
e71aba55a7
commit
c403b4a85a
|
@ -57,19 +57,16 @@ func NewMemoryCounter(acc *qgen.Accumulator) (*DefaultMemoryCounter, error) {
|
|||
func (co *DefaultMemoryCounter) Tick() (err error) {
|
||||
var m runtime.MemStats
|
||||
runtime.ReadMemStats(&m)
|
||||
var avgMem, avgStack, avgHeap uint64
|
||||
var rTotMem, rTotCount, rStackMem, rStackCount, rHeapMem, rHeapCount uint64
|
||||
|
||||
co.Lock()
|
||||
|
||||
co.totCount++
|
||||
co.totMem += m.Sys
|
||||
co.stackCount++
|
||||
co.stackMem += m.StackInuse
|
||||
co.heapCount++
|
||||
co.heapMem += m.HeapAlloc
|
||||
|
||||
avgMem = co.totMem / co.totCount
|
||||
avgStack = co.stackMem / co.stackCount
|
||||
avgHeap = co.heapMem / co.heapCount
|
||||
rTotMem = co.totMem
|
||||
rTotCount = co.totCount
|
||||
rStackMem = co.stackMem
|
||||
rStackCount = co.stackCount
|
||||
rHeapMem = co.heapMem
|
||||
rHeapCount = co.heapCount
|
||||
|
||||
co.totMem = 0
|
||||
co.totCount = 0
|
||||
|
@ -80,6 +77,11 @@ func (co *DefaultMemoryCounter) Tick() (err error) {
|
|||
|
||||
co.Unlock()
|
||||
|
||||
var avgMem, avgStack, avgHeap uint64
|
||||
avgMem = (rTotMem + m.Sys) / (rTotCount + 1)
|
||||
avgStack = (rStackMem + m.StackInuse) / (rStackCount + 1)
|
||||
avgHeap = (rHeapMem + m.HeapAlloc) / (rHeapCount + 1)
|
||||
|
||||
c.DebugLogf("Inserting a memchunk with a value of %d - %d - %d", avgMem, avgStack, avgHeap)
|
||||
_, err = co.insert.Exec(avgMem, avgStack, avgHeap)
|
||||
if err != nil {
|
||||
|
|
|
@ -50,7 +50,7 @@ func (co *DefaultOSViewCounter) insertChunk(count int64, os int) error {
|
|||
|
||||
func (co *DefaultOSViewCounter) Bump(id int) {
|
||||
// TODO: Test this check
|
||||
c.DebugDetail("co.buckets[", id, "]: ", co.buckets[id])
|
||||
c.DebugDetail("buckets[", id, "]: ", co.buckets[id])
|
||||
if len(co.buckets) <= id || id < 0 {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -958,7 +958,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
// WIP UA Parser
|
||||
var items []string
|
||||
var buffer []byte
|
||||
var os string
|
||||
var os int
|
||||
for _, it := range StringToBytes(ua) {
|
||||
if (it > 64 && it < 91) || (it > 96 && it < 123) {
|
||||
buffer = append(buffer, it)
|
||||
|
@ -968,15 +968,15 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
// Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append
|
||||
switch(BytesToString(buffer)) {
|
||||
case "Windows":
|
||||
os = "windows"
|
||||
os = 1
|
||||
case "Linux":
|
||||
os = "linux"
|
||||
os = 2
|
||||
case "Mac":
|
||||
os = "mac"
|
||||
os = 3
|
||||
case "iPhone":
|
||||
os = "iphone"
|
||||
os = 5
|
||||
case "Android":
|
||||
os = "android"
|
||||
os = 4
|
||||
case "like","compatible":
|
||||
// Skip these words
|
||||
default:
|
||||
|
@ -994,9 +994,6 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
break
|
||||
}
|
||||
}
|
||||
if os == "" {
|
||||
os = "unknown"
|
||||
}
|
||||
|
||||
// Iterate over this in reverse as the real UA tends to be on the right side
|
||||
for i := len(items) - 1; i >= 0; i-- {
|
||||
|
@ -1019,11 +1016,11 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
// Special handling
|
||||
switch(agent) {
|
||||
case "chrome":
|
||||
if os == "android" {
|
||||
if os == 4 {
|
||||
agent = "androidchrome"
|
||||
}
|
||||
case "safari":
|
||||
if os == "iphone" {
|
||||
if os == 5 {
|
||||
agent = "mobilesafari"
|
||||
}
|
||||
case "trident":
|
||||
|
@ -1047,7 +1044,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
} else {
|
||||
co.AgentViewCounter.Bump(agentMapEnum[agent])
|
||||
}
|
||||
co.OSViewCounter.Bump(osMapEnum[os])
|
||||
//co.OSViewCounter.Bump(osMapEnum[os])
|
||||
co.OSViewCounter.Bump(os)
|
||||
}
|
||||
|
||||
// TODO: Do we want to track missing language headers too? Maybe as it's own type, e.g. "noheader"?
|
||||
|
|
|
@ -984,6 +984,7 @@
|
|||
"panel_stats_post_counts_head":"Post Counts",
|
||||
"panel_stats_referrers_head":"Referrers",
|
||||
"panel_stats_routes_head":"Routes",
|
||||
"panel_stats_routes_perf_head":"Routes Performance",
|
||||
"panel_stats_operating_systems_head":"Operating Systems",
|
||||
"panel_stats_topic_counts_head":"Topic Counts",
|
||||
"panel_stats_requests_head":"Requests",
|
||||
|
|
|
@ -665,7 +665,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
// WIP UA Parser
|
||||
var items []string
|
||||
var buffer []byte
|
||||
var os string
|
||||
var os int
|
||||
for _, it := range StringToBytes(ua) {
|
||||
if (it > 64 && it < 91) || (it > 96 && it < 123) {
|
||||
buffer = append(buffer, it)
|
||||
|
@ -675,15 +675,15 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
// Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append
|
||||
switch(BytesToString(buffer)) {
|
||||
case "Windows":
|
||||
os = "windows"
|
||||
os = {{.AllOSMap.windows}}
|
||||
case "Linux":
|
||||
os = "linux"
|
||||
os = {{.AllOSMap.linux}}
|
||||
case "Mac":
|
||||
os = "mac"
|
||||
os = {{.AllOSMap.mac}}
|
||||
case "iPhone":
|
||||
os = "iphone"
|
||||
os = {{.AllOSMap.iphone}}
|
||||
case "Android":
|
||||
os = "android"
|
||||
os = {{.AllOSMap.android}}
|
||||
case "like","compatible":
|
||||
// Skip these words
|
||||
default:
|
||||
|
@ -701,9 +701,6 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
break
|
||||
}
|
||||
}
|
||||
if os == "" {
|
||||
os = "unknown"
|
||||
}
|
||||
|
||||
// Iterate over this in reverse as the real UA tends to be on the right side
|
||||
for i := len(items) - 1; i >= 0; i-- {
|
||||
|
@ -726,11 +723,11 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
// Special handling
|
||||
switch(agent) {
|
||||
case "chrome":
|
||||
if os == "android" {
|
||||
if os == {{.AllOSMap.android}} {
|
||||
agent = "androidchrome"
|
||||
}
|
||||
case "safari":
|
||||
if os == "iphone" {
|
||||
if os == {{.AllOSMap.iphone}} {
|
||||
agent = "mobilesafari"
|
||||
}
|
||||
case "trident":
|
||||
|
@ -754,7 +751,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
} else {
|
||||
co.AgentViewCounter.Bump(agentMapEnum[agent])
|
||||
}
|
||||
co.OSViewCounter.Bump(osMapEnum[os])
|
||||
//co.OSViewCounter.Bump(osMapEnum[os])
|
||||
co.OSViewCounter.Bump(os)
|
||||
}
|
||||
|
||||
// TODO: Do we want to track missing language headers too? Maybe as it's own type, e.g. "noheader"?
|
||||
|
|
|
@ -827,21 +827,6 @@ func AnalyticsRoutesPerf(w http.ResponseWriter, r *http.Request, user c.User) c.
|
|||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: Adjust for the missing chunks in week and month
|
||||
var avgList []int64
|
||||
var avgItems []c.PanelAnalyticsItemUnit
|
||||
for _, value := range revLabelList {
|
||||
avgList = append(avgList, avgMap[value])
|
||||
cv, cu := c.ConvertPerfUnit(float64(avgMap[value]))
|
||||
avgItems = append(avgItems, c.PanelAnalyticsItemUnit{Time: value, Unit: cu, Count: int64(cv)})
|
||||
}
|
||||
graph := c.PanelTimeGraph{Series: [][]int64{avgList}, Labels: labelList}
|
||||
c.DebugLogf("graph: %+v\n", graph)
|
||||
pi := c.PanelAnalyticsPerf{graph, avgItems, timeRange.Range, timeRange.Unit, "time", typ}
|
||||
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_performance", pi})
|
||||
*/
|
||||
|
||||
var vList [][]int64
|
||||
var legendList []string
|
||||
var i int
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class="colstack_item colstack_head">
|
||||
<div class="rowitem">
|
||||
<h1>{{lang "panel_stats_routes_head"}}</h1>
|
||||
<h1>{{lang "panel_stats_routes_perf_head"}}</h1>
|
||||
{{template "panel_analytics_time_range.html" . }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue