Author Topic: Are you logging your lisp routine usage?  (Read 11414 times)

0 Members and 1 Guest are viewing this topic.

Didge

  • Bull Frog
  • Posts: 211
Re: Are you logging your lisp routine usage?
« Reply #15 on: November 04, 2011, 07:10:49 AM »
Here's a cheap and cheerful logging function. It saves entries to a monthly CSV text file for easy manipulation within a spreadsheet. 

Just add the line  (Lisp-Log "your Command Name") to the beginning of each routine.

Code: [Select]
(defun LISP-LOG (CMD / Path Adminpath Adminfile)
  (if (and (setq Path (getvar "TEMPPREFIX")) ; replace this path with a suitable network drive
   (setq Adminpath (strcat Path "Lisp-Log-File_" (menucmd (strcat "m=$(edtime,$(getvar," "date" ")," "MONYYYY" ")")) ".csv"))
   (if (findfile Adminpath) (setq Adminfile (open Adminpath "a"))(setq Adminfile (open Adminpath "w")))
      )
    (progn
      (write-line (strcase (strcat (getvar "LOGINNAME") "," CMD ","
(menucmd (strcat "m=$(edtime,$(getvar," "date" ")," "DDDD D MONTH YYYY H:MMam/pm" ")")) ","
(vl-string-translate "," "*" (strcat (getvar "dwgprefix")(getvar "dwgname"))))) Adminfile)
      (close Adminfile)
      T
    )
    (alert "Logging Error")
  )
)
Think Slow......

V-Man

  • Bull Frog
  • Posts: 335
  • I exist therefore I am!
Re: Are you logging your lisp routine usage?
« Reply #16 on: November 04, 2011, 08:24:32 AM »
Here's one from Ron back in 2004. Still works.

Code: [Select]
;;; :FUNCTION
;;; ADDS ENTRIES TO THE LOCAL AND SERVER ENUMERATION FILES
;;; :LIMITATIONS
;;; NONE
;;; :USAGE
;;; ADD THE FOLLOWING LINES TO THE LSP ROUTINES YOU WANT TO RECORD
;;; (IF (= nil id:lispold)
;;;     (setq id:lispold "x")
;;;     (setq id:lispold id:lisp))
;;; (setq id:lisp "FILENAME.lsp")
;;; (c:LispCounter)
;;; :PLATFORMS
;;; 2000+
;;; :AUTHOR
;;; Ron Heigh
;;; email: ron.heigh@globaldetailing.com
;;; :VERSION
;;; 1.0 July 01, 2004
;;; Copyright 2004
;;;
(DEFUN c:LispCounter (/ D YR MO DAY MT HR M S P_TIME P_DATE fp:output fp:output2)
  (setq D   (rtos (getvar "CDATE") 2 6)
    YR  (substr D 3 2)
    MO  (substr D 5 2)
    DAY (substr D 7 2)
  ) ; end of setq
  (setq P_DATE (strcat MO "/" DAY "/" YR))
  (setq
    D  (rtos (getvar "CDATE") 2 6)
    MT (substr D 10 2)
    MT (atoi MT)
  ) ; end of setq
  (if (> MT 12)
    (setq HR (- MT 12))
    (setq HR MT)
  )
  (if (>= MT 12)
    (setq TOD " PM")
    (setq TOD " AM")
  )
  (setq HR (rtos HR 2 0))
  (setq
    M  (substr D 12 2)
    S  (substr D 14 2)
  ) ; end of setq
  (setq P_TIME (strcat HR ":" M ":" S TOD))
  (setq labeltext (strcat p_date " " P_time))
  (setq fp:output (open "c:\\lisp_count.csv" "a"))
  (write-line (strcat id:lisp "," P_DATE "," P_TIME "," (getvar "loginname")) fp:output)
  (close fp:output)
  (princ)
)
AutoCAD 2010 64-bit, AutoCADMap 2008, 2010, Revit 2012

pBe

  • Bull Frog
  • Posts: 377
Re: Are you logging your lisp routine usage?
« Reply #17 on: November 04, 2011, 08:29:43 AM »
vlr-lisp-reactor comes to mind.  :wink:

I never knew that reactor even exists  :lol:

Thanks Lee

Exactly :) ... I'll try to post what I have later ...

Great  :-D

Thank you for that Ron, you are too kind.

Chris

  • Swamp Rat
  • Posts: 546
Re: Are you logging your lisp routine usage?
« Reply #18 on: November 04, 2011, 08:51:10 AM »
you would almost have to use the reactor in order to really log the routine usage, unless you only have one defun per file.  It depends on what you are looking for, if you want to just trace your routines, or see how much any routine is being used.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Re: Are you logging your lisp routine usage?
« Reply #19 on: November 06, 2011, 06:15:35 PM »
Great Topic

One Question, does the counter slow down the work significant?

 
Bernd

ronjonp

  • Needs a day job
  • Posts: 7340
Re: Are you logging your lisp routine usage?
« Reply #20 on: November 06, 2011, 07:59:43 PM »
I don't notice any speed differences.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12549
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #21 on: November 07, 2011, 11:29:06 AM »
Attached is a simple LISP usage logging routine, with data written daily to a CSV log file.

The program uses a LISP-reactor to automatically monitor LISP command usage, and will write data to the log file upon the user saving the drawing.

The program is set to run when loaded, so, to enable automatic LISP logging just set the program to load on startup (either using ACADDOC.lsp / StartupSuite).

You can enable or disable the logging by typing 'LispLogON' and 'LispLogOFF' respectively at the command-line.

Log Files are saved to the folder specified at the top of the code, this folder is created if not present.

Any questions, just ask.

KewlToyZ

  • Guest
Re: Are you logging your lisp routine usage?
« Reply #22 on: November 08, 2011, 12:17:24 PM »
I did something a bit low bro using
Code: [Select]
(defun c:MyRoutine()

(command "LOGFILEON")
; insert code here
(command "LOGFILEOFF")
)
In my routines. I had all of the users using the same profile so they all save to a log file directory on their individual hard drives.
I did try some logging systems before saving to a network storage folder but found it was crashing cad when publishing for a reason neither myself nor Autodesk could figure out why and abandoned.

cmwade77

  • Swamp Rat
  • Posts: 1308
Re: Are you logging your lisp routine usage?
« Reply #23 on: November 08, 2011, 04:28:15 PM »
Attached is a simple LISP usage logging routine, with data written daily to a CSV log file.

The program uses a LISP-reactor to automatically monitor LISP command usage, and will write data to the log file upon the user saving the drawing.

The program is set to run when loaded, so, to enable automatic LISP logging just set the program to load on startup (either using ACADDOC.lsp / StartupSuite).

You can enable or disable the logging by typing 'LispLogON' and 'LispLogOFF' respectively at the command-line.

Log Files are saved to the folder specified at the top of the code, this folder is created if not present.

Any questions, just ask.
It doesn't seem to log anything, I am not sure why though.

Lee Mac

  • Seagull
  • Posts: 12549
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #24 on: November 08, 2011, 04:36:05 PM »
It doesn't seem to log anything, I am not sure why though.

A few questions/statements:
  • The logs are only created when the drawing is saved (so that there is no loss in performance).
  • Do you know where the CSV files are being stored?
  • The routine will only log 'LISP' command usage, not all commands (as per the thread)
  • The routine will not log macros (as these are not LISP expressions).

Krushert

  • Seagull
  • Posts: 13662
  • FREE BEER Tomorrow!!
Re: Are you logging your lisp routine usage?
« Reply #25 on: November 08, 2011, 04:49:59 PM »
Attached is a simple LISP usage logging routine, with data written daily to a CSV log file.

The program uses a LISP-reactor to automatically monitor LISP command usage, and will write data to the log file upon the user saving the drawing.

The program is set to run when loaded, so, to enable automatic LISP logging just set the program to load on startup (either using ACADDOC.lsp / StartupSuite).

You can enable or disable the logging by typing 'LispLogON' and 'LispLogOFF' respectively at the command-line.

Log Files are saved to the folder specified at the top of the code, this folder is created if not present.

Any questions, just ask.
Just as my time is running out, you serve up this awesome code. **sigh**
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12549
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #26 on: November 08, 2011, 05:05:15 PM »
Just as my time is running out, you serve up this awesome code. **sigh**

Cheers Krush, hope you can use it  :-)

alanjt

  • Needs a day job
  • Posts: 5340
  • Standby for witty remark...
Re: Are you logging your lisp routine usage?
« Reply #27 on: November 08, 2011, 05:09:27 PM »
Logging is a good idea - should have thought about it sooner. What about something like this? It's been working successfully for a few days now.

You'll have to edit the folder path.

Code: [Select]
(vl-load-com)

  ;; LISP LOGGER
  ;; Alan J. Thompson

(or *Reactor:LISPLogger*
    (setq *Reactor:LISPLogger*
           (list (vlr-lisp-reactor nil '((:vlr-lispWillStart . Reactor:LISPLogger))))
    )
)



(defun Reactor:LISPLogger (a b / s f)
  (if
    (and (not (wcmatch (setq s (strcase (vl-princ-to-string (car b)))) "*DEFUN*,*VLIDE*,*LISPLOG*"))
         (wcmatch s "*(C:*")
    )
     (progn (write-line
              (strcat "(\""
                      (substr (vl-string-trim "()" s) 3)
                      "\" \""
                      (strcase (getvar 'LOGINNAME))
                      "\")"
              )
              (setq f (open
                        (strcat "U:\\LISPLog\\"
                                (menucmd (strcat "m=$(edtime,$(getvar," "DATE" ")," "MONTH_YYYY" ")"))
                                ".txt"
                        )
                        "A"
                      )
              )
            )
            (close f)
     )
  )
)




(defun c:LISPLog (/ AT:WriteToFile file item final cmd user)

  (defun AT:WriteToFile (file lst overwrite / fo)
    ;; Write list to file
    ;; file - file to write list to (must be in form "c:\\File.txt")
    ;; lst - list to write to file
    ;; overwrite - If T, will overwrite; nil to append
    ;; Alan J. Thompson, 04.28.09
    (if (and (vl-consp lst)
             (setq fo (open file
                            (if overwrite
                              "W"
                              "A"
                            )
                      )
             )
        )
      (progn (foreach x lst (write-line (vl-princ-to-string x) fo))
             (close fo)
             file
      )
    )
  )

  (if (and (setq file (getfiled "Select LISP Log text file:" "U:\\LISPLog\\" "TXT" 2))
           (setq file (open file "R"))
      )
    (progn
      (while (setq item (read-line file))
        (setq item  (read item)
              final (if (setq cmd (assoc (car item) final))
                      (subst (cons (car cmd)
                                   (if (setq user (assoc (cadr item) (cdr cmd)))
                                     (subst (cons (car user) (1+ (cdr user))) user (cdr cmd))
                                     (cons (cons (cadr item) 1) (cdr cmd))
                                   )
                             )
                             cmd
                             final
                      )
                      (cons (list (car item) (cons (cadr item) 1)) final)
                    )
        )
      )
      (vlax-invoke-method
        (setq shell (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application"))
        'Open
        (AT:WriteToFile
          (vl-filename-mktemp "" nil ".xls")
          (mapcar
            '(lambda (item)
               (strcat
                 (car item)
                 "\t"
                 (apply 'strcat
                        (apply 'append
                               (mapcar '(lambda (x) (list (vl-princ-to-string x) "\t"))
                                       (vl-sort (cdr item) '(lambda (a b) (< (car a) (car b))))
                               )
                        )
                 )
               )
             )
            (vl-sort final '(lambda (a b) (< (car a) (car b))))
          )
          T
        )
      )
      (vlax-release-object shell)
    )
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

cmwade77

  • Swamp Rat
  • Posts: 1308
Re: Are you logging your lisp routine usage?
« Reply #28 on: November 08, 2011, 05:36:45 PM »
It doesn't seem to log anything, I am not sure why though.

A few questions/statements:
  • The logs are only created when the drawing is saved (so that there is no loss in performance).
  • Do you know where the CSV files are being stored?
  • The routine will only log 'LISP' command usage, not all commands (as per the thread)
  • The routine will not log macros (as these are not LISP expressions).
I didn't quite realize that it was only when drawings were being saved, that works now, thank you. I made a few tweaks, such as I want it all saved in one file for each month and to save the username with each command, but that didn't take too much to accomplish.

This will definitely help with figuring out who needs more training. I know some people are not using our LISP routines, which are there to make work much faster, I just haven't been able to figure out who is not using them.

Lee Mac

  • Seagull
  • Posts: 12549
  • London, England
Re: Are you logging your lisp routine usage?
« Reply #29 on: November 08, 2011, 06:04:00 PM »
Excellent to hear Chris, I'm glad the program is useful to you and that you were able to tailor it to your needs  :-)