PMPARSEINTERVAL(3)

πŸ“¦
version 6.3.8 Β· 3 versions
, in centos-stream 9, debian trixie, ubuntu questing

πŸ’– PMPARSEINTERVAL(3) β€” Library Functions Manual πŸ’–

okay bestie, welcome to the interval-parsing corner of the PCP universe ✨ this is pmParseInterval and its glow-up cousin pmParseHighResInterval, and they're literally here to turn your cute little human-readable time string into an actual binary time structure. no cap. πŸ•πŸ’…


🌸 NAME 🌸

pmParseInterval, pmParseHighResInterval β€” convert interval string to binary time structure πŸ¦‹


✨ C SYNOPSIS ✨

so first, you gotta pull in the header, obviously:

#include <pcp/pmapi.h>

and then the two icons themselves:

int pmParseInterval(const char *string, struct timeval *urslt,
        char **errmsg);
int pmParseHighResInterval(const char *string, struct timespec *nrslt,
        char **errmsg);

and when you compile, don't forget your girl:

cc ... -lpcp

πŸ’œ DESCRIPTION πŸ’œ

okay so pmParseInterval β€” she takes the argument string, which is specifying an interval of time, parses it, and fills in the tv_sec and tv_usec components of the urslt structure so that it represents that interval. that's microsecond precision, bestie. so precise. πŸŽ€

and then pmParseHighResInterval is the same vibe but leveled up ✨ she parses the argument string and fills in the tv_sec and tv_nsec components of the nrslt structure to represent that interval. nanosecond precision. she ate and left no crumbs fr fr πŸ‘‘

now, where does this string usually come from? most commonly it's the argument following a -t command line option to a PCP application πŸ’« and the syntax β€” the whole grammar of it β€” is fully described in PCPIntro(1). so if you're like "wait what can I even put in here", go read that one, iykyk πŸ“–


😭 DIAGNOSTICS 😭

so here's the vibe check on what these functions hand back:

  • if the parsing is successful, pmParseInterval returns 0, and errmsg is undefined. iconic, no notes πŸ’–
  • if the given string does not conform to the required syntax, pmParseInterval returns -1 and hands you a dynamically allocated error message string in errmsg. πŸ“¬

and that error message? she's terminated with a newline, and she includes the text of the input string along with an indicator of the position at which the error was detected. like, she points at the problem. so helpful. for example:

4minutes 30mumble
          ^ -- unexpected value

see how she's pointing right at the 30mumble? that caret is doing the lord's work πŸ™

⚠️ important bestie, listen up: in the case of an error, the caller is responsible for calling free(3) to release the space allocated for errmsg. don't leave her hanging, don't leak that memory. free her. periodt. πŸ’€

🫢 SEE ALSO 🫢

PCPIntro(1), free(3), PMAPI(3) and pmParseTimeWindow(3) 🌈


that's the whole page, and you absolutely understood all of it, i'm so proud πŸ₯Ή

this masterpiece comes to you from Performance Co-Pilot β€” PCP β€” and it lives at PMPARSEINTERVAL(3). mwah, go parse something πŸ’…πŸ’–

πŸ“¦ where this page comes from