Initializing help system before first use

Profiling and code coverage via the Remote Invocation Protocol


Type: Programming
Rating: 4 (medium-difficult)
Description:
  • Start remote model execution in profiling mode
  • Retrieve and decode profiling information (mprf.mos)
  • Retrieve and decode code overage statistics (mcov.mos)
File(s): mprf.mos, mcov.mos


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

mcov.mos
(!*******************************************************
  * Mosel Example Programs                              *
  * ======================                              *
  *                                                     *
  * file mcov.mos                                       *
  * `````````````                                       *
  * Example for the use of the Mosel language           *
  * (use of the Remote Invocation Protocol)             *
  *                                                     *
  * Implements model code coverage with Mosel           *
  *                                                     *
  * (c) 2016 Fair Isaac Corporation                     *
  *     author: Y. Colombani, 2016                      *
  *******************************************************!)

model mcov

uses 'mmjobs','mmsystem'

parameters
 SRC="qsort.mos"
end-parameters

forward procedure showcov

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

showcov

!*******************************
!* Decode coverage information
!*******************************
procedure showcov
declarations
 tottime:real		! total time
 lines:array(Rlines:range) of integer ! line numbers (in file)
 iters:array(Rlines) of integer ! nb of iterations
 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 'covres' (profiler result for code coverage)
!  mcmd:covres@M
! M: master model (it must have been run with the profiler)

!fcopy("rmt:["+nid+"]mcmd:covres-t@1",""); exit(1)
initialisations from "rmt:["+nid+"]mcmd:covres-t@1"
 tottime
 Rlines lines iters
 Rfiles files
 Rstarts starts
end-initialisations

 f:=-1
 cl:=0
 spc:=" "*7
 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)," ","*"*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),"   ",tl)
 end-do
 fclose(F_INPUT)

end-procedure
end-model

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.