tag:blogger.com,1999:blog-9675303.post521501662170664527..comments2014-03-30T16:15:00.967+02:00Comments on Homebrew Coding: Profiling Android NDK CodeRichard Quirkhttp://www.blogger.com/profile/16290285494071462742noreply@blogger.comBlogger37125tag:blogger.com,1999:blog-9675303.post-76432817778998033352013-06-05T22:36:20.829+02:002013-06-05T22:36:20.829+02:00I'm getting the same undefined reference compi...I'm getting the same undefined reference compilation errors when I attempt to use android-ndk-profiler in my project. I'm using version 3.2, and I've got the extern "C" declarations in my header. <br /><br />Without the extern "C" declarations, I get 'monstartup not declared in this scope'. With them, I get 'undefined reference to monstartup'.<br /><br />Any tips?QRohlfhttps://www.blogger.com/profile/01538260020307175087noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-79226845774855853942012-11-16T14:13:25.268+01:002012-11-16T14:13:25.268+01:00I got similar problem, no time data but only call,...I got similar problem, no time data but only call, I used this library in Android 4.1 emulator and manually compiled it.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9675303.post-75322828648399807972012-03-06T09:14:01.219+01:002012-03-06T09:14:01.219+01:00output i m getting is
% cumulative self ...output i m getting is <br /><br /> % cumulative self self total <br /> time seconds seconds calls Ts/call Ts/call name <br /> 0.00 0.00 0.00 43066 0.00 0.00 std::less::operator()(std::string const&, std::string const&) const<br /><br /><br />Followed your instruction. But the output is weird. Why all the values are 0.00?<br /><br />Is there something that i missed. Thanks in advance.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9675303.post-10559103372831117662012-01-12T02:39:39.921+01:002012-01-12T02:39:39.921+01:00To use Android native pofilier. I used the profili...To use Android native pofilier. I used the profiling library while compiling .so<br />and also used monstartup and mon cleaup in the source file sused to make .so.<br /><br /><br />I am able to get first three parameter in Flat pofile but rest of the parameters are zero. May I know is there as way to ge that information as wellAnandhttps://www.blogger.com/profile/14013737904363005349noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-50610738735799719862012-01-12T02:36:36.000+01:002012-01-12T02:36:36.000+01:00Is it possible to know how much CPU each thread in...Is it possible to know how much CPU each thread in Android native code took. in short Android native code thread profilingAnandhttps://www.blogger.com/profile/14013737904363005349noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-39472286617258943182011-11-18T04:03:47.105+01:002011-11-18T04:03:47.105+01:00Richard,
I'm trying to use your profiler on a...Richard,<br /><br />I'm trying to use your profiler on a JNI app. I don't have much experience with makefiles. I can't seem to get the makefile to build no matter where I insert the snippets from the Usage guide. Can you give me some guidance here? Here is my makefile:<br /><br /><br />TOP_LOCAL_PATH := $(call my-dir)<br /><br />include $(TOP_LOCAL_PATH)/fmod/Android.mk<br /><br />LOCAL_PATH := $(TOP_LOCAL_PATH)<br /><br />include $(CLEAR_VARS)<br /><br />LOCAL_CPP_EXTENSION := .cpp<br /><br />LOCAL_MODULE := xxx<br /><br />include $(LOCAL_PATH)/Sources.mk<br /><br />LOCAL_USER_CFLAGS := -DTARGET_NDK -DOPENGLES -DUSE_LEVEL_LIST<br /><br />ifeq ($(NDK_DEBUG),1)<br /> LOCAL_USER_CFLAGS += -D_DEBUG<br />else<br /> LOCAL_USER_CFLAGS += -DNDEBUG -Os -funroll-loops<br />endif<br /><br />ifeq ($(NDK_LITE),1)<br /> LOCAL_USER_CFLAGS += -D_LITE<br />endif<br /><br />LOCAL_CFLAGS := -Wall $(LOCAL_USER_CFLAGS) $(LOCAL_INCLUDE_CFLAGS) <br /><br />LOCAL_ARM_MODE := arm<br /><br />LOCAL_LDLIBS := -llog -lGLESv1_CM -lz #-lthread_db<br />LOCAL_SHARED_LIBRARIES := fmod-prebuilt<br /><br />include $(BUILD_SHARED_LIBRARY)Jason Pechohttp://www.jasonpecho.comnoreply@blogger.comtag:blogger.com,1999:blog-9675303.post-92004016734400296222011-10-12T12:45:27.539+02:002011-10-12T12:45:27.539+02:00You can compile it in your own code, just as long ...You can compile it in your own code, just as long as you make sure not to do so with -pg on the actual profiling code (or it will get confused).Richard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-62651620300589424542011-10-10T10:14:32.078+02:002011-10-10T10:14:32.078+02:00Nope, it's armeabi-v7a.
I didnt't manage t...Nope, it's armeabi-v7a.<br />I didnt't manage to link with the .a module, but I can compile the profiler from source. However, I get SIGSEGV upon program startup from somewhere outside (before) of my source code.<br />Is it even legitimate to compile your profiler right into my shared module?Alexhttps://www.blogger.com/profile/13586753411926201847noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-67801436476130992942011-10-07T19:41:45.537+02:002011-10-07T19:41:45.537+02:00Can't do much with just that snippet. The Erro...Can't do much with just that snippet. The Error 1 is the error code that the program actually erroring out passed to make. I guess it is gcc linking - perhaps you're using armeabi rather than armeabi-v7a?Richard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-42553861398308504582011-10-07T16:49:58.923+02:002011-10-07T16:49:58.923+02:00Hello!
Thanks for your effort developing the profi...Hello!<br />Thanks for your effort developing the profiler, I can't wait to give it a try. <br />I'm having a slight problem, could you please help? I'm getting this error when I try to compile my lib with your profiler (strictly sticking to your instructions):<br /><br />make: *** [/home/alex/the_project/android/obj/local/armeabi-v7a/libandprof.a] Error 1<br />make: *** Waiting for unfinished jobs....<br /><br />**** Build Finished ****<br /><br />The libandprof.a module is indeed at the path shown above.<br /><br />Thanks in advance!Alexhttps://www.blogger.com/profile/13586753411926201847noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-74969800641299617632011-08-23T23:21:34.861+02:002011-08-23T23:21:34.861+02:00@Jay - looks like the glue function is called &quo...@Jay - looks like the glue function is called "mcount" on x86 and it is put in by the compiler, it doesn't appear in the disassembly of the object files like with arm. APart from that, there's the issue of getting the instruction pointer from pt_regs, which on arm is easy (there's a macro for it) but on x86 it's a mystery to me.Richard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-74521587580904465322011-08-23T00:41:21.240+02:002011-08-23T00:41:21.240+02:00Thanks for replying to my earlier query. I actuall...Thanks for replying to my earlier query. I actually looked at prof.c and there seem to be some symbols which are defined only in ARM: "instruction_pointer". I also wrote some replacement assembly glue for x86, but it seems that __gnu_mcount_nc might not be the function call that is put in by gcc, since at no point did I see a call to profCount (which is ordinarily called by __gnu_mcount_nc). Is there a difference in the nomenclature for gnu_mcount_nc? (I remember reading about this on the gprof website, and it mentioned it could be compiler/OS dependent, _mcount, __mcount etc?) Do you have any idea about this?Jayhttps://www.blogger.com/profile/05252300016332171402noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-62646409354489212112011-08-11T21:17:11.362+02:002011-08-11T21:17:11.362+02:00@Jay: the NDK supports x86 now, so what's miss...@Jay: the NDK supports x86 now, so what's missing is a conversion of the assembly glue for the profiling calls. That's this code: https://android-ndk-profiler.googlecode.com/svn/trunk/jni/gnu_mcount.S which is ARM only.Richard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-39248105939161358752011-08-10T22:45:48.249+02:002011-08-10T22:45:48.249+02:00What would be the changes required to make this wo...What would be the changes required to make this work with an x86 android device (Google TV) ?Jayhttps://www.blogger.com/profile/05252300016332171402noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-46334544613395862922011-07-03T21:52:00.701+02:002011-07-03T21:52:00.701+02:00With version 2.0 of the library onwards you should...With version 2.0 of the library onwards you should get correct timing information when you run it on Gingerbread. Amongst the fixes is just this case: system calls with no overhead report no time. On Froyo the timing info is flaky even in 2.0, that's unfixable.Richard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-87444534686373803232011-07-01T08:01:46.846+02:002011-07-01T08:01:46.846+02:00I try to use the tool to profile my projects. It s...I try to use the tool to profile my projects. It seems that the bottle neck is the following function:<br /><br /> 28.00 11.51 11.51 4922 0.00 0.00 TaskQueue::Dequeue(Queue*, unsigned int, unsigned int*, unsigned long)<br /><br />In this function, pthread_mutex_lock, pthread_cond_wait and pthread_mutex_unlock is used to for atomic operations. <br /><br />So, if the call is pending in pthread_cond_wait, is the waiting time included in the final perf counter(because it doesn't take any CPU time)?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-9675303.post-43243787785786548832011-05-30T23:18:54.947+02:002011-05-30T23:18:54.947+02:00@santa, yep that'll do it. I should add a bett...@santa, yep that'll do it. I should add a better debug message in that case.Richard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-23687177085956681942011-05-30T12:56:56.153+02:002011-05-30T12:56:56.153+02:00corrected the misspelling of the parameter passed ...corrected the misspelling of the parameter passed to monstartup. It rocks&rolls. Thanks!!santahttps://www.blogger.com/profile/10329176320768533902noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-39356601166232557982011-05-30T11:11:53.872+02:002011-05-30T11:11:53.872+02:00Thanks again. I managed to build the thing. Yet, w...Thanks again. I managed to build the thing. Yet, when I get into running, I get <br /><br />I/PROFILING( 714): 0: No smaps found<br /><br />Any chance you got a hint? <br /><br />Thanks!!santahttps://www.blogger.com/profile/10329176320768533902noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-82735088630863396302011-05-30T11:00:56.889+02:002011-05-30T11:00:56.889+02:00Thanks! There was another source of CFLAGS in my p...Thanks! There was another source of CFLAGS in my project...santahttps://www.blogger.com/profile/10329176320768533902noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-19380131465740521232011-05-27T00:03:20.024+02:002011-05-27T00:03:20.024+02:00@santa - you need to remove the -fomit-frame-point...@santa - you need to remove the -fomit-frame-pointer declarations from the build. To do that, you have to temporarily add some lines to your Android.mk. More details https://code.google.com/p/android-ndk-profiler/wiki/UsageRichard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-47398412779083252022011-05-25T17:30:43.630+02:002011-05-25T17:30:43.630+02:00thanks for posting your work. If works, it can be ...thanks for posting your work. If works, it can be SOOO useful!.. <br /><br />I have a following issue. When trying to perform the build with -pg directive, I get <br />"arm-linux-androideabi-g++: -pg and -fomit-frame-pointer are incompatible". May be you can hint what can be done?..<br /><br />THANKS.santahttps://www.blogger.com/profile/10329176320768533902noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-33991878499121037522011-05-11T22:38:27.850+02:002011-05-11T22:38:27.850+02:00Yeah, the calling convention is that r0-r3 are fre...Yeah, the calling convention is that r0-r3 are free for the called function to reuse (i.e. profCount is free to clobber them). r4 onwards have to be preserved by the called function if it uses them.<br /><br />I haven't looked at what armeabi-v7a spits out - I imagine that when you compile with armeabi-v7a and thumb2 in particular it is using a different calling mechanism to __gnu_mcount_nc. It hasn't been a priority for me to really investigate it though.<br /><br />My testing is done on a multi-threaded app. I guess that there's something in 2.3 on hardware that's screwing it up, because even that works fine with regular armeabi on emulators.<br /><br />The article you linked to is for the real gprof and the Linux kernel hooks it uses, which my own hack here doesn't use. I keep track of apparent time spent on each PC in a separate thread. As long as __gnu_mcount_nc is called, it should be registering time spent in the callee.<br /><br />If you get the chance, see the other post I made about the native activity example.Richard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-39652287717184251102011-05-11T19:14:13.950+02:002011-05-11T19:14:13.950+02:00Thanks for posting the armeabi-v7a build; sadly, w...Thanks for posting the armeabi-v7a build; sadly, when compiling in armeabi-v7a mode, it doesn't appear to work any better than the armeabi build. I don't think it's even getting to monstartup() before it hangs.<br /><br />As you said earlier, it doesn't make sense that armeabi-v7a builds would need a different andprof library. The calling convention is unchanged.<br /><br />Do you preserve r2 and r3 because profCount() clobbers them? __gnu_mcount_nc() doesn't otherwise touch them. Looking at the disassembly of profCount(), it isn't obvious to me that profCount is correctly preserving r4, r5, and r6. <br /><br />FWIW, these are the TARGET_* flags I have in my Android.mk:<br /><br />TARGET_CFLAGS := $(filter-out -ffunction-sections,$(TARGET_CFLAGS))<br />TARGET_thumb_release_CFLAGS := $(filter-out -fomit-frame-pointer,$(TARGET_thumb_release_CFLAGS))<br />TARGET_arm_release_CFLAGS := $(filter-out -fomit-frame-pointer,$(TARGET_arm_release_CFLAGS))<br /><br />These flags seem to make both thumb and arm objects work.<br /><br />Finally, I also get "no time accumulated" in my profiling results. This happens both with a JNI-loaded library and with a fully native activity. I'm guessing the problem is caused by the multi-threaded nature of Android apps, even native ones. See http://sam.zoy.org/writings/programming/gprof.html for more details.LightStrukhttps://www.blogger.com/profile/14599692920430431406noreply@blogger.comtag:blogger.com,1999:blog-9675303.post-38516031277654651162011-05-03T20:54:47.754+02:002011-05-03T20:54:47.754+02:00Hmm, actually, seems there isn't actually a TA...Hmm, actually, seems there isn't actually a TARGET_CXXFLAGS, so if you follow http://code.google.com/p/android-ndk-profiler/wiki/Usage it should Just Work.Richard Quirkhttps://www.blogger.com/profile/16290285494071462742noreply@blogger.com