* * *

Author Topic: Visualization of Pascal program dependencies  (Read 4615 times)

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Visualization of Pascal program dependencies
« on: September 14, 2016, 03:23:05 am »
Good day All!
A small program to build a dependency tree.
http://svn.shamangrad.net/zcad/trunk/other/pudgb/
Uses fcl-passrc to parse sources.
Import lpi, scan, and save. Result like this
Code: [Select]
DiGraph Classes {
 pudgb -> mainform
 mainform -> uoptions
 mainform -> uscaner
 mainform -> uscanresult
 mainform -> uwriter
 mainform -> ulpiimporter
 uscaner -> uoptions
 uscaner -> uscanresult
 uscaner -> ufileutils
 uwriter -> uoptions
 uwriter -> uscanresult
 ulpiimporter -> uoptions
 ulpiimporter -> ufileutils
}
can be visualized in GraphViz (or converted to yEd)
Мore pictures:
(http://i83.fastpic.ru/thumb/2016/0913/14/3663f49f884e966f37173218b4645b14.jpeg)
(http://i85.fastpic.ru/thumb/2016/0913/d1/075ae3680268bd80c6b1ff12897004d1.jpeg)
(http://i78.fastpic.ru/thumb/2016/0913/53/92c0330153fb6e6ff7f41c65cc87bf53.jpeg)
(http://i84.fastpic.ru/thumb/2016/0913/ad/8e7879e48cca82948dcd0b3eefbbeaad.jpeg)
(http://i84.fastpic.ru/thumb/2016/0913/4c/52a49a89f51968f465c2f774694a484c.jpeg)
(http://i84.fastpic.ru/thumb/2016/0913/0b/8552429f9c353318883983438755c80b.jpeg)
(http://i84.fastpic.ru/thumb/2016/0913/99/_fb340d6c60d83397667bedf9bd8b1f99.jpeg)

Leledumbo

  • Hero Member
  • *****
  • Posts: 7544
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Visualization of Pascal program dependencies
« Reply #1 on: September 14, 2016, 05:37:57 am »

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #2 on: September 14, 2016, 06:13:25 am »
Yes it is the same. But I use the parser from the fpc structure. Also maybe try the data types graph

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5317
Re: Visualization of Pascal program dependencies
« Reply #3 on: September 14, 2016, 10:45:57 am »
I've played a bit with it and have a few problems.

The first (not supporting /* in -Fu directories like FPC does) is easily worked around, but the second sees to be that the -Fi for includes only seems to work for the first module not for later ones?

For it to really be useful it should model both interface and implementation dependencies (dashes and dotted lines?) though.

It is an interesting start though, and it is great that one can play with it themselves.

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #4 on: September 14, 2016, 04:08:33 pm »
>> but the second sees to be that the -Fi for includes only seems to work for the first module not for later ones?
Should work for all. But there is no support for Lazarus macros.
In my opinion while the big problem is errors on the right code in fcl-passrc

I will add settings. I think something like:
-Include to graph mask
-Exclude from graph mask
-Include not fonded units to graph
-Line type for interface uses edges
-Line type for implementation uses edges
-Colorizing nodes from unit folder
-Your wishes))

Also will be useful to find all loops in graph

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5317
Re: Visualization of Pascal program dependencies
« Reply #5 on: September 14, 2016, 06:02:30 pm »
Not found units and other data to a log file?

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #6 on: September 14, 2016, 06:18:09 pm »
yes.
-Informative log

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #7 on: September 15, 2016, 10:43:26 pm »
Added simple settings. There may be difficulties with the building, the program now depends on non-standard components ( http://svn.shamangrad.net/zcad/trunk/cad_source/components/ ). But the interface is very simple

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #8 on: September 22, 2016, 07:26:35 pm »
Added finding loops in the program uses structure.
An example of analyzing a program consisting of more than 200 units (https://sourceforge.net/projects/zcad). Found 4 bottlenecks forming loops:
Code: [Select]
DiGraph Classes {
 edge [style=solid]
 uzcfcommandline_34_4 -> uzcdrawings_43_7
 edge [style=solid]
 uzcfcommandline_34_4 -> uzccommandsmanager_25_4
 edge [style=solid]
 uzcfcommandline_34_4 -> uzctreenode_26_4
 edge [style=dotted]
 uzcfcommandline_34_4 -> uzcshared_14_0
 edge [style=dotted]
 uzeentity_23_5 -> uzglviewareageneral_34_0
 edge [style=dotted]
 uzeentity_23_5 -> uzeentityfactory_9_0
 edge [style=dotted]
 uzeentity_23_5 -> uzeentgenericsubentry_18_0
 edge [style=dotted]
 uzeentity_23_5 -> UGDBSelectedObjArray_14_2
 edge [style=dotted]
 uzgprimitives_12_1 -> uzglvectorobject_12_0
 edge [style=solid]
 uzglvectorobject_12_0 -> uzgprimitives_12_1
 edge [style=solid]
 uzglviewareageneral_34_0 -> UGDBSelectedObjArray_14_2
 edge [style=solid]
 uzglviewareageneral_34_0 -> uzeentity_23_5
 edge [style=solid]
 uzglviewareageneral_34_0 -> uzedrawingabstract_15_0
 edge [style=solid]
 uzglviewareageneral_34_0 -> uzeentitiestree_10_0
 edge [style=solid]
 uzglviewareageneral_34_0 -> UGDBOpenArrayOfPV_12_1
 edge [style=solid]
 uzglviewareageneral_34_0 -> uzeentgenericsubentry_18_0
 edge [style=solid]
 uzglviewareageneral_34_0 -> UGDBVisibleOpenArray_9_0
 edge [style=solid]
 uzglviewareageneral_34_0 -> uzglviewareaabstract_19_0
 edge [style=solid]
 UGDBSelectedObjArray_14_2 -> uzeentwithmatrix_10_0
 edge [style=solid]
 UGDBSelectedObjArray_14_2 -> uzeentity_23_5
 edge [style=dotted]
 UGDBSelectedObjArray_14_2 -> uzedrawingabstract_15_0
 edge [style=dotted]
 UGDBSelectedObjArray_14_2 -> uzeentgenericsubentry_18_0
 edge [style=solid]
 uzeentwithmatrix_10_0 -> uzeentity_23_5
 edge [style=solid]
 uzeentwithmatrix_10_0 -> uzeentitiestree_10_0
 edge [style=solid]
 uzeentitiestree_10_0 -> gzctnrtree_8_0
 edge [style=solid]
 uzeentitiestree_10_0 -> UGDBVisibleOpenArray_9_0
 edge [style=solid]
 uzeentitiestree_10_0 -> uzeentity_23_5
 edge [style=solid]
 gzctnrtree_8_0 -> UGDBVisibleOpenArray_9_0
 edge [style=solid]
 gzctnrtree_8_0 -> uzeentity_23_5
 edge [style=solid]
 UGDBVisibleOpenArray_9_0 -> uzeentity_23_5
 edge [style=solid]
 UGDBVisibleOpenArray_9_0 -> UGDBOpenArrayOfPV_12_1
 edge [style=solid]
 UGDBOpenArrayOfPV_12_1 -> uzeentity_23_5
 edge [style=dotted]
 UGDBOpenArrayOfPV_12_1 -> uzeentityfactory_9_0
 edge [style=solid]
 uzeentityfactory_9_0 -> uzeentgenericsubentry_18_0
 edge [style=solid]
 uzeentityfactory_9_0 -> uzeentity_23_5
 edge [style=solid]
 uzeentgenericsubentry_18_0 -> UGDBVisibleTreeArray_8_0
 edge [style=solid]
 uzeentgenericsubentry_18_0 -> UGDBOpenArrayOfPV_12_1
 edge [style=solid]
 uzeentgenericsubentry_18_0 -> uzeentwithmatrix_10_0
 edge [style=solid]
 uzeentgenericsubentry_18_0 -> uzeentity_23_5
 edge [style=solid]
 uzeentgenericsubentry_18_0 -> uzeentitiestree_10_0
 edge [style=solid]
 UGDBVisibleTreeArray_8_0 -> uzeentitiestree_10_0
 edge [style=solid]
 UGDBVisibleTreeArray_8_0 -> UGDBVisibleOpenArray_9_0
 edge [style=solid]
 UGDBVisibleTreeArray_8_0 -> uzeentity_23_5
 edge [style=solid]
 uzedrawingabstract_15_0 -> uzeentity_23_5
 edge [style=solid]
 uzedrawingabstract_15_0 -> uzeentgenericsubentry_18_0
 edge [style=solid]
 uzedrawingabstract_15_0 -> uzeroot_13_0
 edge [style=solid]
 uzedrawingabstract_15_0 -> UGDBSelectedObjArray_14_2
 edge [style=solid]
 uzedrawingabstract_15_0 -> UGDBOpenArrayOfPV_12_1
 edge [style=solid]
 uzeroot_13_0 -> uzeentitiestree_10_0
 edge [style=solid]
 uzeroot_13_0 -> uzeentity_23_5
 edge [style=solid]
 uzeroot_13_0 -> uzeentgenericsubentry_18_0
 edge [style=solid]
 uzeroot_13_0 -> uzeentconnected_4_0
 edge [style=solid]
 uzeentconnected_4_0 -> uzeentity_23_5
 edge [style=solid]
 uzeentconnected_4_0 -> uzeentgenericsubentry_18_0
 edge [style=solid]
 uzeentconnected_4_0 -> UGDBOpenArrayOfPV_12_1
 edge [style=solid]
 uzglviewareaabstract_19_0 -> UGDBOpenArrayOfPV_12_1
 edge [style=solid]
 uzglviewareaabstract_19_0 -> uzeentgenericsubentry_18_0
 edge [style=solid]
 uzglviewareaabstract_19_0 -> uzeentitiestree_10_0
 edge [style=solid]
 uzglviewareaabstract_19_0 -> uzedrawingabstract_15_0
 edge [style=solid]
 uzglviewareaabstract_19_0 -> uzeentity_23_5
 edge [style=solid]
 uzcdrawings_43_7 -> uzedimblocksregister_15_1
 edge [style=solid]
 uzcdrawings_43_7 -> uzcdrawing_30_7
 edge [style=dotted]
 uzcdrawings_43_7 -> uzcenitiesvariablesextender_21_0
 edge [style=dotted]
 uzcdrawings_43_7 -> uzcshared_14_0
 edge [style=dotted]
 uzcdrawings_43_7 -> uzccommandsmanager_25_4
 edge [style=dotted]
 uzedimblocksregister_15_1 -> uzcutils_23_0
 edge [style=solid]
 uzcutils_23_0 -> zcmultiobjectcreateundocommand_8_0
 edge [style=solid]
 uzcutils_23_0 -> uzcdrawing_30_7
 edge [style=solid]
 uzcutils_23_0 -> uzcdrawings_43_7
 edge [style=solid]
 zcmultiobjectcreateundocommand_8_0 -> uzcdrawings_43_7
 edge [style=solid]
 uzcdrawing_30_7 -> zcchangeundocommand_9_2
 edge [style=solid]
 uzcdrawing_30_7 -> zcobjectchangeundocommand_5_1
 edge [style=dotted]
 uzcdrawing_30_7 -> uzcdrawings_43_7
 edge [style=dotted]
 uzcdrawing_30_7 -> uzcshared_14_0
 edge [style=dotted]
 uzcdrawing_30_7 -> uzccommandsmanager_25_4
 edge [style=dotted]
 zcchangeundocommand_9_2 -> uzcdrawings_43_7
 edge [style=dotted]
 zcobjectchangeundocommand_5_1 -> uzcdrawings_43_7
 edge [style=solid]
 uzcshared_14_0 -> uzcfcommandline_34_4
 edge [style=solid]
 uzccommandsmanager_25_4 -> uzcctrldynamiccommandmenu_7_1
 edge [style=solid]
 uzccommandsmanager_25_4 -> uzcinfoform_24_2
 edge [style=dotted]
 uzccommandsmanager_25_4 -> uzcshared_14_0
 edge [style=solid]
 uzcctrldynamiccommandmenu_7_1 -> uzcinfoform_24_2
 edge [style=dotted]
 uzcinfoform_24_2 -> uzcshared_14_0
 edge [style=solid]
 uzcenitiesvariablesextender_21_0 -> uzcshared_14_0
 edge [style=solid]
 uzctreenode_26_4 -> uzcutils_23_0
 edge [style=dotted]
 uzctreenode_26_4 -> uzcshared_14_0
 edge [style=dotted]
 uzctreenode_26_4 -> uzccommandsmanager_25_4
 edge [style=dotted]
 uzctreenode_26_4 -> uzcdrawings_43_7
 edge [style=solid]
 uzccombase_60_5 -> uzcoimultiobjects_19_3
 edge [style=dotted]
 uzcoimultiobjects_19_3 -> uzcmainwindow_95_3
 edge [style=dotted]
 uzcoimultiobjects_19_3 -> uzcoidecorations_38_3
 edge [style=solid]
 uzcmainwindow_95_3 -> uzcgui2color_15_1
 edge [style=solid]
 uzcmainwindow_95_3 -> uzcgui2linewidth_10_1
 edge [style=solid]
 uzcmainwindow_95_3 -> uzcgui2linetypes_18_1
 edge [style=solid]
 uzcmainwindow_95_3 -> uzcoidecorations_38_3
 edge [style=solid]
 uzcmainwindow_95_3 -> uzcgui2textstyles_12_1
 edge [style=solid]
 uzcmainwindow_95_3 -> uzcgui2dimstyles_11_1
 edge [style=dotted]
 uzcgui2color_15_1 -> uzcmainwindow_95_3
 edge [style=dotted]
 uzcgui2linewidth_10_1 -> uzcmainwindow_95_3
 edge [style=dotted]
 uzcgui2linetypes_18_1 -> uzcmainwindow_95_3
 edge [style=solid]
 uzcoidecorations_38_3 -> uzccominterface_64_2
 edge [style=dotted]
 uzcoidecorations_38_3 -> uzcgui2color_15_1
 edge [style=dotted]
 uzcoidecorations_38_3 -> uzcgui2linewidth_10_1
 edge [style=dotted]
 uzcoidecorations_38_3 -> uzcgui2linetypes_18_1
 edge [style=solid]
 uzccominterface_64_2 -> uzcflinetypes_29_1
 edge [style=solid]
 uzccominterface_64_2 -> uzccombase_60_5
 edge [style=solid]
 uzccominterface_64_2 -> uzcflayers_45_1
 edge [style=dotted]
 uzccominterface_64_2 -> uzcmainwindow_95_3
 edge [style=dotted]
 uzcflinetypes_29_1 -> uzcgui2linetypes_18_1
 edge [style=dotted]
 uzcflayers_45_1 -> uzcgui2linetypes_18_1
 edge [style=dotted]
 uzcgui2textstyles_12_1 -> uzcmainwindow_95_3
 edge [style=dotted]
 uzcgui2dimstyles_11_1 -> uzcmainwindow_95_3
}
(http://i78.fastpic.ru/thumb/2016/0922/3e/f7db9d627c68c1ad654fc544ca4ac53e.jpeg)
Obtained statistics:
Quote
Total units: 349
Total founded units: 244
Total units with Implimentation uses: 63
Total units in loops: 43
Total dependencies: 3697
Total dependencies in loops: 112
Implimentation uses can be move to interface in uzclog, uzcsysinfo, uzcguimanager, UGDBPoint3DArray, uzgloglstatemanager, uzeentdevice, uzeentdimension, uzcregother, uzeffttf, uzegluinterface, uzeentdimensiongeneric, uzeentdimaligned, uzcentnet, UGDBGraf, uzeentlwpolyline, uzcdevicebaseabstract, uzcdevicebase, uzcfprojecttree, uzcctrlcontextmenu, uzccommandsimpl, uzctextenteditor, zcobjectchangeundocommand2, uzcfabout, uzcfhelp, uzcctrllayercombobox, uzccomdb, uzccomdraw, uzccomdrawdase, uzeenttable, uzcprinterspecfunc, uzcentcable, uzccomelectrical, uzcentelleader, uzccablemanager, uzccomops, uzctextpreprocessorimpl, uzclibraryblocksregister;

The program began depend on several packages, so I give a link to the win32 binary https://sourceforge.net/projects/zcad/files/pugdb.7z/download

The program also uses a patched version fcl-passrc from here http://bugs.freepascal.org/view.php?id=30615
« Last Edit: September 22, 2016, 07:33:56 pm by zamtmn »

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 577
    • Burdjia
Re: Visualization of Pascal program dependencies
« Reply #9 on: September 23, 2016, 11:57:44 am »
Thanks.

A suggestion:  add the version number or the date to the name of the package file.  This will help users (like me ;)) to know what version has been downloaded.

Thaddy

  • Hero Member
  • *****
  • Posts: 3387
Re: Visualization of Pascal program dependencies
« Reply #10 on: September 23, 2016, 12:47:33 pm »
Thanks.

A suggestion:  add the version number or the date to the name of the package file.  This will help users (like me ;)) to know what version has been downloaded.
Oh, well,
Do that yourself, like I do.
REVSTR=<svnversion>  REVINC=force

You are not a nobody, you know how to do that. This can even be done on file level. Actually, it is used at file level with the standard makefile.
« Last Edit: September 23, 2016, 12:53:13 pm by Thaddy »

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #11 on: December 21, 2016, 12:20:34 am »
Hi All! Small improvements:
Added: analysis of all files in a directory by mask. (example: file=Z:\hdd\src\fpc\fpcsrc\ide\*.pas;*.pp path=Z:\hdd\src\fpc\fpcsrc\ide\)
Added: on loop graph each edges signed his "weight" (how much loops will be left if this dependence eliminated)
On test program from here http://forum.lazarus.freepascal.org/index.php/topic,35136.msg232043.html#msg232043 , it looks like attached screen

Also in report appeared recommendation to remove the dependence
Quote
The worst addiction from "uViewIntegrator" to "uRtfdDiagram" with 20
« Last Edit: December 21, 2016, 12:40:59 am by zamtmn »

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #12 on: January 05, 2017, 11:07:31 pm »
I forgot to add - result of the program can be converted to *.graphml file format. With this format you can work in a yEd vector editor, and allow the images to more visual view.

Python scripts for translation can be found here:
https://bitbucket.org/dirkbaechle/dottoxml or https://github.com/vivin/dottoxml
« Last Edit: January 05, 2017, 11:11:52 pm by zamtmn »

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #13 on: February 13, 2017, 10:18:37 am »
Hi All!
Small improvements:
Add Lasarus macros support to lpi importer: Ext, Path, Name, NameOnly, MakeDir, MakeFile, TargetCPU, TargetOS, ProjOutDir, PkgDir

zamtmn

  • Sr. Member
  • ****
  • Posts: 270
Re: Visualization of Pascal program dependencies
« Reply #14 on: April 05, 2017, 11:35:25 pm »
Hi All!
PUDGB became cross-platform!
The old Delphi package AGraph now works in Win|Lin 32|64. This is a powerful package for working with graphs.
Maybe it's useful to someone else - http://svn.shamangrad.net/zcad/trunk/cad_source/other/AGraphLaz/

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus