"Change your thoughts and you change your world."
- Norman Vincent Peale





Working with Milliseconds in Coldfusion

Now that the development and SIT phases of my current project are coming to an end, I've been focusing on preparation for Performance and Load testing. The application that I've been working on was written in Java and runs completely behind the scenes, so using Mercury Loadrunner or some other load testing tool for metrics gathering was out of the question.

The approach that I decided to take was to write a tool in CF that would parse the log files produced by the application (via log4j), aggregate the runtimes for various classes and method and then produce a graph to show average runtimes for various components. Most of the components that I will be measuring execute in an order of milliseconds so immediately I knew that I would have to tap into Java for working with time on that scale. The log files that I am working with output timestamps that look like this, 11/30/2007 13:01:59,123 (MM/dd/yyyy hh:mm:ss,zzz where z is milliseconds).

In the course of building my metrics tool, I wrote the following UDF to aid in calculating time differences in milliseconds. ** variables.runDate is set on instantiation of the object that this udf sits in.

<cffunction name="getMillis" access="public" returnType="numeric" output="false">
      <cfargument name="ts" type="string" required="true">
      <cfset var local = structNew()>
      <cfset local.xms = listLast(arguments.ts,",")>
      <cfset local.tparts = listToArray(listFirst(arguments.ts,","),":")>
      <cfset local.ntime = CreateDateTime(year(variables.runDate), month(variables.runDate), day(variables.runDate), local.tparts[1], local.tparts[2], local.tparts[3])>
      
      <cfset local.ms = local.ntime.getTime() + javaCast("long",local.xms)>
      
      <cfreturn local.ms>
   </cffunction>


Comments

There are no comments for this entry.

Add Comment