-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for strftime() builtin #1387
Conversation
473f268
to
cd8b28f
Compare
What is this?
Does this deprecate/break the old behavior? I don't see a compelling reason why we should. It's in ~10k printed copies of the BPF book that we cannot update, so no. I also saw this (there's no reference docs, so it's not clear what you're doing):
I called it time() because it was not strftime(). This sounds like you're turning it into strftime(). If you want strftime(), add a new thing called strftime() and leave time() alone. |
cd8b28f
to
5d7c690
Compare
strftime()
builtin
strftime()
builtin5d7c690
to
ed4a421
Compare
Why create a new printf() format character? Why not "%s"? See printf.cpp: we convert a lot of types to String when printed.
|
@brendangregg The reason we hesitated to use "%s" was that we were afraid it would send a message to user that Using "%ts" doesn't have that issue. But the problem with it is that creating a new specifier for the old friend I think the async nature of |
A) If it's called strftime() then people will use it with %s. (Where did %ts come from anyway? POSIX? I'm not familiar with it.) B) I don't really see the use case other than with printf(). C) That ship has sailed anyway: we have things like kstack() and username() that use %s, but you can't use with strcmp(). It's a tracing language, not an application language. It only needs to support enough for common case tools -- anything more complex can be deferred to BCC. The existence of BCC allows us to keep bpftrace simple. |
86fb9ff
to
ea2bb2d
Compare
1bb53e9
to
c29983b
Compare
Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small things but looks good overal :)
src/ast/irbuilderbpf.cpp
Outdated
@@ -273,7 +273,7 @@ Value *IRBuilderBPF::CreateMapLookupElem(Value *ctx, | |||
CreateCondBr(condition, lookup_success_block, lookup_failure_block); | |||
|
|||
SetInsertPoint(lookup_success_block); | |||
if (type.IsAggregate()) | |||
if (type.IsAggregate() || type.IsTimestampTy()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should either put timestamp in IsAggregate or find a new name to describe them both (and all future async events which should be handled like this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd agree. I think IsCompound
could be a nice name here since C++ seems to use similar term: std::is_compound
and it includes array, tuple, class and so on (Type::timestamp
seems like a class type to me). Btw there could be some other options like IsCollectionTy
, IsComposite
and IsCombined
though I'm not sure if there are as good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with @danobi and thought that it might be good to add a helper function instead.
@@ -1673,6 +1686,52 @@ std::string BPFtrace::resolve_uid(uintptr_t addr) const | |||
return username; | |||
} | |||
|
|||
std::string BPFtrace::resolve_timestamp(uint32_t strftime_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this currently gives us 1s accuracy right? I was hoping for to get closer to 100us but that should probably go in a follow up ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. If we want someting better, we may have to choose something more accurate than btime. clock_gettime(CLOCK_REALTIME)
might help though I'm not so sure if that's what we want; and if we use it, it wouldn't make sense to use nsecs
as the second argument of strftime
since it means 'nsecs since boot time'.
e9f83b2
to
84adc3d
Compare
8d2b3d1
to
5800d4b
Compare
5800d4b
to
5bb7d3e
Compare
This introduces a new builtin function `strftime`. This function makes it possible to print the current time with `printf`: ``` bpftrace -e 'i:s:1 { printf("%s\n", strftime("%H:%M:%S", nsecs)); }' ``` Although `time` can print current time on its own, printing timestamp with `printf` can produce more concise and more readable output. Resolves bpftrace#1337 .
5bb7d3e
to
5fff47e
Compare
This PR introduces a new builtin function
strftime
. This function makes it possible to print the current time withprintf
:Although
time
can print current time on its own, printing timestamp withprintf
can produce more concise and more readable output. Resolves #1337 .Checklist
docs/reference_guide.md
CHANGELOG.md