Open honggyukim opened 6 years ago
There's nothing to modify uftrace
code itself but we have to distribute the above uftrace
header file during installation. Then uftrace users can just include it when it's needed.
Another goal is to provide multiple arguments using variadic template. I've tested for a while but it doesn't capture any arguments with my current implementation.
template <typename ...Args>
__attribute__((optimize(0)))
void uftrace_print(Args&&... args)
{
}
int main()
{
int a = 10;
uftrace_print(a, &a, 'A', "Hi");
}
Variadic template is only supported from C++11.
$ g++ -pg -g -std=c++11 test.cpp
But the replay output shows nothing.
$ uftrace --auto-args a.out
# DURATION TID FUNCTION
2.040 us [113254] | __monstartup();
1.014 us [113254] | __cxa_atexit();
[113254] | main() {
0.237 us [113254] | uftrace_print();
1.453 us [113254] | } = 0; /* main */
Generally I don't want to change user's program and there's similar thing like SDT marker so I'm not sure it's worth doing it in uftrace. If user can change the program he or she can add a dummy function without this, right? Also there seem no way to handle C programs..
Generally I don't want to change user's program
I agree. uftrace must not require user to modify their source code, but sometimes, it's needed in my experience.
and there's similar thing like SDT marker so I'm not sure it's worth doing it in uftrace.
There are something that I'm not comfortable on SDT approach.
systemtap-std-dev
on ubuntuSTAP_PROBE(uftrace, event)
looks more complicated than uftrace_print(value)
to general users-E uftrace:event
option to uftrace.If user can change the program he or she can add a dummy function without this, right?
Right. User can add their dummy function for that but it requires additional attributes to stay the function in binary when optimized. As I wrote it above, the attributes are different between gcc
and clang
and they might be complicated to general users. Moreover, making a dummy function for string requires some extra code to avoid optimizing the unused string as well.
Also there seem no way to handle C programs..
Right. This approach depends on C++ template so don't handle C programs yet.
I just made a prototype and don't think this is the only solution. But just wanted to make it better and simpler to general users. Thanks for your feedback!
I've implemented it in #636 and it works both C
and C++
with the same function name uftrace_print
. Please take a look at it. Thanks!
Introduction
uftrace is able to capture function arguments and return values and that is the core feature.
But sometimes, it's also necessary to see some internal variables or even user may want to put a marker to distinguish the point from a long sequence of function calls.
ftrace
already has that feature and providingftrace_printk
- https://lwn.net/Articles/292371/I've designed a prototype to provide similar way to print or capture some variables inside function. The design idea is to provide a simple function that does nothing and just accept a single parameter.
The basic usage is as follows:
uftrace
header file.uftrace_print()
function with a single argument that can be recorded$ uftrace --auto-args a.out
DURATION TID FUNCTION
2.130 us [112169] | monstartup(); 1.257 us [112169] | cxa_atexit(); [112169] | main() { 1.437 us [112169] | uftrace_print(100); 314.116 us [112169] | uftrace_print("Hello"); 317.776 us [112169] | } = 0; / main /
$ g++ -pg -g test.cpp
$ ./a.out (... does nothing ...)
T2. enum types
T3. string types
Implementation
Here is the full implementation of
uftrace
header file.As shown above,
uftrace_print()
function does nothing but accepts a single argument. It uses template to distinguish each type but provides one more prototype -void uftrace_print(const char* s)
to avoid compiler optimization.It contains some verbose attribute and macros but it's to handle the difference between
gcc
andclang
.Please let me know any feedback or some ideas that I can improve it. Thanks!