Guides/Performance Monitor

From J Wiki
Jump to: navigation, search

References

Summary

   load 'jpm'
   start_jpm_ ''
   ... run tests ...
   viewtotal_jpm_ ''     NB. time
   1 viewtotal_jpm_ ''   NB. space

Jpm.png

  • to view details, double-click the function name
  • locale and name should still exist, so don't close locale based forms
  • to open the other Total view, time or space, current has to be closed
  • clicking on headers does the sorting

Keyboard Shortcuts

In order to simplify the Performance Monitor interface, it is possible to assign keyboard shortcuts and replace almost all typing with GUI support.

In user/config/config.ijs put the following

FKEYS=: 0 : 0
...
'f8';'2';'Start Performace Monitor';'start_jpm_ '''' [ require ''jpm'''
'f8ctrl';'1';'View Performace Space';'1 viewtotal_jpm_'''''
'f8shift';'1';'View Performace Time';'0 viewtotal_jpm_'''''

Notes

Before invoking showdetail, you need to make sure that your target verb has gotten and remained in the PM stats tables. (Because of numerous records, some records may be discarded). If you do not see your verb in showtotal, then run 6!:13'' and observe the value for records lost. If it is 1, then try to increase the initial records buffer size by passing a parameter to start_jpm_, e.g. 1e8.

1. The records may be lost if you have a lot of loops/loop count. So try to narrow down your sample in all dimensions. In the end, if you optimize it on a smaller area, it will scale for larger samples. But in the meantime it will take less memory and run faster for your PM tests.

Although opposite to this perspective, one may try to use jpm for a LOOPLESS explicit verb. It may prove to be an inappropriate use of jpm. One may loop alternatively through two verbs a couple of hundred times and then think to use jpm on one more single iteration of the system at that somewhat arbitrary point. But, probably that is not the way jpm is used. A more basic, maybe more conceptual, analysis could be used.

1. before doing start_jpm_, run your test-verb a few times to "warm-up" the system to cache files, swap memory, etc. Then the stats will be more consistent. (Reason: PM registers not only J pure calc time, but also system/etc other time).

1. If you don't see your verb in showtotal it MAY mean that it is dropped. It is LIKELY to be dropped if you have dropped records. But if there are no dropped records, all your explicit verbs SHOULD be in the stats. (See Example 2).

When the main explicit verb CONTAINS no explicit verbs, showdetail may not work. But showtotal could.

Examples

Example 1

test1=: 3 : 0
  A1=. ? 100 100 $ 1000
  empty''                   NB. 'empty' for space (1)
  A2=. 100 100 ?@$ 1000     NB.   to report correctly
  empty''
)

   start_jpm_''
357142
   test1''
   showtotal_jpm_''
 Time (seconds)
+-------+------+--------+--------+-----+----+---+
|name   |locale|all     |here    |here%|cum%|rep|
+-------+------+--------+--------+-----+----+---+
|test1  |base  |0.000653|0.000649| 99.3| 99 |1  |
|[rest] |      |        |0.000004|  0.7|100 |   |
|[total]|      |        |0.000653|100.0|100 |   |
+-------+------+--------+--------+-----+----+---+

As long as it is in total, it MUST be in details

   0 1 showdetail_jpm_'test1'
 Time (seconds)
+--------+--------+---+----------------------+
|all     |here    |rep|test1                 |
+--------+--------+---+----------------------+
|0.000015|0.000015|1  |monad                 |
|0.000413|0.000413|1  |[0] A1=.?100 100$1000 |
|0.000029|0.000026|1  |[1] empty''           |
|0.000171|0.000171|1  |[2] A2=.100 100?@$1000|
|0.000025|0.000023|1  |[3] empty''           |
|0.000653|0.000649|1  |total monad           |
+--------+--------+---+----------------------+
 Space (bytes)
+-------+-------+---+----------------------+
|all    |here   |rep|test1                 |
+-------+-------+---+----------------------+
|    192|    192|1  |monad                 |
|    512|    512|1  |[0] A1=.?100 100$1000 |
|131,520|131,520|1  |[1] empty''           |
|      0|      0|1  |[2] A2=.100 100?@$1000|
| 65,536| 65,472|1  |[3] empty''           |
|197,760|197,696|1  |total monad           |
+-------+-------+---+----------------------+

Example 2

test2=: 3 : 0
  case2A''
  empty''
  case2B''
  empty''
)

case2A=: 3 : 0
  A1=. ? 100 100 $ 1000
  empty''
)

case2B=: 3 : 0
  A2=. 100 100 ?@$ 1000
  empty''
)

   start_jpm_''
357142
   test2''
   showtotal_jpm_''
 Time (seconds)
+-------+------+--------+--------+-----+----+---+
|name   |locale|all     |here    |here%|cum%|rep|
+-------+------+--------+--------+-----+----+---+
|case2A |base  |0.000463|0.000461| 66.5| 66 |1  |
|case2B |base  |0.000192|0.000191| 27.5| 94 |1  |
|[rest] |      |        |0.000042|  6.0|100 |   |
|[total]|      |        |0.000693|100.0|100 |   |
+-------+------+--------+--------+-----+----+---+

Hmm, don't see it. How about dropped records (need to restart):

   start_jpm_''
357142
   test2''
   6!:13''
1 0 357142 24 0 1   NB. nothing dropped, OK.

   0 1 showdetail_jpm_'test2'
 Time (seconds)
+--------+--------+---+------------+
|all     |here    |rep|test2       |
+--------+--------+---+------------+
|0.000011|0.000011|1  |monad       |
|0.000467|0.000020|1  |[0] case2A''|
|0.000006|0.000005|1  |[1] empty'' |
|0.000198|0.000015|1  |[2] case2B''|
|0.000009|0.000007|1  |[3] empty'' |
|0.000689|0.000058|1  |total monad |
+--------+--------+---+------------+
 Space (bytes)
+-------+-----+---+------------+
|all    |here |rep|test2       |
+-------+-----+---+------------+
|    192|  192|1  |monad       |
|133,376|  768|1  |[0] case2A''|
|    128|    0|1  |[1] empty'' |
| 67,008|  256|1  |[2] case2B''|
|    128|    0|1  |[3] empty'' |
|200,832|1,216|1  |total monad |
+-------+-----+---+------------+

(Adapted from JForum April 24-26, 2004 )