Commit 87632589 authored by Kunshan Wang's avatar Kunshan Wang

run-time statistics

parent 7cdb32c6
......@@ -23,8 +23,12 @@ import uvm.staticanalysis.StaticAnalyzer
import uvm.utils.IDFactory
import uvm.utils.WithUtils.tryWithResource
import uvm.refimpl.bootimg.PrimordialInfo
import com.typesafe.scalalogging.Logger
import org.slf4j.LoggerFactory
object MicroVM {
val logger = Logger(LoggerFactory.getLogger(getClass.getName))
val DEFAULT_SOS_SIZE: Word = 2L * 1024L * 1024L; // 2MiB
val DEFAULT_LOS_SIZE: Word = 2L * 1024L * 1024L; // 2MiB
val DEFAULT_GLOBAL_SIZE: Word = 1L * 1024L * 1024L; // 1MiB
......@@ -57,6 +61,8 @@ object MicroVM {
class MicroVM private (val vmConf: VMConf, val appArgs: Option[Seq[String]]) extends IRBuilderListener {
// implicitly injected resources
private implicit val microVM = this
val stats = new VMStats()
val globalBundle = new GlobalBundle()
val constantPool = new ConstantPool()
......@@ -225,6 +231,9 @@ class MicroVM private (val vmConf: VMConf, val appArgs: Option[Seq[String]]) ext
*/
def execute(): Unit = {
threadStackManager.execute()
MicroVM.logger.info("Execution statistics:")
MicroVM.logger.info(stats.getStatesString())
}
// Automatically load the boot image if provided
......
......@@ -19,7 +19,9 @@ trait CommInstExecutor extends InterpreterActions with ObjectPinner with IRBuild
override def interpretCurrentCommonInstruction(): Unit = {
assert(curInst.isInstanceOf[InstCommInst])
val InstCommInst(ci, flagList, typeList, sigList, argList, excClause, keepalives) = curInst
microVM.stats.onInstExec("InstCommInst/" + ci.name.get)
if (ci.name.get.startsWith("@uvm.irbuilder")) {
return interpretCurrentIRBuilderCommonInstruction()
}
......
......@@ -20,6 +20,8 @@ trait InstructionExecutor extends InterpreterActions with CommInstExecutor {
/** Interpret the current instruction. */
protected def interpretCurrentInstruction(): Unit = try {
logger.debug(ctx + "Executing instruction...")
microVM.stats.onInstExec(curInst.getClass.getSimpleName)
curInst match {
case i @ InstBinOp(op, opndTy, op1, op2, excClause) => {
......@@ -240,6 +242,10 @@ trait InstructionExecutor extends InterpreterActions with CommInstExecutor {
}
val argBoxes = argList.map(boxOf)
if (i.excClause.isDefined) {
microVM.stats.peiCalled += 1
}
val shouldIncrementPC = curStack.callMu(calleeFunc, argBoxes)
if (shouldIncrementPC) {
......@@ -361,6 +367,7 @@ trait InstructionExecutor extends InterpreterActions with CommInstExecutor {
}
case i @ InstAlloca(allocTy, excClause) => {
microVM.stats.allocaExecuted += 1
handleOutOfMemory(excClause) {
val addr = mutator.allocaScalar(curStack.stackMemory, allocTy)
results(0).asIRef = (0L, addr)
......@@ -369,6 +376,7 @@ trait InstructionExecutor extends InterpreterActions with CommInstExecutor {
}
case i @ InstAllocaHybrid(allocTy, lenTy, length, excClause) => {
microVM.stats.allocaExecuted += 1
handleOutOfMemory(excClause) {
val len = length.getUInt(lenTy.length).longValue
val addr = mutator.allocaHybrid(curStack.stackMemory, allocTy, len)
......
......@@ -313,6 +313,8 @@ trait InterpreterActions extends InterpreterThreadState {
val f = s.top
val (newFrame, dc) = unwindUntilCatchable(f)
s.unwindTo(newFrame)
microVM.stats.exceptionsThrown += 1
branchTo(dc, Some(exc))
}
......
package uvm.refimpl
import scala.collection.mutable.HashMap
import uvm.ssavariables.Instruction
class VMStats {
var exceptionsThrown: Long = 0L
var peiCalled: Long = 0L
var allocaExecuted: Long = 0L
val instExecCount: HashMap[String, Long] = new HashMap()
def onInstExec(i: String): Unit = {
val oldCount = instExecCount.getOrElse(i, 0L)
val newCount = oldCount + 1
instExecCount.update(i, newCount)
}
def getStatesString(): String = {
val sb = new StringBuilder()
sb ++= "Exceptions thrown: %d\n".format(exceptionsThrown)
sb ++= "PEI called: %d\n".format(peiCalled)
sb ++= "ALLOCA and ALLOCAHYBRID executed: %d\n".format(peiCalled)
sb ++= "Instructions executed:\n"
for ((i, c) <- instExecCount.toSeq.sortBy(_._2).reverse) {
sb ++= " %s: %d\n".format(i, c)
}
sb.toString()
}
def printState(): Unit = {
print(getStatesString())
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment