PMPARSEINTERVAL(3)

πŸ“¦
version 7.2.2 Β· 5 versions
, in arch rolling, centos-stream 10, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

✨ PMPARSEINTERVAL ✨

okay bestie, welcome to pmParseInterval πŸ’– this one lives in the PMPARSEINTERVAL(3) corner of the Library Functions Manual, and honestly? she's giving "glow-up from string to struct" and we're obsessed.

🌸 NAME 🌸

pmParseInterval β€” literally converts an interval string into a binary time structure. that's it, that's the job, no cap πŸ’…


πŸ’œ C SYNOPSIS πŸ’œ

#include <pcp/pmapi.h>

int pmParseInterval(const char *string, struct timespec *rslt,
                    char **errmsg);

cc ... -lpcp

yeah so you include <pcp/pmapi.h>, you link with -lpcp, and you get a function with three args and a whole lot of main character energy πŸ”₯


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: pmParseInterval takes the argument string β€” which is describing an interval of time β€” parses it, and fills in the tv_sec and tv_nsec components of the rslt structure so they represent that interval. nanosecond precision, bestie, we do NOT round here ✨

where does this string usually come from? most commonly it's the argument that follows a -t command line option to a PCP application. and the syntax of that string? it's fully described in PCPIntro(1) β€” go read her, she ate πŸ’–


πŸŽ€ DIAGNOSTICS πŸŽ€

okay so the results are very much a vibe check:

  • if the parsing is successful, pmParseInterval returns 0, and errmsg is undefined. (yes, undefined. don't look at it. it's not for you πŸ™ˆ)
  • 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.

that error message is terminated with a newline, and it includes the text of the input string along with an indicator of the position at which the error was detected, like this:

4minutes 30mumble
          ^ -- unexpected value
⚠️ important bestie: in the case of an error, the caller is responsible for calling free(3) to release the space allocated for errmsg. yes, YOU. it's your job. don't leave her hanging 😭

🌈 COMPATIBILITY 🌈

history lesson, come sit with me 🫢

prior to PCP 7.0, the rslt argument was a struct timeval. so if you're dealing with old code, here's the tea: to support PMAPI transition, the old interface and semantics can be used if applications are recompiled with -DPMAPI_VERSION=2.

and for a time in PCP 6.x, there was a routine with the same semantics as the current pmParseInterval called pmParseHighResInterval. however β€” and I need you to hear this β€” this is now deprecated, and compile-time support for pmParseHighResInterval will be removed in a future release. so like, don't get attached πŸ’€


πŸ‘‘ SEE ALSO πŸ‘‘

PCPIntro(1), free(3), PMAPI(3) and pmParseTimeWindow(3) β€” go give them a follow, they're all part of the friend group ✨


that's the whole page, bestie 🌟 she's brought to you by Performance Co-Pilot, from PCP, and she's iconic, periodt. mwah πŸ’…πŸ’–πŸ¦‹

πŸ“¦ where this page comes from