Jump to content

Lisp code profiler, call graph generator


Suha

Recommended Posts

Call Grind for Lisp (CG) is a Lisp application aimed to help profiling of lisp programs running on IntelliCAD, AutoCAD, BricsCAD and alikes. If you are in need of determining the bottle-necks, the time consumed for specified functions , visualize call diagram of your lisp application you may find CG useful.

 

CG collects data (time consumed by each function and call stack) at runtime (dynamic analysis) and creates “call grind” type output to be used by CacheGrind system (credit goes to authors). 

cg.thumb.png.f9851557ad10e5d8a2eeea1ae922f8fb.png

 

cg_table.png.b5d5523a079c0933e8b6e7f289bd50ac.png

 

Requirement:  

Download and install qcachegrind software recompiled for Windows version of KCacheGrind. 

 

Refer to header of the lisp code attached for instructions.

 

Limitation: May fail in consecutive functions forming loop.

License: Copy Left

 

Enhanced the code, found a bug? Just let me know.

 

Suha

cg.lsp

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Once you know "the time consumed for specified functions" what then ?

 

Its well known that entmake is faster than command if doing in the hundreds. Making a table turn off the table regen turn back on when finished 1 line of code = 14 minutes of time save creating a 200+ line table with some complicated calcs.

 

I write very simple lisp compared to others and at times is slow, time saving is in knowing about something in the coding method rather than this function causes a 5 minute delay. I dont write a couple of hundred lines of code with out testing like 20 at a time or seperate defuns, so soon find a bottle neck and stop and have a think about is there a faster way. 

 

Having a number of speed up hints would probably be more beneficial, there are numerous posts here were methods have been compared on like a 1000 repetitions to get the best optimised code.

 

What is slow ? Something I just did say 15 minutes to draft. With dcl user input its now like 20 seconds. Is this not fast enough ? The only time, excuse pun is when manipulating large data sets that the Cad can seriously slow down. Its up to the programmer then to look at how to fix.

Link to comment
Share on other sites

  • 1 year later...

Thank you so much for this program, it has allowed us to profile a large AutoLISP application and find out where the bottlenecks were.

 

A small fix I made (at least on Windows) was on line 271: 

(setq fname (strcat fname "\\callgrind.out.lisp"))

 

I had to add the \\ because "MYDOCUMENTSPREFIX" (in my case: "C:\\Users\\<user>\\Documents") does not end with them, so it would save the file as "Documentscallgrind.out.lisp".

 

I also added/fixed the provided Regex to support VSCode out of the box, as this is the main environment we program in because of the official AutoLISP extension:

Find (VSCode):
  ^\(defun\s+(\S+)\s*(\(([\w\s\n\-\+%&#$@]*).*)
    
Replace (VSCode):
  (defun $1 ($3 / retval)\n\t(cg_begin "$1")\n\t(setq retval ($1_cg$ $3))\n\t(cg_end)\n\tretval\n)\n(defun $1_cg$ $2

Maybe this is useful for other people too.

 

Thank you again for this wonderful program :) 

Link to comment
Share on other sites

  • 1 month later...

It is commonly known that entmake executes commands in the hundreds of times faster than command. Making a table turn off the table regen turn back on when finished saves 14 minutes compared to making a 200+ line table with a few tricky calculations.

 

It would store the file as "Documentscallgrind.out.lisp," thus I had to append the since "MYDOCUMENTSPREFIX" (in my example, "C: Usersuser>Documents") does not end with them.


Compared to other people, I write extremely simple lisp, which can occasionally be slow. Time can be saved by understanding a coding technique rather than by using a function that delays execution by 5 minutes. I don't create many hundred lines of code without testing them like 20 at a time or using separate defuns, so I quickly run into a bottleneck and have to pause and consider whether there is a quicker method.

Link to comment
Share on other sites

The fact that entmake processes instructions numerous times faster than command is well known. As opposed to creating a 200plus line table with a few challenging computations, creating a table that turns off the table regenerate and turns back on when finished saves minutes.

Due to the click that "MYDOCUMENTSPREFIX" (in my case, "C: Usersuser>Documents") does not end with them, the file would be stored as "Documentscallgrind.out.lisp," therefore I had to append it.

I write very simple lisp, which is sometimes slow, compared to other people. Learning a coding trick can save time instead of employing a function whose execution is delayed by five minutes. I rarely write more than a few hundred lines of code without testing them Twenty at a time or using separate defuns, so I rapidly hit a roadblock and must halt to think of a faster way.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...