From owner-freebsd-questions@freebsd.org Fri Apr 9 04:40:01 2021 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E481F5CAB97 for ; Fri, 9 Apr 2021 04:40:01 +0000 (UTC) (envelope-from bennett@sdf.org) Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mx.sdf.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FGlmJ5P25z3mJc for ; Fri, 9 Apr 2021 04:40:00 +0000 (UTC) (envelope-from bennett@sdf.org) Received: from sdf.org (IDENT:bennett@rie.sdf.org [205.166.94.4]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 1394dqEd014808 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Fri, 9 Apr 2021 04:39:52 GMT Received: (from bennett@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 1394dogG015985; Thu, 8 Apr 2021 23:39:50 -0500 (CDT) From: Scott Bennett Message-Id: <202104090439.1394dogG015985@sdf.org> Date: Thu, 08 Apr 2021 23:39:50 -0500 To: ml@netfence.it Subject: Re: Profiling C application Cc: freebsd-questions@freebsd.org References: <202011281922.0ASJMtiH020409@sdf.org> <16423477-7854-20bf-58ff-c174375e37fe@netfence.it> <202011291202.0ATC2rbO024634@sdf.org> <1139046c-7f48-dbdb-0790-bb821e9e9001@netfence.it> In-Reply-To: <1139046c-7f48-dbdb-0790-bb821e9e9001@netfence.it> User-Agent: Heirloom mailx 12.5 6/20/10 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4FGlmJ5P25z3mJc X-Spamd-Bar: --- X-Spamd-Result: default: False [-3.80 / 15.00]; RCVD_TLS_ALL(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[205.166.94.24:from]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:205.166.94.0/24]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[]; SPAMHAUS_ZRD(0.00)[205.166.94.24:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[sdf.org,quarantine]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:14361, ipnet:205.166.94.0/24, country:US]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-questions] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Apr 2021 04:40:01 -0000 Andrea Venturoli wrote: > On 11/29/20 1:02 PM, Scott Bennett wrote: > > Andrea Venturoli wrote: > > > >> On 11/28/20 8:22 PM, Scott Bennett via freebsd-questions wrote: > >> > >>> I see you already have one response at least to your question, but > >>> perhaps a simpler one is to use a now ancient BSD UNIX tool called gprof(1), > >>> along with the compiler option -pg. (See the gprof(1) man page for the > >>> details.) Note, too, that you may want to link your program to the profiling > >>> versions of system libraries as explained in the man page. > >> > >> I didn't mention gprof because it stopped working when FreeBSD switched > >> from GCC to clang. Or, maybe, it was my fault, not being able to get it > >> working again. > >> > >> That was a long time ago, however; if nowadays it's a viable solution, > >> I'm happy to hear this. > >> > > Bugzilla only turned up one PR that may have a bearing on that. See > > PR 198462 from 2017 and 10.1. There's no sign that anyone, other than the poster > > of the PR, even looked into it, an unfortunately common situation. > > Thank you for pointing out the problem. Do you still have a test case you > > could try? > > Sorry for answering so late... > > Today I need once again to profile a program and, since valgrind is > currently broken :-(, I decided to give gprof another shot (on 12.2/amd64). > > As per gprof(1), I added "-pg" to compilation and linking phase, i.e. my > program compiles with something like: > c++ -c -ggdb -O0 -pg ... -o a.o a.cxx > c++ -c -ggdb -O0 -pg ... -o b.o b.cxx > ... > c++ -o a.exe a.o b.o ... -lthr -pg ... > > When I run it, I get: > % ./a.exe > ld-elf.so.1: /lib/libc.so.7: Undefined symbol "__progname" > > gprof(1) states that "The -pg option also links in versions of the > library routines that are compiled for profiling". Alas, this does not > seem to be the case: > ldd a.exe > a.exe: > libarchive.so.13 => /usr/local/lib/libarchive.so.13 (0x8004a0000) > libboost_filesystem.so.1.72.0 => > /usr/local/lib/libboost_filesystem.so.1.72.0 (0x800574000) > libboost_program_options.so.1.72.0 => > /usr/local/lib/libboost_program_options.so.1.72.0 (0x800591000) > libboost_system.so.1.72.0 => /usr/local/lib/libboost_system.so.1.72.0 > (0x8005f1000) > libcrypto.so.111 => /lib/libcrypto.so.111 (0x8005f5000) > libexpat.so.1 => /usr/local/lib/libexpat.so.1 (0x8008e7000) > liblzo2.so.2 => /usr/local/lib/liblzo2.so.2 (0x800914000) > liblzma.so.5 => /usr/lib/liblzma.so.5 (0x800944000) > liblz4.so.1 => /usr/local/lib/liblz4.so.1 (0x800970000) > libbz2.so.4 => /usr/lib/libbz2.so.4 (0x80099e000) > libz.so.6 => /lib/libz.so.6 (0x8009b4000) > libc.so.7 => /lib/libc.so.7 (0x8009d0000) > libc++.so.1 => /usr/lib/libc++.so.1 (0x800dc6000) > libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x800e93000) > libm.so.5 => /lib/libm.so.5 (0x800eb5000) > libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x800ee7000) > libthr.so.3 => /lib/libthr.so.3 (0x800f01000) > libmd.so.6 => /lib/libmd.so.6 (0x800f2e000) > > I think I should change "-lthr" to "-lthr_p", but that does not make any > difference. Ditto if I add "-lc_p": apparently these are ignored. Actually, I think it should work even using non-profiling libraries, but you wouldn't see any data gathered regarding calls within those libraries. > > What am I doing wrong? > > BTW, would solving this be enough or would I later hit the fact that I'm > using third party libraries (e.g. boost) which are not compiled with "-pg"? > See above. I am afraid I can be of little help. The last time I recall playing with this stuff was under 4.3BSD or maybe SunOS 4.2. Either way it was with a now- ancient compiler and set of libraries, not one used today. Now, thirty-odd years later, I remember nothing much about it. My apologies to you. Two questions occur to me. Have you tried using gcc/g++ as a test? Have you tested it on a C program instead of a C++ program? Scott