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) {
|
func (co *DefaultMemoryCounter) Tick() (err error) {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
||||||
var avgMem, avgStack, avgHeap uint64
|
var rTotMem, rTotCount, rStackMem, rStackCount, rHeapMem, rHeapCount uint64
|
||||||
|
|
||||||
co.Lock()
|
co.Lock()
|
||||||
|
|
||||||
co.totCount++
|
rTotMem = co.totMem
|
||||||
co.totMem += m.Sys
|
rTotCount = co.totCount
|
||||||
co.stackCount++
|
rStackMem = co.stackMem
|
||||||
co.stackMem += m.StackInuse
|
rStackCount = co.stackCount
|
||||||
co.heapCount++
|
rHeapMem = co.heapMem
|
||||||
co.heapMem += m.HeapAlloc
|
rHeapCount = co.heapCount
|
||||||
|
|
||||||
avgMem = co.totMem / co.totCount
|
|
||||||
avgStack = co.stackMem / co.stackCount
|
|
||||||
avgHeap = co.heapMem / co.heapCount
|
|
||||||
|
|
||||||
co.totMem = 0
|
co.totMem = 0
|
||||||
co.totCount = 0
|
co.totCount = 0
|
||||||
|
@ -80,6 +77,11 @@ func (co *DefaultMemoryCounter) Tick() (err error) {
|
||||||
|
|
||||||
co.Unlock()
|
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)
|
c.DebugLogf("Inserting a memchunk with a value of %d - %d - %d", avgMem, avgStack, avgHeap)
|
||||||
_, err = co.insert.Exec(avgMem, avgStack, avgHeap)
|
_, err = co.insert.Exec(avgMem, avgStack, avgHeap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (co *DefaultOSViewCounter) insertChunk(count int64, os int) error {
|
||||||
|
|
||||||
func (co *DefaultOSViewCounter) Bump(id int) {
|
func (co *DefaultOSViewCounter) Bump(id int) {
|
||||||
// TODO: Test this check
|
// 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 {
|
if len(co.buckets) <= id || id < 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -958,7 +958,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
// WIP UA Parser
|
// WIP UA Parser
|
||||||
var items []string
|
var items []string
|
||||||
var buffer []byte
|
var buffer []byte
|
||||||
var os string
|
var os int
|
||||||
for _, it := range StringToBytes(ua) {
|
for _, it := range StringToBytes(ua) {
|
||||||
if (it > 64 && it < 91) || (it > 96 && it < 123) {
|
if (it > 64 && it < 91) || (it > 96 && it < 123) {
|
||||||
buffer = append(buffer, it)
|
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
|
// 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)) {
|
switch(BytesToString(buffer)) {
|
||||||
case "Windows":
|
case "Windows":
|
||||||
os = "windows"
|
os = 1
|
||||||
case "Linux":
|
case "Linux":
|
||||||
os = "linux"
|
os = 2
|
||||||
case "Mac":
|
case "Mac":
|
||||||
os = "mac"
|
os = 3
|
||||||
case "iPhone":
|
case "iPhone":
|
||||||
os = "iphone"
|
os = 5
|
||||||
case "Android":
|
case "Android":
|
||||||
os = "android"
|
os = 4
|
||||||
case "like","compatible":
|
case "like","compatible":
|
||||||
// Skip these words
|
// Skip these words
|
||||||
default:
|
default:
|
||||||
|
@ -994,9 +994,6 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if os == "" {
|
|
||||||
os = "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over this in reverse as the real UA tends to be on the right side
|
// Iterate over this in reverse as the real UA tends to be on the right side
|
||||||
for i := len(items) - 1; i >= 0; i-- {
|
for i := len(items) - 1; i >= 0; i-- {
|
||||||
|
@ -1019,11 +1016,11 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
// Special handling
|
// Special handling
|
||||||
switch(agent) {
|
switch(agent) {
|
||||||
case "chrome":
|
case "chrome":
|
||||||
if os == "android" {
|
if os == 4 {
|
||||||
agent = "androidchrome"
|
agent = "androidchrome"
|
||||||
}
|
}
|
||||||
case "safari":
|
case "safari":
|
||||||
if os == "iphone" {
|
if os == 5 {
|
||||||
agent = "mobilesafari"
|
agent = "mobilesafari"
|
||||||
}
|
}
|
||||||
case "trident":
|
case "trident":
|
||||||
|
@ -1047,7 +1044,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
co.AgentViewCounter.Bump(agentMapEnum[agent])
|
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"?
|
// 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_post_counts_head":"Post Counts",
|
||||||
"panel_stats_referrers_head":"Referrers",
|
"panel_stats_referrers_head":"Referrers",
|
||||||
"panel_stats_routes_head":"Routes",
|
"panel_stats_routes_head":"Routes",
|
||||||
|
"panel_stats_routes_perf_head":"Routes Performance",
|
||||||
"panel_stats_operating_systems_head":"Operating Systems",
|
"panel_stats_operating_systems_head":"Operating Systems",
|
||||||
"panel_stats_topic_counts_head":"Topic Counts",
|
"panel_stats_topic_counts_head":"Topic Counts",
|
||||||
"panel_stats_requests_head":"Requests",
|
"panel_stats_requests_head":"Requests",
|
||||||
|
|
|
@ -665,7 +665,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
// WIP UA Parser
|
// WIP UA Parser
|
||||||
var items []string
|
var items []string
|
||||||
var buffer []byte
|
var buffer []byte
|
||||||
var os string
|
var os int
|
||||||
for _, it := range StringToBytes(ua) {
|
for _, it := range StringToBytes(ua) {
|
||||||
if (it > 64 && it < 91) || (it > 96 && it < 123) {
|
if (it > 64 && it < 91) || (it > 96 && it < 123) {
|
||||||
buffer = append(buffer, it)
|
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
|
// 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)) {
|
switch(BytesToString(buffer)) {
|
||||||
case "Windows":
|
case "Windows":
|
||||||
os = "windows"
|
os = {{.AllOSMap.windows}}
|
||||||
case "Linux":
|
case "Linux":
|
||||||
os = "linux"
|
os = {{.AllOSMap.linux}}
|
||||||
case "Mac":
|
case "Mac":
|
||||||
os = "mac"
|
os = {{.AllOSMap.mac}}
|
||||||
case "iPhone":
|
case "iPhone":
|
||||||
os = "iphone"
|
os = {{.AllOSMap.iphone}}
|
||||||
case "Android":
|
case "Android":
|
||||||
os = "android"
|
os = {{.AllOSMap.android}}
|
||||||
case "like","compatible":
|
case "like","compatible":
|
||||||
// Skip these words
|
// Skip these words
|
||||||
default:
|
default:
|
||||||
|
@ -701,9 +701,6 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if os == "" {
|
|
||||||
os = "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over this in reverse as the real UA tends to be on the right side
|
// Iterate over this in reverse as the real UA tends to be on the right side
|
||||||
for i := len(items) - 1; i >= 0; i-- {
|
for i := len(items) - 1; i >= 0; i-- {
|
||||||
|
@ -726,11 +723,11 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
// Special handling
|
// Special handling
|
||||||
switch(agent) {
|
switch(agent) {
|
||||||
case "chrome":
|
case "chrome":
|
||||||
if os == "android" {
|
if os == {{.AllOSMap.android}} {
|
||||||
agent = "androidchrome"
|
agent = "androidchrome"
|
||||||
}
|
}
|
||||||
case "safari":
|
case "safari":
|
||||||
if os == "iphone" {
|
if os == {{.AllOSMap.iphone}} {
|
||||||
agent = "mobilesafari"
|
agent = "mobilesafari"
|
||||||
}
|
}
|
||||||
case "trident":
|
case "trident":
|
||||||
|
@ -754,7 +751,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
co.AgentViewCounter.Bump(agentMapEnum[agent])
|
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"?
|
// 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
|
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 vList [][]int64
|
||||||
var legendList []string
|
var legendList []string
|
||||||
var i int
|
var i int
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="colstack_item colstack_head">
|
<div class="colstack_item colstack_head">
|
||||||
<div class="rowitem">
|
<div class="rowitem">
|
||||||
<h1>{{lang "panel_stats_routes_head"}}</h1>
|
<h1>{{lang "panel_stats_routes_perf_head"}}</h1>
|
||||||
{{template "panel_analytics_time_range.html" . }}
|
{{template "panel_analytics_time_range.html" . }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue