PMPARSEUNITSSTR(3)
π pmParseUnitsStr β the Library Functions Manual glow-up π
okay bestie, so this one lives in the PCP Library Functions Manual, and it's literally the function that reads units for you. no cap.
β¨ NAME β¨
pmParseUnitsStr β parse units specification π¦
πΈ C SYNOPSIS πΈ
#include <pcp/pmapi.h>
int pmParseUnitsStr(const char *string, struct pmUnits *out,
double *outMult, char **errMsg);
cc ... -lpcp
π DESCRIPTION π
So pmParseUnitsStr is the girl whose whole job is to encapsulate the interpretation of a units (dimension and scale) specification inside command line switches, for all the PCP client tools to use. she's the translator, the vibe-checker, the main character of unit parsing π
You call her with the unit/scale spec sitting in string. That spec takes the general form that pmUnitsStr(3) produces. briefly: the format lets you have a /-separated divisor and dividend, and each one lists space-separated dimensions/scales along the space, time, and count axes. iconic honestly.
and then there's a few extra possibilities that are lowkey the best part:
- First β multiple equivalent sets of keywords are accepted for the time and space dimensions, and it's insensitive to case. so for example
"microseconds","microsecond","microsec","us"are all considered synonymous. same energy for"kilobytes","KB","KiB","kiloByte", and so on. pick your fighter, they all slay π - Second β units may be offered in any order, e.g.
ms kb count x 10^3orcount x 10^3 kb ms. the way that she doesn't care about your ordering? obsessed. but β and this is the catch β they may not be repeated within the denominator or within the numerator. each scale/unit keyword may be immediately followed by positive or negative exponents, e.g.^-4. π«Ά - Third β numerical scaling factors may be supplied. these get factored together with implicit scale conversions into the final
outMultresult. β¨
heads up bestie: theoutandoutMultvalues must both be allocated before callingpmParseUnitsStr(3). no allocating mid-call, that's not the vibe.
if the conversion is successful, pmParseUnitsStr returns 0, and fills in out and outMult with the unit/scales defined by the input parameter. π
if the argument strings could not be parsed, she returns a negative status code. it's giving "not today." π
π₯ EXAMPLES π₯
here's the receipts, bestie β string goes in, out and outMult come out:
2 countβoutis{0,1,0,0,0,0},outMultis0.5count / 7.5 nanosecondβoutis{0,1,-1,0,0,0},outMultis7.510 kilobytes / 2.5e2 count x 10^3βoutis{1,-1,0,1,3,0},outMultis25millisecond / second^2βoutis{0,0,-1,0,0,3},outMultis1000mib/sβoutis{1,0,-1,2,0,3},outMultis1
π BUGS π
okay so for backward compatibility, this interface interprets several traditional computer science interpretations of space units incorrectly according to the International System of Units (SI) standard. it's giving β¨chaosβ¨ and not the fun kind. π
the accepted unit string β in either singular or plural form β and the pmParseUnitsStr interpretation for each are:
megabyte(is really mebibyte)gigabyte(is really gibibyte)terabyte(is really tebibyte)petabyte(is really pebibyte)exabyte(is really exbibyte)zettabyte(is really zebibyte)yottabyte(is really yobibyte)
so yeah. she's lying to you about bytes. knowingly. for legacy reasons. π
β RETURN VALUE β
- A zero status indicates success. π
- A negative status indicates an error β in which case the
errMsgpointer will contain a textual error message, which the caller should laterfree(3). don't forget the free bestie, that's a leak otherwise π
π¦ SEE ALSO π¦
PMAPI(3), pmUnitsStr(3), pmConvScale(3), and pmLookupDesc(3). go read them, they're all part of the same friend group π«Ά
and that's the whole page, babe β¨ this one's from Performance Co-Pilot, aka PCP, and it's the PMPARSEUNITSSTR(3) page β so go parse some units, allocate your out and outMult first, and free your errMsg like the responsible icon you are. periodt. π
π¦ 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) 2014,2018 Red Hat
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms