-
-
Notifications
You must be signed in to change notification settings - Fork 441
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
Show year as start time for processes older than a year #1116
Conversation
That warning says, that when calling On the actual change: I see the problem you're addressing but I'm not sure the current suggested patch is a sensible way to go forward with it. |
Just a note: I tried this workaround in Compiler Explorer but it results in a slightly larger code (three assembly if (this->starttime_ctime > now - 86400) {
strftime(this->starttime_show, sizeof(this->starttime_show) - 1, "%R ", &date);
} else if (this->starttime_ctime > now - 364*86400) {
strftime(this->starttime_show, sizeof(this->starttime_show) - 1, "%b%d ", &date);
} else {
strftime(this->starttime_show, sizeof(this->starttime_show) - 1, " %Y ", &date);
} |
Suggestion to please the compiler: void Process_fillStarttimeBuffer(Process* this) {
struct tm date;
time_t now = time(NULL);
(void) localtime_r(&this->starttime_ctime, &date);
strftime(this->starttime_show,
sizeof(this->starttime_show) - 1,
(this->starttime_ctime > now - 86400) ? "%R " : (this->starttime_ctime > now - 364*86400) ? "%b%d " : " %Y ",
&date);
} |
@natoscott Can you take a look at this patch re PCP time archive support? Not sure if |
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.
Even the the code might be a bit larger (we are not constrained on this), I'd prefer the fully static format string variant here. And be it to avoid accidentally providing the wrong number of arguments and thus causing information leakage bugs …
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 to avoid confusion regarding the year display the switch-over should be similar to what is used for things like ls
, where files older than like 6 months are marked by the year, instead of a precise date/time.
Otherwise LGTM.
Sorry, I missed this question earlier. We don't have archive support yet in pcp-htop but yes, this sort of thing would be problematic from that POV. In general calling time() for every process we find is not ideal anyway - it would be more efficient to use the time_t from the timestamp we take at each time step. Nowadays this lives in the 'realtime.tv_sec' field of struct Machine and using this has the added benefit that it will do the right thing with PCP archives when we get to that. |
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.
As per inline comment, it'd be slightly more efficient to use the timestamp we already took for this sample. Should be a relatively straight forward change too.
Otherwise, LGTM.
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.
Why are you moving the call to Process_fillStarttimeBuffer
relative to the ProcessList_add
call everywhere?
|
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.
LGTM.
Old format is month+day which can be ambiguous.
Not sure what to do with this compilation warning: