PMTIMESPECNOW(3)
PMTIMESPECNOW π (section 3 of the manual, bestie)
okay so listen, this is the PMTIMESPECNOW(3) page from the Library Functions Manual, and it's literally a whole glow-up for handling time when your time is stored as a struct timespec. ten little helper routines. all of them iconic. let's go π¦
β¨ NAME β¨
pmtimespecNow, pmtimespecInc, pmtimespecDec, pmtimespecAdd, pmtimespecSub, pmtimespecToReal, pmtimespecFromReal, pmtimespecTotimeval, pmtimespecPrint, pmtimespecPrintInterval β helper routines for time stored as a struct timespec π
β¨ C SYNOPSIS β¨
like, the vibe is:
#include <pcp/pmapi.h>
void pmtimespecNow(struct timespec *tp);
void pmtimespecInc(struct timespec *ap, const struct timespec *bp);
void pmtimespecDec(struct timespec *ap, const struct timespec *bp);
double pmtimespecAdd(const struct timespec *ap,
const struct timespec *bp);
double pmtimespecSub(const struct timespec *ap,
const struct timespec *bp);
double pmtimespecToReal(const struct timespec *tp);
void pmtimespecFromReal(double secs, struct timespec *tp);
void pmtimespecTotimeval(struct timespec *tsp, struct timeval *tvp);
void pmtimespecPrint(FILE *f, const struct timespec *tp);
void pmtimespecPrintInterval(FILE *f, const struct timespec *tp);
and don't forget to link it, bestie:
cc ... -lpcp
β¨ DESCRIPTION β¨
okay so, function by function, no skipping π
pmtimespecNow is the platform-independent queen π β she returns the current system time since the Epoch, and drops it in tp.
pmtimespecInc adds the time in ap to the time in bp and stores the result in ap. and pmtimespecDec? she's the opposite energy β she subtracts the time in bp from the time in ap and stores the result in ap. π
pmtimespecAdd (and pmtimespecSub) add (and subtract) times and hand you back the result as a double value. and here's the thing β the time in the ap argument is not changed. untouched. no notes. β¨
pmtimespecToReal converts the time in tp into an equivalent double value. pmtimespecFromReal is the reverse glow-up, taking the time in secs and returning the equivalent time in tp. π¦
pmtimespecTotimeval converts the struct timespec tsp into an equivalent struct timeval tvp β but lowkey, modulo nanosecond to microsecond truncation. that's the trade, bestie. π
π¨ okay so precision tea: forpmtimespecAdd,pmtimespecSub,pmtimespecToRealandpmtimespecFromRealthere is an issue of numerical precision. if thedoubleresult or operand has more than 6 decimal digits of precision in the seconds part of the value, then the fractional value is converted to microseconds before arithmetic computations, so the nanoseconds field is only accurate to 6 decimal digits in this case. not me being dramatic, that's literally the manpage. π
pmtimespecPrint prints the timestamp from tp on the stream f in the local time (as returned by pmLocaltime(3)) in the format:
HH:MM:SS.XXXXXXXXX
pmtimespecPrintInterval prints the interval from tp on the stream f in a minimalist format:
[[HHh]MMm]SS[.XXXXXXXXX]s
where the hours, minutes and nanoseconds are only reported if they are non-zero, and any trailing zeroes in the nanoseconds are omitted. fr fr, watch this: if tp->tv_sec was 75 and tp->tv_nsec was 51000000 then the output would be:
1h15.51s
ate. no crumbs. π
πΈ NOTES πΈ
for variants of these interfaces using microsecond precision and the timeval structure, go read pmtimevalNow(3). iykyk β¨
π COMPATIBILITY π
prior to PCP 7.0 the routine pmtimespecPrint was called pmPrintHighResStamp. to support PMAPI transition, the old routine can still be used if applications are recompiled with -DPMAPI_VERSION=2. π
π and heads up: pmPrintHighResStamp is now deprecated and compile-time support for this routine name will be removed in a future release. so like, plan accordingly, bestie.
π«Ά SEE ALSO π«Ά
PMAPI(3), pmLocaltime(3) and pmtimevalNow(3). go read them too, they're all part of the lore π
and that's the whole page, bestie!! this was brought to you by Performance Co-Pilot (PCP) β she's the source, she's the version, she's everything β and this was the PMTIMESPECNOW(3) manual page. mwah, stay precise, stay truncated-modulo-microseconds π
β¨π
π¦ where this page comes from
- arch rolling: pcp 7.2.2-2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0
- centos-stream 10: pcp-doc 7.1.5-6.el10 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.0.1-1.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.2.1-1.fc43
- fedora 43: pcp-doc 7.2.2-1.fc43
- fedora 43: pcp-doc 7.2.2-2.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.1.0-6.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.2.1-1.fc44
- fedora 44: pcp-doc 7.2.2-1.fc44
- fedora 44: pcp-doc 7.2.2-2.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- ubuntu resolute: libpcp4-dev 7.1.1-1
- ubuntu stonking: libpcp4-dev 7.2.1-2build1
- Copyright (c) 2022 Red Hat. All Rights Reserved
- Copyright (c) 2017 Ken McDonell. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms