PMUNITSSTR(3)
π PMUNITSSTR(3) β from the Library Functions Manual, bestie π
okay so. this is a page from the Library Functions Manual, and it's about two lil functions β pmUnitsStr and pmUnitsStr_r β that take a performance metric's units and turn them into a string you can actually read. it's giving translator. it's giving glow-up for numbers. π¦
β¨ NAME β¨
pmUnitsStr, pmUnitsStr_r β convert a performance metric's units into a string
β¨ C SYNOPSIS β¨
#include <pcp/pmapi.h>
const char *pmUnitsStr(const pmUnits *pu);
char *pmUnitsStr_r(const pmUnits *pu, char *buf, int buflen);
cc ... -lpcp
link it with -lpcp and you're so good. π«Ά
β¨ DESCRIPTION β¨
so the way a performance metric's dimensionality and scale get encoded? it uses a pmUnits structure β go check pmLookupDesc(3) for the whole lore. π
pmUnitsStr is here to help with labeling graphs and tables, or for error messages, and what it does is take a dimension + scale spec as per *pu and hand you back the corresponding text string. iconic behavior.
pmUnitsStr_r does the same exact thing, except it stores the result in a buffer you supply β buf, of length buflen β and that buffer should have room for at least 60 bytes. no cap.
β οΈ ifbuflenis less than 60, thenpmUnitsStr_rreturnsNULLandbufis not changed. it just β¨refusesβ¨, respectfully.
for example, {1, -2, 0, PM_SPACE_MBYTE, PM_TIME_SEC, 0} as the value of *pu gives the result string:
Mbyte / sec^2
the string value result from pmUnitsStr is held in a single static buffer, so the returned value is only valid until the next call to pmUnitsStr. π so don't go holding onto it like it's gonna stay. it will not stay. it's a one-call-at-a-time kind of situation.
and if the count'' dimension is non-zero, and the count'' scale is not zero, then the text string will include a decimal scaling factor β like:
count x 10^6
π
special case alert π¨ β if all components of the dimension are zero, then the ``count'' scale is used to produce the text. if this scale is zero, the result is an empty string. otherwise the result is of the form:
x1 0^2
periodt.
β¨ NOTES β¨
pmUnitsStr returns a pointer to a static buffer and hence is not thread-safe. π multi-threaded applications should use pmUnitsStr_r instead β that's literally why it exists, bestie.
β¨ SEE ALSO β¨
PMAPI(3), pmAtomStr(3), pmConvScale(3), pmExtractValue(3), pmLookupDesc(3), pmPrintValue(3), pmIDStr(3), pmInDomStr(3), pmTypeStr(3), pmSemStr(3) and pmUnitsStr(3).
and that's the whole page, bestie!! π this one came out of the Performance Co-Pilot crew, tagged PCP, and it's page PMUNITSSTR(3) β slay, go format some units, i'm obsessed πβ¨πΈ
π¦ 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) 2000-2004 Silicon Graphics, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms