alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (DiagramStats.scala)

This example Scala source code file (DiagramStats.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Scala source code examples by using tags.

All credit for the original source code belongs to scala-lang.org; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Scala tags/keywords

broken, compiler, diagramstats, fixed, int, long, nsc, settings, string, timetracker, unit

The DiagramStats.scala Scala example source code

/**
 * @author Vlad Ureche
 */
package scala.tools.nsc.doc
package html.page.diagram

object DiagramStats {

  class TimeTracker(title: String) {
    var totalTime: Long = 0l
    var maxTime: Long = 0l
    var instances: Int = 0

    def addTime(ms: Long) = {
      if (maxTime < ms)
        maxTime = ms
      totalTime += ms
      instances += 1
    }

    def printStats(print: String => Unit) = {
      if (instances == 0)
        print(title + ": no stats gathered")
      else {
        print("  " + title)
        print("  " + "=" * title.length)
        print("    count:        " + instances + " items")
        print("    total time:   " + totalTime + " ms")
        print("    average time: " + (totalTime/instances) + " ms")
        print("    maximum time: " + maxTime + " ms")
        print("")
      }
    }
  }

  private[this] val filterTrack = new TimeTracker("diagrams model filtering")
  private[this] val modelTrack = new TimeTracker("diagrams model generation")
  private[this] val dotGenTrack = new TimeTracker("dot diagram generation")
  private[this] val dotRunTrack = new TimeTracker("dot process runnning")
  private[this] val svgTrack = new TimeTracker("svg processing")
  private[this] var brokenImages = 0
  private[this] var fixedImages = 0

  def printStats(settings: Settings) = {
    if (settings.docDiagramsDebug) {
      settings.printMsg("\nDiagram generation running time breakdown:\n")
      filterTrack.printStats(settings.printMsg)
      modelTrack.printStats(settings.printMsg)
      dotGenTrack.printStats(settings.printMsg)
      dotRunTrack.printStats(settings.printMsg)
      svgTrack.printStats(settings.printMsg)
      println("  Broken images: " + brokenImages)
      println("  Fixed images: " + fixedImages)
      println("")
    }
  }

  def addFilterTime(ms: Long) = filterTrack.addTime(ms)
  def addModelTime(ms: Long) = modelTrack.addTime(ms)
  def addDotGenerationTime(ms: Long) = dotGenTrack.addTime(ms)
  def addDotRunningTime(ms: Long) = dotRunTrack.addTime(ms)
  def addSvgTime(ms: Long) = svgTrack.addTime(ms)

  def addBrokenImage(): Unit = brokenImages += 1
  def addFixedImage(): Unit = fixedImages += 1
}

Other Scala source code examples

Here is a short list of links related to this Scala DiagramStats.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.