FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Profiling and code coverage via the Remote Invocation Protocol

Description
  • Start remote model execution in profiling mode
  • Retrieve and decode profiling information (mprf.mos)
  • Retrieve and decode code overage statistics (mcov.mos)
Further explanation of this example: 'Mosel Language Reference', Appendix B Remote Invocation Protocol


Source Files





mprf.mos

(!*******************************************************
  * Mosel Example Programs                              *
  * ======================                              *
  *                                                     *
  * file mprf.mos                                       *
  * `````````````                                       *
  * Example for the use of the Mosel language           *
  * (use of the Remote Invocation Ptotocol)             *
  *                                                     *
  * Implements a profiler written in Mosel              *
  *                                                     *
  * (c) 2015 Fair Isaac Corporation                     *
  *     author: Y. Colombani, 2015                      *
  *******************************************************!)

model mprf

uses 'mmjobs','mmsystem'

parameters
 SRC="qsort.mos"
end-parameters

forward procedure showprof(path:string)

declarations
 MO:Mosel
 M:Model
end-declarations

if connect(MO,"")<0 then
 exit(1)
end-if
if compile("G",SRC,"tmp:bimfile")<>0 then
 writeln("Compilation failed")
 exit(1)
end-if

nid:=getid(MO)
load(MO,M,"rmt:[-1]tmp:bimfile")
! switch model to profile mode
setcontrol(M,"runmode","2")
run(M)

waitfor(EVENT_END,-1,WAIT_EXACT)
dropnextevent

showprof("")
!fcopy("rmt:["+nid+"]mcmd:profres-t@1","")

!*******************************
!* Decode profile information
!*******************************
procedure showprof(path:string)
declarations
 tottime:real		! total time
 nbsub:integer		! nb of submodels profiled
 nbnoprf:integer	! nb of submodels not profiled
 lines:array(Rlines:range) of integer ! line numbers (in file)
 iters:array(Rlines) of integer ! nb of iterations
 times:array(Rlines) of real ! time spent on line
 elaps:array(Rlines) of real ! last time the line was executed
 files:array(Rfiles:range) of string ! file names
 starts:array(Rstarts:range) of integer ! line ref where the file starts
 spc,tl:text
end-declarations

! Request 'profres' (profiler result)
!  mcmd:profres@M[ path]
! M: master model (it must have been run with the profiler)
! path: a submodel e.g. 1.3 is the 3d submodel of the 1st submodel
initialisations from "rmt:["+nid+"]mcmd:profres-t@1 "+path
 tottime
 nbsub
 nbnoprf
 Rlines lines iters times elaps
 Rfiles files
 Rstarts starts
end-initialisations

 f:=-1
 cl:=0
 spc:=" "*14
 forall(l in Rlines) do
  if l=starts(f+1) then
   if f>=0 then fclose(F_INPUT); end-if
   f+=1
   writeln
   writeln("*"*30," File:",files(f),
   		if(path.size>0," submodel:"+path," master model")," ","*"*30)
   writeln
   fopen(files(f),F_INPUT)
   cl:=0
  end-if
  dum:=readtextline(tl)
  cl+=1
  while(cl<lines(l)) do
    write(spc,tl)
    dum:=readtextline(tl)
    cl+=1
  end-do
  write(textfmt(iters(l),4)," ",textfmt(times(l),5,2),"   ",tl)
 end-do
 fclose(F_INPUT)

 ! Let's process all the submodels
 if path.size>0 then path:=path+"."; end-if
 forall(i in 1..nbsub)
  showprof(path+i)
end-procedure
end-model

Back to examples browserPrevious exampleNext example