2 * Copyright (C) 2012-2017 Red Hat.
3 * Copyright (C) 2009-2012 Michael T. Werner
5 * This file is part of the "pcp" module, the python interfaces for the
6 * Performance Co-Pilot toolkit.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 /**************************************************************************\
21 ** This C extension module mainly serves the purpose of loading constants **
22 ** from PCP headers into the module dictionary. The PMAPI functions and **
23 ** data structures are wrapped in pmapi.py and friends, using ctypes. **
25 \**************************************************************************/
28 #include <pcp/pmapi.h>
31 #if PY_MAJOR_VERSION >= 3
32 #define MOD_ERROR_VAL NULL
33 #define MOD_SUCCESS_VAL(val) val
34 #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
35 #define MOD_DEF(ob, name, doc, methods) \
36 static struct PyModuleDef moduledef = { \
37 PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
38 ob = PyModule_Create(&moduledef);
41 #define MOD_SUCCESS_VAL(val)
42 #define MOD_INIT(name) void init##name(void)
43 #define MOD_DEF(ob, name, doc, methods) \
44 ob = Py_InitModule3(name, methods, doc);
47 static pmOptions options
;
48 static int longOptionsCount
;
49 static PyObject
*optionCallback
;
50 static PyObject
*overridesCallback
;
53 dict_add_unsigned(PyObject
*dict
, char *symbol
, unsigned long value
)
55 PyObject
*pyvalue
= PyLong_FromUnsignedLong(value
);
56 PyDict_SetItemString(dict
, symbol
, pyvalue
);
61 dict_add(PyObject
*dict
, char *symbol
, long value
)
63 #if PY_MAJOR_VERSION >= 3
64 PyObject
*pyvalue
= PyLong_FromLong(value
);
66 PyObject
*pyvalue
= PyInt_FromLong(value
);
68 PyDict_SetItemString(dict
, symbol
, pyvalue
);
73 edict_add(PyObject
*dict
, PyObject
*edict
, char *symbol
, long value
)
75 #if PY_MAJOR_VERSION >= 3
76 PyObject
*pyvalue
= PyLong_FromLong(value
);
77 PyObject
*pysymbol
= PyUnicode_FromString(symbol
);
79 PyObject
*pyvalue
= PyInt_FromLong(value
);
80 PyObject
*pysymbol
= PyString_FromString(symbol
);
83 PyDict_SetItemString(dict
, symbol
, pyvalue
);
84 PyDict_SetItem(edict
, pyvalue
, pysymbol
);
90 setExtendedTimeBase(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
93 char *keyword_list
[] = {"type", NULL
};
95 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
96 "i:PM_XTB_SET", keyword_list
, &type
))
98 return Py_BuildValue("i", PM_XTB_SET(type
));
102 getExtendedTimeBase(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
105 char *keyword_list
[] = {"mode", NULL
};
107 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
108 "i:PM_XTB_GET", keyword_list
, &mode
))
110 return Py_BuildValue("i", PM_XTB_GET(mode
));
114 timevalSleep(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
117 long seconds
, useconds
;
118 char *keyword_list
[] = {"seconds", "useconds", NULL
};
119 extern void __pmtimevalSleep(struct timeval
);
121 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
122 "ll:pmtimevalSleep", keyword_list
, &seconds
, &useconds
))
124 ctv
.tv_sec
= seconds
;
125 ctv
.tv_usec
= useconds
;
126 __pmtimevalSleep(ctv
);
132 timevalToReal(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
135 long seconds
, useconds
;
136 char *keyword_list
[] = {"seconds", "useconds", NULL
};
137 extern double __pmtimevalToReal(const struct timeval
*);
139 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
140 "ll:pmtimevalToReal", keyword_list
, &seconds
, &useconds
))
142 ctv
.tv_sec
= seconds
;
143 ctv
.tv_usec
= useconds
;
144 return Py_BuildValue("d", __pmtimevalToReal(&ctv
));
148 setIdentity(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
151 char *keyword_list
[] = {"name", NULL
};
152 extern int __pmSetProcessIdentity(const char *);
154 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
155 "s:pmSetProcessIdentity", keyword_list
, &name
))
157 return Py_BuildValue("i", __pmSetProcessIdentity(name
));
161 makeTime(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
166 char *keyword_list
[] = {"tm_sec", "tm_min", "tm_hour",
167 "tm_mday", "tm_mon", "tm_year",
168 "tm_wday", "tm_yday", "tm_isdst",
169 "tm_gmtoff", "tm_zone", NULL
};
171 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
172 "iiiiiiiiils:pmMktime", keyword_list
,
173 &tm
.tm_sec
, &tm
.tm_min
, &tm
.tm_hour
,
174 &tm
.tm_mday
, &tm
.tm_mon
, &tm
.tm_year
,
175 &tm
.tm_wday
, &tm
.tm_yday
, &tm
.tm_isdst
,
179 tm
.tm_gmtoff
= gmtoff
;
182 return Py_BuildValue("l", __pmMktime(&tm
));
186 * Common command line option handling code - wrapping pmOptions
190 addLongOption(pmLongOptions
*opt
, int duplicate
)
194 int index
= longOptionsCount
;
199 bytes
= (index
+ 2) * sizeof(pmLongOptions
); /* +2 for PMAPI_OPTIONS_END */
200 if ((lp
= realloc(options
.long_options
, bytes
)) == NULL
)
202 options
.long_options
= lp
;
207 if ((opt
->long_opt
= strdup(opt
->long_opt
)) == NULL
)
210 (opt
->argname
= strdup(opt
->argname
)) == NULL
) {
211 free((char *)opt
->long_opt
);
215 (opt
->message
= strdup(opt
->message
)) == NULL
) {
216 free((char *)opt
->long_opt
);
217 free((char *)opt
->argname
);
222 lp
[index
].long_opt
= opt
->long_opt
;
223 lp
[index
].has_arg
= opt
->has_arg
;
224 lp
[index
].short_opt
= opt
->short_opt
;
225 lp
[index
].argname
= opt
->argname
;
226 lp
[index
].message
= opt
->message
;
227 memset(&lp
[index
+1], 0, sizeof(pmLongOptions
)); /* PMAPI_OPTIONS_END */
233 setLongOptionHeader(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
235 pmLongOptions header
= PMAPI_OPTIONS_HEADER("");
236 char *keyword_list
[] = {"heading", NULL
};
238 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
239 "s:pmSetLongOptionHeader", keyword_list
,
242 if ((header
.message
= strdup(header
.message
)) == NULL
)
243 return PyErr_NoMemory();
245 if (addLongOption(&header
, 0) < 0) {
246 free((char *)header
.message
);
247 return PyErr_NoMemory();
254 setLongOptionText(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
256 pmLongOptions text
= PMAPI_OPTIONS_TEXT("");
257 char *keyword_list
[] = {"text", NULL
};
259 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
260 "s:pmSetLongOptionText", keyword_list
,
263 if ((text
.message
= strdup(text
.message
)) == NULL
)
264 return PyErr_NoMemory();
266 if (addLongOption(&text
, 0) < 0) {
267 free((char *)text
.message
);
268 return PyErr_NoMemory();
275 addLongOptionObject(pmLongOptions
*option
)
277 if (addLongOption(option
, 1) < 0)
278 return PyErr_NoMemory();
284 setLongOption(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
286 char *short_opt
= NULL
;
287 pmLongOptions option
= { 0 };
288 char *keyword_list
[] = {"long_opt", "has_arg", "short_opt",
289 "argname", "message", NULL
};
291 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
292 "sisss:pmSetLongOption", keyword_list
,
293 &option
.long_opt
, &option
.has_arg
, &short_opt
,
294 &option
.argname
, &option
.message
))
297 option
.short_opt
= (int)short_opt
[0];
298 return addLongOptionObject(&option
);
302 setLongOptionAlign(PyObject
*self
, PyObject
*args
)
304 pmLongOptions option
= PMOPT_ALIGN
;
305 return addLongOptionObject(&option
);
309 setLongOptionArchive(PyObject
*self
, PyObject
*args
)
311 pmLongOptions option
= PMOPT_ARCHIVE
;
312 return addLongOptionObject(&option
);
316 setLongOptionHostList(PyObject
*self
, PyObject
*args
)
318 pmLongOptions option
= PMOPT_HOST_LIST
;
319 return addLongOptionObject(&option
);
323 setLongOptionArchiveList(PyObject
*self
, PyObject
*args
)
325 pmLongOptions option
= PMOPT_ARCHIVE_LIST
;
326 return addLongOptionObject(&option
);
330 setLongOptionArchiveFolio(PyObject
*self
, PyObject
*args
)
332 pmLongOptions option
= PMOPT_ARCHIVE_FOLIO
;
333 return addLongOptionObject(&option
);
337 setLongOptionContainer(PyObject
*self
, PyObject
*args
)
339 pmLongOptions option
= PMOPT_CONTAINER
;
340 return addLongOptionObject(&option
);
344 setLongOptionDebug(PyObject
*self
, PyObject
*args
)
346 pmLongOptions option
= PMOPT_DEBUG
;
347 return addLongOptionObject(&option
);
351 setLongOptionHost(PyObject
*self
, PyObject
*args
)
353 pmLongOptions option
= PMOPT_HOST
;
354 return addLongOptionObject(&option
);
358 setLongOptionHostsFile(PyObject
*self
, PyObject
*args
)
360 pmLongOptions option
= PMOPT_HOSTSFILE
;
361 return addLongOptionObject(&option
);
365 setLongOptionSpecLocal(PyObject
*self
, PyObject
*args
)
367 pmLongOptions option
= PMOPT_SPECLOCAL
;
368 return addLongOptionObject(&option
);
372 setLongOptionLocalPMDA(PyObject
*self
, PyObject
*args
)
374 pmLongOptions option
= PMOPT_LOCALPMDA
;
375 return addLongOptionObject(&option
);
379 setLongOptionOrigin(PyObject
*self
, PyObject
*args
)
381 pmLongOptions option
= PMOPT_ORIGIN
;
382 return addLongOptionObject(&option
);
386 setLongOptionStart(PyObject
*self
, PyObject
*args
)
388 pmLongOptions option
= PMOPT_START
;
389 return addLongOptionObject(&option
);
393 setLongOptionSamples(PyObject
*self
, PyObject
*args
)
395 pmLongOptions option
= PMOPT_SAMPLES
;
396 return addLongOptionObject(&option
);
400 setLongOptionFinish(PyObject
*self
, PyObject
*args
)
402 pmLongOptions option
= PMOPT_FINISH
;
403 return addLongOptionObject(&option
);
407 setLongOptionInterval(PyObject
*self
, PyObject
*args
)
409 pmLongOptions option
= PMOPT_INTERVAL
;
410 return addLongOptionObject(&option
);
414 setLongOptionVersion(PyObject
*self
, PyObject
*args
)
416 pmLongOptions option
= PMOPT_VERSION
;
417 return addLongOptionObject(&option
);
421 setLongOptionTimeZone(PyObject
*self
, PyObject
*args
)
423 pmLongOptions option
= PMOPT_TIMEZONE
;
424 return addLongOptionObject(&option
);
428 setLongOptionHostZone(PyObject
*self
, PyObject
*args
)
430 pmLongOptions option
= PMOPT_HOSTZONE
;
431 return addLongOptionObject(&option
);
435 setLongOptionHelp(PyObject
*self
, PyObject
*args
)
437 pmLongOptions option
= PMOPT_HELP
;
438 return addLongOptionObject(&option
);
442 resetAllOptions(PyObject
*self
, PyObject
*args
)
444 pmFreeOptions(&options
);
445 memset(&options
, 0, sizeof(options
));
451 setShortOptions(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
454 char *keyword_list
[] = {"short_options", NULL
};
456 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
457 "s:pmSetShortOptions", keyword_list
, &short_opts
))
460 if ((short_opts
= strdup(short_opts
? short_opts
: "")) == NULL
)
461 return PyErr_NoMemory();
462 if (options
.short_options
)
463 free((void *)options
.short_options
);
464 options
.short_options
= short_opts
;
470 setShortUsage(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
473 char *keyword_list
[] = {"short_usage", NULL
};
475 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
476 "s:pmSetShortUsage", keyword_list
, &short_usage
))
479 if ((short_usage
= strdup(short_usage
? short_usage
: "")) == NULL
)
480 return PyErr_NoMemory();
481 if (options
.short_usage
)
482 free((void *)options
.short_usage
);
483 options
.short_usage
= short_usage
;
489 setOptionContext(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
492 char *keyword_list
[] = {"context", NULL
};
494 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
495 "i:pmSetOptionContext", keyword_list
, &context
))
498 options
.context
= context
;
504 setOptionFlags(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
507 char *keyword_list
[] = {"flags", NULL
};
509 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
510 "i:pmSetOptionFlags", keyword_list
, &flags
))
513 options
.flags
|= flags
;
519 setOptionArchiveFolio(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
522 char *keyword_list
[] = {PMLONGOPT_ARCHIVE_FOLIO
, NULL
};
524 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
525 "s:pmSetOptionArchiveFolio", keyword_list
, &folio
))
528 __pmAddOptArchiveFolio(&options
, folio
);
534 setOptionArchiveList(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
537 char *keyword_list
[] = {PMLONGOPT_ARCHIVE_LIST
, NULL
};
539 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
540 "s:pmSetOptionArchiveList", keyword_list
, &archives
))
543 __pmAddOptArchiveList(&options
, archives
);
549 setOptionArchive(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
552 char *keyword_list
[] = {"archive", NULL
};
554 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
555 "s:pmSetOptionArchive", keyword_list
, &archive
))
558 if ((archive
= strdup(archive
? archive
: "")) == NULL
)
559 return PyErr_NoMemory();
560 __pmAddOptArchive(&options
, archive
);
566 setOptionContainer(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
569 char *keyword_list
[] = {PMLONGOPT_CONTAINER
, NULL
};
571 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
572 "s:pmSetOptionContainer", keyword_list
, &container
))
575 if ((container
= strdup(container
? container
: "")) == NULL
)
576 return PyErr_NoMemory();
577 __pmAddOptContainer(&options
, container
);
583 setOptionHost(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
586 char *keyword_list
[] = {"host", NULL
};
588 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
589 "s:pmSetOptionHost", keyword_list
, &host
))
592 if ((host
= strdup(host
? host
: "")) == NULL
)
593 return PyErr_NoMemory();
594 __pmAddOptHost(&options
, host
);
600 setOptionHostList(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
603 char *keyword_list
[] = {PMLONGOPT_HOST_LIST
, NULL
};
605 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
606 "s:pmSetOptionHostList", keyword_list
, &hosts
))
609 __pmAddOptHostList(&options
, hosts
);
615 setOptionSpecLocal(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
618 char *keyword_list
[] = {"spec", NULL
};
620 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
621 "s:pmSetOptionSpecLocal", keyword_list
, &spec
))
624 if ((spec
= strdup(spec
? spec
: "")) == NULL
)
625 return PyErr_NoMemory();
626 __pmSetLocalContextTable(&options
, spec
);
632 setOptionLocalPMDA(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
634 __pmSetLocalContextFlag(&options
);
640 setOptionSamples(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
642 char *count
, *endnum
;
643 char *keyword_list
[] = {"count", NULL
};
645 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
646 "s:pmSetOptionSamples", keyword_list
, &count
))
649 if (options
.finish_optarg
) {
650 pmprintf("%s: at most one of finish time and sample count allowed\n",
654 options
.samples
= (int)strtol(count
, &endnum
, 10);
655 if (*endnum
!= '\0' || options
.samples
< 0) {
656 pmprintf("%s: sample count must be a positive numeric argument\n",
666 setOptionInterval(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
668 char *delta
, *errmsg
;
669 char *keyword_list
[] = {"delta", NULL
};
671 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
672 "s:pmSetOptionInterval", keyword_list
, &delta
))
675 if (pmParseInterval(delta
, &options
.interval
, &errmsg
) < 0) {
676 pmprintf("%s: interval argument not in pmParseInterval(3) format:\n",
678 pmprintf("%s\n", errmsg
);
687 setOptionErrors(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
690 char *keyword_list
[] = {"errors", NULL
};
692 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
693 "i:pmSetOptionErrors", keyword_list
, &errors
))
696 options
.errors
= errors
;
702 override_callback(int opt
, pmOptions
*opts
)
704 PyObject
*arglist
, *result
;
705 char argstring
[2] = { (char)opt
, '\0' };
708 arglist
= Py_BuildValue("(s)", argstring
);
713 result
= PyEval_CallObject(overridesCallback
, arglist
);
717 return -EAGAIN
; /* exception thrown */
719 sts
= PyLong_AsLong(result
);
725 options_callback(int opt
, pmOptions
*opts
)
727 PyObject
*arglist
, *result
;
728 char argstring
[2] = { (char)opt
, '\0' };
730 arglist
= Py_BuildValue("(ssi)", argstring
, options
.optarg
, options
.index
);
734 result
= PyEval_CallObject(optionCallback
, arglist
);
745 getNonOptionsFromList(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
749 PyObject
*pyargv
= NULL
;
750 char *keyword_list
[] = {"argv", NULL
};
752 /* Caller must perform pmGetOptions before running this, check */
753 if (!(options
.flags
& PM_OPTFLAG_DONE
)) {
754 PyErr_SetString(PyExc_RuntimeError
, "pmGetOptions must be called first");
758 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
759 "O:pmGetNonOptionsFromList", keyword_list
, &pyargv
))
763 if (!PyList_Check(pyargv
)) {
764 PyErr_SetString(PyExc_TypeError
, "pmGetNonOptionsFromList uses a list");
769 if ((argc
= PyList_GET_SIZE(pyargv
)) > 0)
770 length
= argc
- options
.optind
;
777 if ((result
= PyList_New(length
)) == NULL
)
778 return PyErr_NoMemory();
780 for (i
= 0; i
< length
; i
++) {
781 PyObject
*pyarg
= PyList_GET_ITEM(pyargv
, options
.optind
+ i
);
783 PyList_SET_ITEM(result
, i
, pyarg
);
790 getOptionsFromList(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
794 PyObject
*pyargv
= NULL
;
795 char *keyword_list
[] = {"argv", NULL
};
797 // Note that PyArg_ParseTupleAndKeywords() returns a "borrowed"
798 // reference, so there is no need to decrement a reference to
800 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
801 "O:pmGetOptionsFromList", keyword_list
, &pyargv
))
805 return Py_BuildValue("i", 0);
807 if (!PyList_Check(pyargv
)) {
808 PyErr_SetString(PyExc_TypeError
, "pmGetOptionsFromList uses a list");
812 if ((argc
= PyList_GET_SIZE(pyargv
)) <= 0) {
813 return Py_BuildValue("i", 0);
816 if ((argv
= malloc(argc
* sizeof(char *))) == NULL
) {
817 return PyErr_NoMemory();
820 for (i
= 0; i
< argc
; i
++) {
821 PyObject
*pyarg
= PyList_GET_ITEM(pyargv
, i
);
822 #if PY_MAJOR_VERSION >= 3
823 char *string
= PyUnicode_AsUTF8(pyarg
);
825 char *string
= PyString_AsString(pyarg
);
828 /* argv[0] parameter will be used for pmProgname, so need to
829 * ensure the memory that backs it will be with us forever.
831 if (i
== 0 && (string
= strdup(string
)) == NULL
) {
833 return PyErr_NoMemory();
838 if (overridesCallback
)
839 options
.override
= override_callback
;
840 while ((i
= pmGetOptions(argc
, argv
, &options
)) != -1)
841 options_callback(i
, &options
);
844 if (options
.flags
& PM_OPTFLAG_EXIT
)
845 return Py_BuildValue("i", PM_ERR_APPVERSION
);
847 return Py_BuildValue("i", options
.errors
);
851 endOptions(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
853 __pmEndOptions(&options
);
859 setContextOptions(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
861 int sts
, ctx
, step
, mode
, delta
;
862 char *keyword_list
[] = {"context", "mode", "delta", NULL
};
864 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
865 "iii:pmSetContextOptions", keyword_list
, &ctx
, &mode
, &delta
))
868 /* complete time window and timezone setup */
869 if ((sts
= pmGetContextOptions(ctx
, &options
)) < 0)
870 return Py_BuildValue("i", sts
);
872 /* initial archive mode, position and delta */
873 if (options
.context
== PM_CONTEXT_ARCHIVE
&&
874 (options
.flags
& PM_OPTFLAG_BOUNDARIES
)) {
875 const int SECONDS_IN_24_DAYS
= 2073600;
876 struct timeval interval
= options
.interval
;
877 struct timeval position
= options
.origin
;
879 if (interval
.tv_sec
> SECONDS_IN_24_DAYS
) {
880 step
= interval
.tv_sec
;
881 mode
|= PM_XTB_SET(PM_TIME_SEC
);
883 if (interval
.tv_sec
== 0 && interval
.tv_usec
== 0)
884 interval
.tv_sec
= delta
;
885 step
= interval
.tv_sec
* 1e3
+ interval
.tv_usec
/ 1e3
;
886 mode
|= PM_XTB_SET(PM_TIME_MSEC
);
888 if ((sts
= pmSetMode(mode
, &position
, step
)) < 0) {
889 pmprintf("%s: pmSetMode: %s\n", pmProgname
, pmErrStr(sts
));
890 options
.flags
|= PM_OPTFLAG_RUNTIME_ERR
;
894 return Py_BuildValue("i", sts
);
898 pmnsDecodeCallback(const char *name
, void *closure
)
900 PyObject
*arglist
, *result
;
902 arglist
= Py_BuildValue("(s)", name
);
905 result
= PyEval_CallObject(closure
, arglist
);
914 * This pmTraversePMNS_r wrapper is specifically so that python3
915 * installs can pass out correctly decoded python strings rather
919 pmnsTraverse(PyObject
*self
, PyObject
*args
, PyObject
*keywords
)
922 char *keyword_list
[] = {"name", "callback", NULL
};
926 if (!PyArg_ParseTupleAndKeywords(args
, keywords
,
927 "sO:pmnsTraverse", keyword_list
, &name
, &func
))
929 if (!PyCallable_Check(func
)) {
930 PyErr_SetString(PyExc_TypeError
, "pmnsTraverse needs a callable");
933 sts
= pmTraversePMNS_r(name
, pmnsDecodeCallback
, func
);
934 return Py_BuildValue("i", sts
);
938 usageMessage(PyObject
*self
, PyObject
*args
)
940 pmUsageMessage(&options
);
946 setOverrideCallback(PyObject
*self
, PyObject
*args
)
950 if (!PyArg_ParseTuple(args
, "O:pmSetOverrideCallback", &func
))
952 if (!PyCallable_Check(func
)) {
953 PyErr_SetString(PyExc_TypeError
,
954 "pmSetOverrideCallback parameter not callable");
958 Py_XDECREF(overridesCallback
);
959 overridesCallback
= func
;
965 setOptionCallback(PyObject
*self
, PyObject
*args
)
969 if (!PyArg_ParseTuple(args
, "O:pmSetOptionCallback", &func
))
971 if (!PyCallable_Check(func
)) {
972 PyErr_SetString(PyExc_TypeError
,
973 "pmSetOptionCallback parameter not callable");
977 Py_XDECREF(optionCallback
);
978 optionCallback
= func
;
984 getOptionErrors(PyObject
*self
, PyObject
*args
)
986 return Py_BuildValue("i", options
.errors
);
990 getOptionFlags(PyObject
*self
, PyObject
*args
)
992 return Py_BuildValue("i", options
.flags
);
996 getOptionContext(PyObject
*self
, PyObject
*args
)
998 if (options
.context
> 0)
999 return Py_BuildValue("i", options
.context
);
1005 getOptionHosts(PyObject
*self
, PyObject
*args
)
1010 if (options
.nhosts
> 0) {
1011 if ((result
= PyList_New(options
.nhosts
)) == NULL
)
1012 return PyErr_NoMemory();
1013 for (i
= 0; i
< options
.nhosts
; i
++) {
1014 #if PY_MAJOR_VERSION >= 3
1015 PyObject
*pyent
= PyUnicode_FromString(options
.hosts
[i
]);
1017 PyObject
*pyent
= PyString_FromString(options
.hosts
[i
]);
1019 PyList_SET_ITEM(result
, i
, pyent
);
1029 getOptionArchives(PyObject
*self
, PyObject
*args
)
1034 if (options
.narchives
> 0) {
1035 if ((result
= PyList_New(options
.narchives
)) == NULL
)
1036 return PyErr_NoMemory();
1037 for (i
= 0; i
< options
.narchives
; i
++) {
1038 #if PY_MAJOR_VERSION >= 3
1039 PyObject
*pyent
= PyUnicode_FromString(options
.archives
[i
]);
1041 PyObject
*pyent
= PyString_FromString(options
.archives
[i
]);
1043 PyList_SET_ITEM(result
, i
, pyent
);
1053 getOptionStart_sec(PyObject
*self
, PyObject
*args
)
1055 if (options
.start
.tv_sec
|| options
.start
.tv_usec
)
1056 return Py_BuildValue("l", options
.start
.tv_sec
);
1062 getOptionStart_usec(PyObject
*self
, PyObject
*args
)
1064 if (options
.start
.tv_sec
|| options
.start
.tv_usec
)
1065 return Py_BuildValue("l", options
.start
.tv_usec
);
1071 getOptionAlign_optarg(PyObject
*self
, PyObject
*args
)
1073 if (options
.align_optarg
)
1074 return Py_BuildValue("s", options
.align_optarg
);
1080 getOptionFinish_optarg(PyObject
*self
, PyObject
*args
)
1082 if (options
.finish_optarg
)
1083 return Py_BuildValue("s", options
.finish_optarg
);
1089 getOptionFinish_sec(PyObject
*self
, PyObject
*args
)
1091 if (options
.finish
.tv_sec
|| options
.finish
.tv_usec
)
1092 return Py_BuildValue("l", options
.finish
.tv_sec
);
1098 getOptionFinish_usec(PyObject
*self
, PyObject
*args
)
1100 if (options
.finish
.tv_sec
|| options
.finish
.tv_usec
)
1101 return Py_BuildValue("l", options
.finish
.tv_usec
);
1107 getOptionOrigin_sec(PyObject
*self
, PyObject
*args
)
1109 if (options
.origin
.tv_sec
|| options
.origin
.tv_usec
)
1110 return Py_BuildValue("l", options
.origin
.tv_sec
);
1116 getOptionOrigin_usec(PyObject
*self
, PyObject
*args
)
1118 if (options
.origin
.tv_sec
|| options
.origin
.tv_usec
)
1119 return Py_BuildValue("l", options
.origin
.tv_usec
);
1125 getOptionInterval_sec(PyObject
*self
, PyObject
*args
)
1127 if (options
.interval
.tv_sec
|| options
.interval
.tv_usec
)
1128 return Py_BuildValue("l", options
.interval
.tv_sec
);
1134 getOptionInterval_usec(PyObject
*self
, PyObject
*args
)
1136 if (options
.interval
.tv_sec
|| options
.interval
.tv_usec
)
1137 return Py_BuildValue("l", options
.interval
.tv_usec
);
1143 getOptionSamples(PyObject
*self
, PyObject
*args
)
1145 if (options
.samples
)
1146 return Py_BuildValue("i", options
.samples
);
1152 getOptionTimezone(PyObject
*self
, PyObject
*args
)
1154 if (options
.timezone
)
1155 return Py_BuildValue("s", options
.timezone
);
1161 getOptionHostZone(PyObject
*self
, PyObject
*args
)
1163 return Py_BuildValue("i", options
.tzflag
);
1167 getOptionContainer(PyObject
*self
, PyObject
*args
)
1171 if ((container
= getenv("PCP_CONTAINER")) != NULL
)
1172 return Py_BuildValue("s", strdup(container
));
1178 getOptionLocalPMDA(PyObject
*self
, PyObject
*args
)
1180 return Py_BuildValue("i", options
.Lflag
);
1183 static PyMethodDef methods
[] = {
1184 { .ml_name
= "PM_XTB_SET",
1185 .ml_meth
= (PyCFunction
) setExtendedTimeBase
,
1186 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1187 { .ml_name
= "PM_XTB_GET",
1188 .ml_meth
= (PyCFunction
) getExtendedTimeBase
,
1189 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1190 { .ml_name
= "pmtimevalSleep",
1191 .ml_meth
= (PyCFunction
) timevalSleep
,
1192 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1193 { .ml_name
= "pmtimevalToReal",
1194 .ml_meth
= (PyCFunction
) timevalToReal
,
1195 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1196 { .ml_name
= "pmSetProcessIdentity",
1197 .ml_meth
= (PyCFunction
) setIdentity
,
1198 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1199 { .ml_name
= "pmMktime",
1200 .ml_meth
= (PyCFunction
) makeTime
,
1201 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1202 { .ml_name
= "pmResetAllOptions",
1203 .ml_meth
= (PyCFunction
) resetAllOptions
,
1204 .ml_flags
= METH_NOARGS
},
1205 { .ml_name
= "pmSetLongOptionHeader",
1206 .ml_meth
= (PyCFunction
) setLongOptionHeader
,
1207 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1208 { .ml_name
= "pmSetLongOptionText",
1209 .ml_meth
= (PyCFunction
) setLongOptionText
,
1210 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1211 { .ml_name
= "pmSetLongOption",
1212 .ml_meth
= (PyCFunction
) setLongOption
,
1213 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1214 { .ml_name
= "pmSetLongOptionAlign",
1215 .ml_meth
= (PyCFunction
) setLongOptionAlign
,
1216 .ml_flags
= METH_NOARGS
},
1217 { .ml_name
= "pmSetLongOptionArchive",
1218 .ml_meth
= (PyCFunction
) setLongOptionArchive
,
1219 .ml_flags
= METH_NOARGS
},
1220 { .ml_name
= "pmSetLongOptionArchiveList",
1221 .ml_meth
= (PyCFunction
) setLongOptionArchiveList
,
1222 .ml_flags
= METH_NOARGS
},
1223 { .ml_name
= "pmSetLongOptionArchiveFolio",
1224 .ml_meth
= (PyCFunction
) setLongOptionArchiveFolio
,
1225 .ml_flags
= METH_NOARGS
},
1226 { .ml_name
= "pmSetLongOptionContainer",
1227 .ml_meth
= (PyCFunction
) setLongOptionContainer
,
1228 .ml_flags
= METH_NOARGS
},
1229 { .ml_name
= "pmSetLongOptionDebug",
1230 .ml_meth
= (PyCFunction
) setLongOptionDebug
,
1231 .ml_flags
= METH_NOARGS
},
1232 { .ml_name
= "pmSetLongOptionHost",
1233 .ml_meth
= (PyCFunction
) setLongOptionHost
,
1234 .ml_flags
= METH_NOARGS
},
1235 { .ml_name
= "pmSetLongOptionHostList",
1236 .ml_meth
= (PyCFunction
) setLongOptionHostList
,
1237 .ml_flags
= METH_NOARGS
},
1238 { .ml_name
= "pmSetLongOptionHostsFile",
1239 .ml_meth
= (PyCFunction
) setLongOptionHostsFile
,
1240 .ml_flags
= METH_NOARGS
},
1241 { .ml_name
= "pmSetLongOptionSpecLocal",
1242 .ml_meth
= (PyCFunction
) setLongOptionSpecLocal
,
1243 .ml_flags
= METH_NOARGS
},
1244 { .ml_name
= "pmSetLongOptionLocalPMDA",
1245 .ml_meth
= (PyCFunction
) setLongOptionLocalPMDA
,
1246 .ml_flags
= METH_NOARGS
},
1247 { .ml_name
= "pmSetLongOptionOrigin",
1248 .ml_meth
= (PyCFunction
) setLongOptionOrigin
,
1249 .ml_flags
= METH_NOARGS
},
1250 { .ml_name
= "pmSetLongOptionStart",
1251 .ml_meth
= (PyCFunction
) setLongOptionStart
,
1252 .ml_flags
= METH_NOARGS
},
1253 { .ml_name
= "pmSetLongOptionSamples",
1254 .ml_meth
= (PyCFunction
) setLongOptionSamples
,
1255 .ml_flags
= METH_NOARGS
},
1256 { .ml_name
= "pmSetLongOptionFinish",
1257 .ml_meth
= (PyCFunction
) setLongOptionFinish
,
1258 .ml_flags
= METH_NOARGS
},
1259 { .ml_name
= "pmSetLongOptionInterval",
1260 .ml_meth
= (PyCFunction
) setLongOptionInterval
,
1261 .ml_flags
= METH_NOARGS
},
1262 { .ml_name
= "pmSetLongOptionVersion",
1263 .ml_meth
= (PyCFunction
) setLongOptionVersion
,
1264 .ml_flags
= METH_NOARGS
},
1265 { .ml_name
= "pmSetLongOptionTimeZone",
1266 .ml_meth
= (PyCFunction
) setLongOptionTimeZone
,
1267 .ml_flags
= METH_NOARGS
},
1268 { .ml_name
= "pmSetLongOptionHostZone",
1269 .ml_meth
= (PyCFunction
) setLongOptionHostZone
,
1270 .ml_flags
= METH_NOARGS
},
1271 { .ml_name
= "pmSetLongOptionHelp",
1272 .ml_meth
= (PyCFunction
) setLongOptionHelp
,
1273 .ml_flags
= METH_NOARGS
},
1274 { .ml_name
= "pmSetShortOptions",
1275 .ml_meth
= (PyCFunction
) setShortOptions
,
1276 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1277 { .ml_name
= "pmSetShortUsage",
1278 .ml_meth
= (PyCFunction
) setShortUsage
,
1279 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1280 { .ml_name
= "pmSetOptionContext",
1281 .ml_meth
= (PyCFunction
) setOptionContext
,
1282 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1283 { .ml_name
= "pmSetOptionFlags",
1284 .ml_meth
= (PyCFunction
) setOptionFlags
,
1285 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1286 { .ml_name
= "pmSetOptionErrors",
1287 .ml_meth
= (PyCFunction
) setOptionErrors
,
1288 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1289 { .ml_name
= "pmGetOptionErrors",
1290 .ml_meth
= (PyCFunction
) getOptionErrors
,
1291 .ml_flags
= METH_NOARGS
},
1292 { .ml_name
= "pmGetOptionFlags",
1293 .ml_meth
= (PyCFunction
) getOptionFlags
,
1294 .ml_flags
= METH_NOARGS
},
1295 { .ml_name
= "pmGetOptionsFromList",
1296 .ml_meth
= (PyCFunction
) getOptionsFromList
,
1297 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1298 { .ml_name
= "pmGetNonOptionsFromList",
1299 .ml_meth
= (PyCFunction
) getNonOptionsFromList
,
1300 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1301 { .ml_name
= "pmEndOptions",
1302 .ml_meth
= (PyCFunction
) endOptions
,
1303 .ml_flags
= METH_NOARGS
},
1304 { .ml_name
= "pmSetContextOptions",
1305 .ml_meth
= (PyCFunction
) setContextOptions
,
1306 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1307 { .ml_name
= "pmUsageMessage",
1308 .ml_meth
= (PyCFunction
) usageMessage
,
1309 .ml_flags
= METH_NOARGS
},
1310 { .ml_name
= "pmSetOptionCallback",
1311 .ml_meth
= (PyCFunction
) setOptionCallback
,
1312 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1313 { .ml_name
= "pmSetOverrideCallback",
1314 .ml_meth
= (PyCFunction
) setOverrideCallback
,
1315 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1316 { .ml_name
= "pmGetOptionContext",
1317 .ml_meth
= (PyCFunction
) getOptionContext
,
1318 .ml_flags
= METH_NOARGS
},
1319 { .ml_name
= "pmGetOptionHosts",
1320 .ml_meth
= (PyCFunction
) getOptionHosts
,
1321 .ml_flags
= METH_NOARGS
},
1322 { .ml_name
= "pmGetOptionArchives",
1323 .ml_meth
= (PyCFunction
) getOptionArchives
,
1324 .ml_flags
= METH_NOARGS
},
1325 { .ml_name
= "pmGetOptionStart_sec",
1326 .ml_meth
= (PyCFunction
) getOptionStart_sec
,
1327 .ml_flags
= METH_NOARGS
},
1328 { .ml_name
= "pmGetOptionStart_usec",
1329 .ml_meth
= (PyCFunction
) getOptionStart_usec
,
1330 .ml_flags
= METH_NOARGS
},
1331 { .ml_name
= "pmGetOptionAlign_optarg",
1332 .ml_meth
= (PyCFunction
) getOptionAlign_optarg
,
1333 .ml_flags
= METH_NOARGS
},
1334 { .ml_name
= "pmGetOptionFinish_optarg",
1335 .ml_meth
= (PyCFunction
) getOptionFinish_optarg
,
1336 .ml_flags
= METH_NOARGS
},
1337 { .ml_name
= "pmGetOptionFinish_sec",
1338 .ml_meth
= (PyCFunction
) getOptionFinish_sec
,
1339 .ml_flags
= METH_NOARGS
},
1340 { .ml_name
= "pmGetOptionFinish_usec",
1341 .ml_meth
= (PyCFunction
) getOptionFinish_usec
,
1342 .ml_flags
= METH_NOARGS
},
1343 { .ml_name
= "pmGetOptionOrigin_sec",
1344 .ml_meth
= (PyCFunction
) getOptionOrigin_sec
,
1345 .ml_flags
= METH_NOARGS
},
1346 { .ml_name
= "pmGetOptionOrigin_usec",
1347 .ml_meth
= (PyCFunction
) getOptionOrigin_usec
,
1348 .ml_flags
= METH_NOARGS
},
1349 { .ml_name
= "pmGetOptionInterval_sec",
1350 .ml_meth
= (PyCFunction
) getOptionInterval_sec
,
1351 .ml_flags
= METH_NOARGS
},
1352 { .ml_name
= "pmGetOptionInterval_usec",
1353 .ml_meth
= (PyCFunction
) getOptionInterval_usec
,
1354 .ml_flags
= METH_NOARGS
},
1355 { .ml_name
= "pmSetOptionInterval",
1356 .ml_meth
= (PyCFunction
) setOptionInterval
,
1357 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1358 { .ml_name
= "pmGetOptionSamples",
1359 .ml_meth
= (PyCFunction
) getOptionSamples
,
1360 .ml_flags
= METH_NOARGS
},
1361 { .ml_name
= "pmSetOptionSamples",
1362 .ml_meth
= (PyCFunction
) setOptionSamples
,
1363 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1364 { .ml_name
= "pmGetOptionTimezone",
1365 .ml_meth
= (PyCFunction
) getOptionTimezone
,
1366 .ml_flags
= METH_NOARGS
},
1367 { .ml_name
= "pmGetOptionHostZone",
1368 .ml_meth
= (PyCFunction
) getOptionHostZone
,
1369 .ml_flags
= METH_NOARGS
},
1370 { .ml_name
= "pmGetOptionContainer",
1371 .ml_meth
= (PyCFunction
) getOptionContainer
,
1372 .ml_flags
= METH_NOARGS
},
1373 { .ml_name
= "pmGetOptionLocalPMDA",
1374 .ml_meth
= (PyCFunction
) getOptionLocalPMDA
,
1375 .ml_flags
= METH_NOARGS
},
1376 { .ml_name
= "pmSetOptionArchive",
1377 .ml_meth
= (PyCFunction
) setOptionArchive
,
1378 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1379 { .ml_name
= "pmSetOptionArchiveList",
1380 .ml_meth
= (PyCFunction
) setOptionArchiveList
,
1381 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1382 { .ml_name
= "pmSetOptionArchiveFolio",
1383 .ml_meth
= (PyCFunction
) setOptionArchiveFolio
,
1384 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1385 { .ml_name
= "pmSetOptionContainer",
1386 .ml_meth
= (PyCFunction
) setOptionContainer
,
1387 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1388 { .ml_name
= "pmSetOptionHost",
1389 .ml_meth
= (PyCFunction
) setOptionHost
,
1390 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1391 { .ml_name
= "pmSetOptionHostList",
1392 .ml_meth
= (PyCFunction
) setOptionHostList
,
1393 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1394 { .ml_name
= "pmSetOptionSpecLocal",
1395 .ml_meth
= (PyCFunction
) setOptionSpecLocal
,
1396 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1397 { .ml_name
= "pmSetOptionLocalPMDA",
1398 .ml_meth
= (PyCFunction
) setOptionLocalPMDA
,
1399 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1400 { .ml_name
= "pmnsTraverse",
1401 .ml_meth
= (PyCFunction
) pmnsTraverse
,
1402 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
},
1406 /* called when the module is initialized. */
1409 PyObject
*module
, *dict
, *edict
;
1411 MOD_DEF(module
, "cpmapi", NULL
, methods
);
1413 return MOD_ERROR_VAL
;
1415 dict
= PyModule_GetDict(module
);
1416 edict
= PyDict_New();
1418 PyModule_AddObject(module
, "pmErrSymDict", edict
);
1420 dict_add(dict
, "PMAPI_VERSION_2", PMAPI_VERSION_2
);
1421 dict_add(dict
, "PMAPI_VERSION", PMAPI_VERSION
);
1423 dict_add_unsigned(dict
, "PM_ID_NULL", PM_ID_NULL
);
1424 dict_add_unsigned(dict
, "PM_INDOM_NULL", PM_INDOM_NULL
);
1425 dict_add_unsigned(dict
, "PM_IN_NULL", PM_IN_NULL
);
1427 dict_add_unsigned(dict
, "PM_NS_DEFAULT", 0);
1429 #ifdef HAVE_BITFIELDS_LTOR
1430 dict_add(dict
, "HAVE_BITFIELDS_LTOR", 1);
1431 dict_add(dict
, "HAVE_BITFIELDS_RTOL", 0);
1433 dict_add(dict
, "HAVE_BITFIELDS_LTOR", 0);
1434 dict_add(dict
, "HAVE_BITFIELDS_RTOL", 1);
1436 dict_add(dict
, "SIZEOF_SUSECONDS_T", SIZEOF_SUSECONDS_T
);
1437 dict_add(dict
, "SIZEOF_TIME_T", SIZEOF_TIME_T
);
1439 dict_add(dict
, "PM_SPACE_BYTE", PM_SPACE_BYTE
);
1440 dict_add(dict
, "PM_SPACE_KBYTE", PM_SPACE_KBYTE
);
1441 dict_add(dict
, "PM_SPACE_MBYTE", PM_SPACE_MBYTE
);
1442 dict_add(dict
, "PM_SPACE_GBYTE", PM_SPACE_GBYTE
);
1443 dict_add(dict
, "PM_SPACE_TBYTE", PM_SPACE_TBYTE
);
1444 dict_add(dict
, "PM_SPACE_PBYTE", PM_SPACE_PBYTE
);
1445 dict_add(dict
, "PM_SPACE_EBYTE", PM_SPACE_EBYTE
);
1447 dict_add(dict
, "PM_TIME_NSEC", PM_TIME_NSEC
);
1448 dict_add(dict
, "PM_TIME_USEC", PM_TIME_USEC
);
1449 dict_add(dict
, "PM_TIME_MSEC", PM_TIME_MSEC
);
1450 dict_add(dict
, "PM_TIME_SEC", PM_TIME_SEC
);
1451 dict_add(dict
, "PM_TIME_MIN", PM_TIME_MIN
);
1452 dict_add(dict
, "PM_TIME_HOUR", PM_TIME_HOUR
);
1453 dict_add(dict
, "PM_COUNT_ONE", PM_COUNT_ONE
);
1455 dict_add(dict
, "PM_TYPE_NOSUPPORT", PM_TYPE_NOSUPPORT
);
1456 dict_add(dict
, "PM_TYPE_32", PM_TYPE_32
);
1457 dict_add(dict
, "PM_TYPE_U32", PM_TYPE_U32
);
1458 dict_add(dict
, "PM_TYPE_64", PM_TYPE_64
);
1459 dict_add(dict
, "PM_TYPE_U64", PM_TYPE_U64
);
1460 dict_add(dict
, "PM_TYPE_FLOAT", PM_TYPE_FLOAT
);
1461 dict_add(dict
, "PM_TYPE_DOUBLE", PM_TYPE_DOUBLE
);
1462 dict_add(dict
, "PM_TYPE_STRING", PM_TYPE_STRING
);
1463 dict_add(dict
, "PM_TYPE_AGGREGATE", PM_TYPE_AGGREGATE
);
1464 dict_add(dict
, "PM_TYPE_AGGREGATE_STATIC", PM_TYPE_AGGREGATE_STATIC
);
1465 dict_add(dict
, "PM_TYPE_EVENT", PM_TYPE_EVENT
);
1466 dict_add(dict
, "PM_TYPE_HIGHRES_EVENT", PM_TYPE_HIGHRES_EVENT
);
1467 dict_add(dict
, "PM_TYPE_UNKNOWN", PM_TYPE_UNKNOWN
);
1469 dict_add(dict
, "PM_SEM_COUNTER", PM_SEM_COUNTER
);
1470 dict_add(dict
, "PM_SEM_INSTANT", PM_SEM_INSTANT
);
1471 dict_add(dict
, "PM_SEM_DISCRETE", PM_SEM_DISCRETE
);
1473 dict_add(dict
, "PMNS_LOCAL", PMNS_LOCAL
);
1474 dict_add(dict
, "PMNS_REMOTE", PMNS_REMOTE
);
1475 dict_add(dict
, "PMNS_ARCHIVE", PMNS_ARCHIVE
);
1476 dict_add(dict
, "PMNS_LEAF_STATUS", PMNS_LEAF_STATUS
);
1477 dict_add(dict
, "PMNS_NONLEAF_STATUS", PMNS_NONLEAF_STATUS
);
1479 dict_add(dict
, "PM_CONTEXT_UNDEF", PM_CONTEXT_UNDEF
);
1480 dict_add(dict
, "PM_CONTEXT_HOST", PM_CONTEXT_HOST
);
1481 dict_add(dict
, "PM_CONTEXT_ARCHIVE", PM_CONTEXT_ARCHIVE
);
1482 dict_add(dict
, "PM_CONTEXT_LOCAL", PM_CONTEXT_LOCAL
);
1483 dict_add(dict
, "PM_CONTEXT_TYPEMASK", PM_CONTEXT_TYPEMASK
);
1484 dict_add(dict
, "PM_CTXFLAG_EXCLUSIVE", PM_CTXFLAG_EXCLUSIVE
);
1485 dict_add(dict
, "PM_CTXFLAG_SECURE", PM_CTXFLAG_SECURE
);
1486 dict_add(dict
, "PM_CTXFLAG_COMPRESS", PM_CTXFLAG_COMPRESS
);
1487 dict_add(dict
, "PM_CTXFLAG_RELAXED", PM_CTXFLAG_RELAXED
);
1489 dict_add(dict
, "PM_VAL_HDR_SIZE", PM_VAL_HDR_SIZE
);
1490 dict_add(dict
, "PM_VAL_VLEN_MAX", PM_VAL_VLEN_MAX
);
1491 dict_add(dict
, "PM_VAL_INSITU", PM_VAL_INSITU
);
1492 dict_add(dict
, "PM_VAL_DPTR", PM_VAL_DPTR
);
1493 dict_add(dict
, "PM_VAL_SPTR", PM_VAL_SPTR
);
1495 dict_add(dict
, "PMCD_NO_CHANGE", PMCD_NO_CHANGE
);
1496 dict_add(dict
, "PMCD_ADD_AGENT", PMCD_ADD_AGENT
);
1497 dict_add(dict
, "PMCD_RESTART_AGENT", PMCD_RESTART_AGENT
);
1498 dict_add(dict
, "PMCD_DROP_AGENT", PMCD_DROP_AGENT
);
1500 dict_add(dict
, "PM_MAXERRMSGLEN", PM_MAXERRMSGLEN
);
1501 dict_add(dict
, "PM_TZ_MAXLEN", PM_TZ_MAXLEN
);
1503 dict_add(dict
, "PM_LOG_MAXHOSTLEN", PM_LOG_MAXHOSTLEN
);
1504 dict_add(dict
, "PM_LOG_MAGIC", PM_LOG_MAGIC
);
1505 dict_add(dict
, "PM_LOG_VERS02", PM_LOG_VERS02
);
1506 dict_add(dict
, "PM_LOG_VOL_TI", PM_LOG_VOL_TI
);
1507 dict_add(dict
, "PM_LOG_VOL_META", PM_LOG_VOL_META
);
1509 dict_add(dict
, "PM_MODE_LIVE", PM_MODE_LIVE
);
1510 dict_add(dict
, "PM_MODE_INTERP", PM_MODE_INTERP
);
1511 dict_add(dict
, "PM_MODE_FORW", PM_MODE_FORW
);
1512 dict_add(dict
, "PM_MODE_BACK", PM_MODE_BACK
);
1514 dict_add(dict
, "PM_TEXT_ONELINE", PM_TEXT_ONELINE
);
1515 dict_add(dict
, "PM_TEXT_HELP", PM_TEXT_HELP
);
1517 dict_add(dict
, "PM_XTB_FLAG", PM_XTB_FLAG
);
1519 dict_add(dict
, "PM_OPTFLAG_INIT", PM_OPTFLAG_INIT
);
1520 dict_add(dict
, "PM_OPTFLAG_DONE", PM_OPTFLAG_DONE
);
1521 dict_add(dict
, "PM_OPTFLAG_MULTI", PM_OPTFLAG_MULTI
);
1522 dict_add(dict
, "PM_OPTFLAG_USAGE_ERR", PM_OPTFLAG_USAGE_ERR
);
1523 dict_add(dict
, "PM_OPTFLAG_RUNTIME_ERR", PM_OPTFLAG_RUNTIME_ERR
);
1524 dict_add(dict
, "PM_OPTFLAG_EXIT", PM_OPTFLAG_EXIT
);
1525 dict_add(dict
, "PM_OPTFLAG_POSIX", PM_OPTFLAG_POSIX
);
1526 dict_add(dict
, "PM_OPTFLAG_MIXED", PM_OPTFLAG_MIXED
);
1527 dict_add(dict
, "PM_OPTFLAG_ENV_ONLY", PM_OPTFLAG_ENV_ONLY
);
1528 dict_add(dict
, "PM_OPTFLAG_LONG_ONLY", PM_OPTFLAG_LONG_ONLY
);
1529 dict_add(dict
, "PM_OPTFLAG_BOUNDARIES", PM_OPTFLAG_BOUNDARIES
);
1530 dict_add(dict
, "PM_OPTFLAG_STDOUT_TZ", PM_OPTFLAG_STDOUT_TZ
);
1531 dict_add(dict
, "PM_OPTFLAG_NOFLUSH", PM_OPTFLAG_NOFLUSH
);
1532 dict_add(dict
, "PM_OPTFLAG_QUIET", PM_OPTFLAG_QUIET
);
1534 dict_add(dict
, "PM_EVENT_FLAG_POINT", PM_EVENT_FLAG_POINT
);
1535 dict_add(dict
, "PM_EVENT_FLAG_START", PM_EVENT_FLAG_START
);
1536 dict_add(dict
, "PM_EVENT_FLAG_END", PM_EVENT_FLAG_END
);
1537 dict_add(dict
, "PM_EVENT_FLAG_ID", PM_EVENT_FLAG_ID
);
1538 dict_add(dict
, "PM_EVENT_FLAG_PARENT", PM_EVENT_FLAG_PARENT
);
1539 dict_add(dict
, "PM_EVENT_FLAG_MISSED", PM_EVENT_FLAG_MISSED
);
1542 * subset of the debug flags - all of 'em seems like overkill
1543 * order here the same as the output from pmdbg -l
1545 dict_add(dict
, "PM_DEBUG_APPL0", DBG_TRACE_APPL0
);
1546 dict_add(dict
, "PM_DEBUG_APPL1", DBG_TRACE_APPL1
);
1547 dict_add(dict
, "PM_DEBUG_APPL2", DBG_TRACE_APPL2
);
1550 * for ease of maintenance make the order of the error codes
1551 * here the same as the output from pmerr -l
1553 edict_add(dict
, edict
, "PM_ERR_GENERIC", PM_ERR_GENERIC
);
1554 edict_add(dict
, edict
, "PM_ERR_PMNS", PM_ERR_PMNS
);
1555 edict_add(dict
, edict
, "PM_ERR_NOPMNS", PM_ERR_NOPMNS
);
1556 edict_add(dict
, edict
, "PM_ERR_DUPPMNS", PM_ERR_DUPPMNS
);
1557 edict_add(dict
, edict
, "PM_ERR_TEXT", PM_ERR_TEXT
);
1558 edict_add(dict
, edict
, "PM_ERR_APPVERSION", PM_ERR_APPVERSION
);
1559 edict_add(dict
, edict
, "PM_ERR_VALUE", PM_ERR_VALUE
);
1560 edict_add(dict
, edict
, "PM_ERR_TIMEOUT", PM_ERR_TIMEOUT
);
1561 edict_add(dict
, edict
, "PM_ERR_NODATA", PM_ERR_NODATA
);
1562 edict_add(dict
, edict
, "PM_ERR_RESET", PM_ERR_RESET
);
1563 edict_add(dict
, edict
, "PM_ERR_NAME", PM_ERR_NAME
);
1564 edict_add(dict
, edict
, "PM_ERR_PMID", PM_ERR_PMID
);
1565 edict_add(dict
, edict
, "PM_ERR_INDOM", PM_ERR_INDOM
);
1566 edict_add(dict
, edict
, "PM_ERR_INST", PM_ERR_INST
);
1567 edict_add(dict
, edict
, "PM_ERR_TYPE", PM_ERR_TYPE
);
1568 edict_add(dict
, edict
, "PM_ERR_UNIT", PM_ERR_UNIT
);
1569 edict_add(dict
, edict
, "PM_ERR_CONV", PM_ERR_CONV
);
1570 edict_add(dict
, edict
, "PM_ERR_TRUNC", PM_ERR_TRUNC
);
1571 edict_add(dict
, edict
, "PM_ERR_SIGN", PM_ERR_SIGN
);
1572 edict_add(dict
, edict
, "PM_ERR_PROFILE", PM_ERR_PROFILE
);
1573 edict_add(dict
, edict
, "PM_ERR_IPC", PM_ERR_IPC
);
1574 edict_add(dict
, edict
, "PM_ERR_EOF", PM_ERR_EOF
);
1575 edict_add(dict
, edict
, "PM_ERR_NOTHOST", PM_ERR_NOTHOST
);
1576 edict_add(dict
, edict
, "PM_ERR_EOL", PM_ERR_EOL
);
1577 edict_add(dict
, edict
, "PM_ERR_MODE", PM_ERR_MODE
);
1578 edict_add(dict
, edict
, "PM_ERR_LABEL", PM_ERR_LABEL
);
1579 edict_add(dict
, edict
, "PM_ERR_LOGREC", PM_ERR_LOGREC
);
1580 edict_add(dict
, edict
, "PM_ERR_LOGFILE", PM_ERR_LOGFILE
);
1581 edict_add(dict
, edict
, "PM_ERR_NOTARCHIVE", PM_ERR_NOTARCHIVE
);
1582 edict_add(dict
, edict
, "PM_ERR_NOCONTEXT", PM_ERR_NOCONTEXT
);
1583 edict_add(dict
, edict
, "PM_ERR_PROFILESPEC", PM_ERR_PROFILESPEC
);
1584 edict_add(dict
, edict
, "PM_ERR_PMID_LOG", PM_ERR_PMID_LOG
);
1585 edict_add(dict
, edict
, "PM_ERR_INDOM_LOG", PM_ERR_INDOM_LOG
);
1586 edict_add(dict
, edict
, "PM_ERR_INST_LOG", PM_ERR_INST_LOG
);
1587 edict_add(dict
, edict
, "PM_ERR_NOPROFILE", PM_ERR_NOPROFILE
);
1588 edict_add(dict
, edict
, "PM_ERR_NOAGENT", PM_ERR_NOAGENT
);
1589 edict_add(dict
, edict
, "PM_ERR_PERMISSION", PM_ERR_PERMISSION
);
1590 edict_add(dict
, edict
, "PM_ERR_CONNLIMIT", PM_ERR_CONNLIMIT
);
1591 edict_add(dict
, edict
, "PM_ERR_AGAIN", PM_ERR_AGAIN
);
1592 edict_add(dict
, edict
, "PM_ERR_ISCONN", PM_ERR_ISCONN
);
1593 edict_add(dict
, edict
, "PM_ERR_NOTCONN", PM_ERR_NOTCONN
);
1594 edict_add(dict
, edict
, "PM_ERR_NEEDPORT", PM_ERR_NEEDPORT
);
1595 edict_add(dict
, edict
, "PM_ERR_NONLEAF", PM_ERR_NONLEAF
);
1596 edict_add(dict
, edict
, "PM_ERR_PMDAREADY", PM_ERR_PMDAREADY
);
1597 edict_add(dict
, edict
, "PM_ERR_PMDANOTREADY", PM_ERR_PMDANOTREADY
);
1598 edict_add(dict
, edict
, "PM_ERR_TOOSMALL", PM_ERR_TOOSMALL
);
1599 edict_add(dict
, edict
, "PM_ERR_TOOBIG", PM_ERR_TOOBIG
);
1600 edict_add(dict
, edict
, "PM_ERR_FAULT", PM_ERR_FAULT
);
1601 edict_add(dict
, edict
, "PM_ERR_THREAD", PM_ERR_THREAD
);
1602 edict_add(dict
, edict
, "PM_ERR_NOCONTAINER", PM_ERR_NOCONTAINER
);
1603 edict_add(dict
, edict
, "PM_ERR_BADSTORE", PM_ERR_BADSTORE
);
1604 edict_add(dict
, edict
, "PM_ERR_LOGOVERLAP", PM_ERR_LOGOVERLAP
);
1605 edict_add(dict
, edict
, "PM_ERR_LOGHOST", PM_ERR_LOGHOST
);
1606 edict_add(dict
, edict
, "PM_ERR_LOGCHANGETYPE", PM_ERR_LOGCHANGETYPE
);
1607 edict_add(dict
, edict
, "PM_ERR_LOGCHANGESEM", PM_ERR_LOGCHANGESEM
);
1608 edict_add(dict
, edict
, "PM_ERR_LOGCHANGEINDOM", PM_ERR_LOGCHANGEINDOM
);
1609 edict_add(dict
, edict
, "PM_ERR_LOGCHANGEUNITS", PM_ERR_LOGCHANGEUNITS
);
1610 edict_add(dict
, edict
, "PM_ERR_NEEDCLIENTCERT", PM_ERR_NEEDCLIENTCERT
);
1611 edict_add(dict
, edict
, "PM_ERR_NYI", PM_ERR_NYI
);
1613 return MOD_SUCCESS_VAL(module
);