All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.squeryl.logging.BarChartRenderer.scala Maven / Gradle / Ivy
package org.squeryl.logging
import xml.Unparsed
import java.io.{FileOutputStream, PrintStream}
import org.squeryl.InternalFieldMapper._
object BarChartRenderer {
class Stat(val title: String, val xAxisLabel: String, val lines: Iterable[StatLine], measureFromLike: StatLine => String) {
def queryLabelsJSArray: String =
lines.map(sl => "'" + sl.statement.definitionOrCallSite + "'").mkString("[",",","]")
def measuresJSArray: String =
lines.map(measureFromLike(_)).mkString("[",",","]")
}
def generateStatSummary(staticHtmlFile: java.io.File, n: Int): Unit = {
val page =
BarChartRenderer.page(
new Stat(
"Top "+n+" statements with longest avg",
"avg time",
StatsSchema.topRankingStatements(n, Measure.AvgExecTime),
sl => sl.avgExecTime.toString),
new Stat(
"Top "+n+" most called statements",
"invocation count",
StatsSchema.topRankingStatements(n, Measure.InvocationCount),
sl => sl.invocationCount.toString),
new Stat(
"Top "+n+" statements incurring most cumulative execution time",
"cumulative execution time",
StatsSchema.topRankingStatements(n, Measure.CumulativeExecutionTime),
sl => sl.cumulativeExecutionTime.toString),
new Stat(
"Top "+n+" statements with highest avg row count",
"avg row count",
StatsSchema.topRankingStatements(n, Measure.AvgResultSetSize),
sl => sl.avgRowCount.toString)
)
val ps = new PrintStream(new FileOutputStream(staticHtmlFile))
ps.print(page)
ps.close()
}
val drawFunc = """
function drawBarGraph(divId, chartTitle, statType, queryClasses, measure) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Z');
data.addColumn('number', statType);
data.addRows(queryClasses.length);
for (var j = 0; j < queryClasses.length; ++j) {
data.setValue(j, 0, queryClasses[j].toString());
data.setValue(j, 1, measure[j]);
}
var v = new google.visualization.BarChart(document.getElementById(divId))
v.draw(data,
{title: chartTitle,
width:600, height:400,
vAxis: {title: "Queries"},
hAxis: {title: statType}
}
);
}
"""
def funcCalls(stats: collection.Seq[Stat]): String = {
val sb = new java.lang.StringBuilder
var i = 0
for(s <- stats) {
i += 1
sb.append("drawBarGraph('chart")
sb.append(i)
sb.append("','")
sb.append(s.title)
sb.append("','")
sb.append(s.xAxisLabel)
sb.append("',")
sb.append(s.queryLabelsJSArray)
sb.append(",")
sb.append(s.measuresJSArray)
sb.append(");\n")
}
sb.toString
}
def page(stats: Stat*) = s"""
Performance profile of Squeryl queries
"""
}