home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18287 < prev    next >
Encoding:
Text File  |  1992-12-22  |  1.8 KB  |  55 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!think.com!rpi!zaphod.mps.ohio-state.edu!uunet.ca!ohrd!twriter
  3. From: twriter@rd.hydro.on.ca (Timothy Writer)
  4. Subject: Re: profiling g++ code
  5. Message-ID: <1992Dec21.223548.8464@rd.hydro.on.ca>
  6. Reply-To: twriter@rd.hydro.on.ca
  7. Organization: "Ontario Hydro - Research Division"
  8. References: <BzHJwy.LpG@cs.columbia.edu>
  9. Distribution: usa
  10. Date: Mon, 21 Dec 92 22:35:48 GMT
  11. Lines: 42
  12.  
  13. ykim@cs.columbia.edu (Yong Su Kim) writes:
  14.  
  15.  
  16. >I have a C++ program and I would like to profile it to see which
  17. >functions are taking the most time so that I can optimise those
  18. >functions. 
  19.  
  20. >I tried g++ -p, but I get an error message saying that the symbol
  21. >"mcount" is undefined.
  22.  
  23. On many systems you need to link with a profiling library, for example
  24. /usr/lib/libc_p.a (Sun) or /usr/lib/libprof1.a (SGI).  The -p option of
  25. g++ (gcc) is supposed to take care of this for you; however, on some
  26. systems it may not, for example, my SGI.  On my system g++ -p -v
  27. illustrates the problem:
  28.  
  29.     ...
  30.     /very-long-path/ld /usr/lib/mcrt1.o ... file.o -lg++ -lgcc -lc_p ...
  31.  
  32. Do you see the problem?  g++ is trying to link libc_p not libprof1.  Of
  33. course, the proper fix is to patch g++ which is not difficult but I
  34. haven't had time.  The short term solution is to add -lprof1 to the g++
  35. command line and create a dummy libc_p.a in the current working
  36. directory:
  37.  
  38.     ln -s /usr/lib/libc.a libc_p.a
  39.     g++ -L. -p -v file.o -lprof1
  40.  
  41. As you didn't tell us what kind of system you are using, I can't say if
  42. this fix will work for you but you should be able to do something
  43. similar.
  44.  
  45. >Are there other ways, or other programs which will allow me to
  46. >determine which functions are taking the most time?
  47.  
  48. Tim
  49.  
  50. -- 
  51. Tim Writer                 phone:  (416) 231-4111 ext. 6990
  52. Ontario Hydro Research Division         fax:    (416) 237-9285
  53. Toronto, Ontario             e-mail: twriter@rd.hydro.on.ca
  54. CANADA
  55.