Discussion:
Can I use 'ATrace_beginSection' and 'ATrace_endSection' API for logging systrace on C++?
Neo
2016-06-22 07:31:07 UTC
Permalink
Can I use 'ATrace_beginSection' and 'ATrace_endSection' API for logging
systrace on C++?

I found "trace.h" header file from ndk (android-23 over).
So, include that header file and tried to call 'ATrace_beginSection' API.
But I failed.

I got an error message " undefined reference to 'ATrace_beginSection' "

Is there a library which I have to link ?

Help me please. Thanks..
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7cc219de-7389-417f-903c-ba11c1f77009%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Don Turner' via android-ndk
2016-07-02 06:50:55 UTC
Permalink
You can but you'll need to dynamically load the symbols at runtime as they
are not exposed in libandroid.so (hence the undefined reference error
you're getting). Code example:

void *(*ATrace_beginSection) (const char* sectionName);
void *(*ATrace_endSection) (void);
void *(*ATrace_isEnabled) (void);

typedef void *(*fp_ATrace_beginSection) (const char* sectionName);
typedef void *(*fp_ATrace_endSection) (void);
typedef void *(*fp_ATrace_isEnabled) (void);


// Native Trace API is supported in API level 23
void *lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL);
if (lib != NULL) {
//LOGI("Run with Trace Native API.");
// Retrieve function pointers from shared object.
ATrace_beginSection =
reinterpret_cast<fp_ATrace_beginSection >(
dlsym(lib, "ATrace_beginSection"));
ATrace_endSection =
reinterpret_cast<fp_ATrace_endSection >(
dlsym(lib, "ATrace_endSection"));
ATrace_isEnabled =
reinterpret_cast<fp_ATrace_isEnabled >(
dlsym(lib, "ATrace_isEnabled"));
}
Post by Neo
Can I use 'ATrace_beginSection' and 'ATrace_endSection' API for logging
systrace on C++?
I found "trace.h" header file from ndk (android-23 over).
So, include that header file and tried to call 'ATrace_beginSection' API.
But I failed.
I got an error message " undefined reference to 'ATrace_beginSection' "
Is there a library which I have to link ?
Help me please. Thanks..
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/a3ba9150-d697-40dd-a261-0f2d9964f1d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kenneth Geisshirt
2016-07-02 14:43:01 UTC
Permalink
Please remember that using non-NDK libraries and functions will not be
allowed soon. So it might be a good idea to guard it with a macro and only
use it internally.

Den lÞr. 2. jul. 2016 08.51 skrev 'Don Turner' via android-ndk <
Post by 'Don Turner' via android-ndk
You can but you'll need to dynamically load the symbols at runtime as they
are not exposed in libandroid.so (hence the undefined reference error
void *(*ATrace_beginSection) (const char* sectionName);
void *(*ATrace_endSection) (void);
void *(*ATrace_isEnabled) (void);
typedef void *(*fp_ATrace_beginSection) (const char* sectionName);
typedef void *(*fp_ATrace_endSection) (void);
typedef void *(*fp_ATrace_isEnabled) (void);
// Native Trace API is supported in API level 23
void *lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL);
if (lib != NULL) {
//LOGI("Run with Trace Native API.");
// Retrieve function pointers from shared object.
ATrace_beginSection =
reinterpret_cast<fp_ATrace_beginSection >(
dlsym(lib, "ATrace_beginSection"));
ATrace_endSection =
reinterpret_cast<fp_ATrace_endSection >(
dlsym(lib, "ATrace_endSection"));
ATrace_isEnabled =
reinterpret_cast<fp_ATrace_isEnabled >(
dlsym(lib, "ATrace_isEnabled"));
}
Post by Neo
Can I use 'ATrace_beginSection' and 'ATrace_endSection' API for logging
systrace on C++?
I found "trace.h" header file from ndk (android-23 over).
So, include that header file and tried to call 'ATrace_beginSection' API.
But I failed.
I got an error message " undefined reference to 'ATrace_beginSection' "
Is there a library which I have to link ?
Help me please. Thanks..
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/a3ba9150-d697-40dd-a261-0f2d9964f1d2%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/a3ba9150-d697-40dd-a261-0f2d9964f1d2%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAFLzvuo1Pb-UjGZXW%3D8UTCBvNmE8K7ConF-qVbbWx3f_FouyxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
'Dan Albert' via android-ndk
2016-07-06 21:23:59 UTC
Permalink
Post by Kenneth Geisshirt
Please remember that using non-NDK libraries and functions will not be
allowed soon.
Actually safe in this case because this was *supposed* to be an NDK
library. We screwed up and the change was only half done (header is there,
library changes were missing)​. I actually fixed this a few hours ago, but
that won't help you much until r13 is available. The NDK is wrong here, but
the linker on the platform knows better. Still good advice in general
though :)

The dlopen/dlsym approach Don Turner suggested will work fine until then.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAFVaGht%3DTspPPwEDJtAEmZu0G%2BtOge7YPoW5YrSA8OigXCKfPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
sriram nagaswamy
2016-10-18 14:03:50 UTC
Permalink
Is this working in r13? with r13 NDK, I'm getting the same undefined
message.
Post by Kenneth Geisshirt
Please remember that using non-NDK libraries and functions will not be
Post by Kenneth Geisshirt
allowed soon.
Actually safe in this case because this was *supposed* to be an NDK
library. We screwed up and the change was only half done (header is there,
library changes were missing)​. I actually fixed this a few hours ago, but
that won't help you much until r13 is available. The NDK is wrong here, but
the linker on the platform knows better. Still good advice in general
though :)
The dlopen/dlsym approach Don Turner suggested will work fine until then.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/b93bf2fd-de78-4352-a1df-077d3b25402f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yury Habets
2018-06-28 09:44:50 UTC
Permalink
Yes, you just need to link with android (-landroid).
Post by sriram nagaswamy
Is this working in r13? with r13 NDK, I'm getting the same undefined
message.
Post by Kenneth Geisshirt
Please remember that using non-NDK libraries and functions will not be
Post by Kenneth Geisshirt
allowed soon.
Actually safe in this case because this was *supposed* to be an NDK
library. We screwed up and the change was only half done (header is there,
library changes were missing)​. I actually fixed this a few hours ago, but
that won't help you much until r13 is available. The NDK is wrong here, but
the linker on the platform knows better. Still good advice in general
though :)
The dlopen/dlsym approach Don Turner suggested will work fine until then.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/59a12492-8dc1-44f1-9d26-f64772341291%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yury Habets
2018-06-28 10:11:31 UTC
Permalink
ATrace_isEnabled has a return type of bool. :)
Post by 'Don Turner' via android-ndk
You can but you'll need to dynamically load the symbols at runtime as they
are not exposed in libandroid.so (hence the undefined reference error
void *(*ATrace_beginSection) (const char* sectionName);
void *(*ATrace_endSection) (void);
void *(*ATrace_isEnabled) (void);
typedef void *(*fp_ATrace_beginSection) (const char* sectionName);
typedef void *(*fp_ATrace_endSection) (void);
typedef void *(*fp_ATrace_isEnabled) (void);
// Native Trace API is supported in API level 23
void *lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL);
if (lib != NULL) {
//LOGI("Run with Trace Native API.");
// Retrieve function pointers from shared object.
ATrace_beginSection =
reinterpret_cast<fp_ATrace_beginSection >(
dlsym(lib, "ATrace_beginSection"));
ATrace_endSection =
reinterpret_cast<fp_ATrace_endSection >(
dlsym(lib, "ATrace_endSection"));
ATrace_isEnabled =
reinterpret_cast<fp_ATrace_isEnabled >(
dlsym(lib, "ATrace_isEnabled"));
}
Post by Neo
Can I use 'ATrace_beginSection' and 'ATrace_endSection' API for logging
systrace on C++?
I found "trace.h" header file from ndk (android-23 over).
So, include that header file and tried to call 'ATrace_beginSection' API.
But I failed.
I got an error message " undefined reference to 'ATrace_beginSection' "
Is there a library which I have to link ?
Help me please. Thanks..
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/baddff43-6404-4892-b6fd-a1613cd286a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...