本文整理汇总了C++中pmErrStr函数的典型用法代码示例。如果您正苦于以下问题:C++ pmErrStr函数的具体用法?C++ pmErrStr怎么用?C++ pmErrStr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pmErrStr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rawlocalhost
static char *
rawlocalhost(pmOptions *opts)
{
int ctxt;
char *host;
if (opts->nhosts > 0)
return opts->hosts[0];
if ((ctxt = pmNewContext(PM_CONTEXT_LOCAL, NULL)) < 0)
{
fprintf(stderr, "%s: cannot create local context: %s\n",
pmProgname, pmErrStr(ctxt));
cleanstop(1);
}
host = (char *)pmGetContextHostName(ctxt);
pmDestroyContext(ctxt);
if (host[0] == '\0')
{
fprintf(stderr, "%s: cannot find local hostname\n", pmProgname);
cleanstop(1);
}
return host;
}
示例2: darwin_init
void
darwin_init(pmdaInterface *dp)
{
int sts;
if (_isDSO) {
int sep = __pmPathSeparator();
char helppath[MAXPATHLEN];
sprintf(helppath, "%s%c" "darwin" "%c" "help",
pmGetConfig("PCP_PMDAS_DIR"), sep, sep);
pmdaDSO(dp, PMDA_INTERFACE_3, "darwin DSO", helppath);
} else {
__pmSetProcessIdentity(username);
}
if (dp->status != 0)
return;
dp->version.two.instance = darwin_instance;
dp->version.two.fetch = darwin_fetch;
pmdaSetFetchCallBack(dp, darwin_fetchCallBack);
pmdaSetFlags(dp, PMDA_EXT_FLAG_DIRECT);
pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]),
metrictab, sizeof(metrictab)/sizeof(metrictab[0]));
mach_host = mach_host_self();
host_page_size(mach_host, &mach_page_size);
mach_page_shift = ffs(mach_page_size) - 1;
if (refresh_hertz(&mach_hertz) != 0)
mach_hertz = 100;
if ((sts = refresh_hinv()) != 0)
fprintf(stderr, "darwin_init: refresh_hinv failed: %s\n", pmErrStr(sts));
init_network();
}
示例3: mounts_config_file_check
static void
mounts_config_file_check(void)
{
struct stat statbuf;
static int last_error;
int sep = __pmPathSeparator();
snprintf(mypath, sizeof(mypath), "%s%c" "mounts" "%c" "mounts.conf",
pmGetConfig("PCP_PMDAS_DIR"), sep, sep);
if (stat(mypath, &statbuf) == -1) {
if (oserror() != last_error) {
last_error = oserror();
__pmNotifyErr(LOG_WARNING, "stat failed on %s: %s\n",
mypath, pmErrStr(last_error));
}
} else {
last_error = 0;
#if defined(HAVE_ST_MTIME_WITH_E)
if (statbuf.st_mtime != file_change.st_mtime)
#elif defined(HAVE_ST_MTIME_WITH_SPEC)
if (statbuf.st_mtimespec.tv_sec != file_change.st_mtimespec.tv_sec ||
statbuf.st_mtimespec.tv_nsec != file_change.st_mtimespec.tv_nsec)
#else
if (statbuf.st_mtim.tv_sec != file_change.st_mtim.tv_sec ||
statbuf.st_mtim.tv_nsec != file_change.st_mtim.tv_nsec)
#endif
{
mounts_clear_config_info();
mounts_grab_config_info();
file_change = statbuf;
}
}
}
示例4: setup_origin
/*
* Set the origin position and interval for PMAPI context fetching
*/
static int
setup_origin(pmOptions *opts)
{
int sts = 0;
curtime = origin = opts->origin;
/* initial archive mode, position and delta */
if (opts->context == PM_CONTEXT_ARCHIVE)
{
if (opts->interval.tv_sec || opts->interval.tv_usec)
interval = opts->interval;
setup_step_mode(opts, 1);
if ((sts = pmSetMode(fetchmode, &curtime, fetchstep)) < 0)
{
pmprintf(
"%s: pmSetMode failure: %s\n", pmProgname, pmErrStr(sts));
opts->flags |= PM_OPTFLAG_RUNTIME_ERR;
opts->errors++;
}
}
return sts;
}
示例5: fetch_metrics
int
fetch_metrics(const char *purpose, int nmetrics, pmID *pmids, pmResult **result)
{
int sts;
pmSetMode(fetchmode, &curtime, fetchstep);
if ((sts = pmFetch(nmetrics, pmids, result)) < 0)
{
if (sts != PM_ERR_EOL)
fprintf(stderr, "%s: %s query: %s\n",
pmProgname, purpose, pmErrStr(sts));
cleanstop(1);
}
if (pmDebug & DBG_TRACE_APPL1)
{
pmResult *rp = *result;
struct tm tmp;
time_t sec;
sec = (time_t)rp->timestamp.tv_sec;
pmLocaltime(&sec, &tmp);
fprintf(stderr, "%s: got %d %s metrics @%02d:%02d:%02d.%03d\n",
pmProgname, rp->numpmid, purpose,
tmp.tm_hour, tmp.tm_min, tmp.tm_sec,
(int)(rp->timestamp.tv_usec / 1000));
}
return sts;
}
示例6: SignalReloadPMNS
static void
SignalReloadPMNS(void)
{
int sts;
/* Reload PMNS if necessary.
* Note: this will only stat() the base name i.e. ASCII pmns,
* typically $PCP_VAR_DIR/pmns/root and not $PCP_VAR_DIR/pmns/root.bin .
* This is considered a very low risk problem, as the binary
* PMNS is always compiled from the ASCII version;
* when one changes so should the other.
* This caveat was allowed to make the code a lot simpler.
*/
if (__pmHasPMNSFileChanged(pmnsfile)) {
__pmNotifyErr(LOG_INFO, "Reloading PMNS \"%s\"",
(pmnsfile==PM_NS_DEFAULT)?"DEFAULT":pmnsfile);
pmUnloadNameSpace();
sts = pmLoadASCIINameSpace(pmnsfile, dupok);
if (sts < 0) {
__pmNotifyErr(LOG_ERR, "pmLoadASCIINameSpace(%s, %d): %s\n",
(pmnsfile == PM_NS_DEFAULT) ? "DEFAULT" : pmnsfile, dupok, pmErrStr(sts));
}
}
else {
__pmNotifyErr(LOG_INFO, "PMNS file \"%s\" is unchanged",
(pmnsfile == PM_NS_DEFAULT) ? "DEFAULT" : pmnsfile);
}
}
示例7: dometric
/*
* with -e come here for every metric in the PMNS ...
*/
void
dometric(const char *name)
{
int sts;
pmID pmid;
char *tp;
sts = pmLookupName(1, (char **)&name, &pmid);
if (sts < 0) {
fprintf(stderr, "pmLookupName: failed for \"%s\": %s\n", name, pmErrStr(sts));
return;
}
if (sts == 0) {
fprintf(stderr, "pmLookupName: failed for \"%s\"\n", name);
return;
}
tp = pmdaGetHelp(handle, pmid, PM_TEXT_ONELINE);
if (tp != NULL)
return;
tp = pmdaGetHelp(handle, pmid, PM_TEXT_HELP);
if (tp != NULL)
return;
/* no help text, report metric */
printf("%s\n", name);
}
示例8: func2
static void *
func2(void *arg)
{
char *fn = "func2";
int i;
int j;
FILE *f;
if ((f = fopen("/tmp/func2.out", "w")) == NULL) {
perror("func2 fopen");
pthread_exit("botch");
}
j = pmUseContext(ctx2);
if ( j < 0) {
fprintf(f, "Error: %s: pmUseContext(%d) -> %s\n", fn, ctx2, pmErrStr(j));
fclose(f);
pthread_exit("botch");
}
pthread_barrier_wait(&barrier);
for (j = 0; j < 100; j++) {
for (i = NMETRIC-1; i >= 0; i--)
foo(f, fn, i);
}
fclose(f);
pthread_exit(NULL);
}
示例9: _e
static void
_e(int since)
{
int i;
int j;
int sts;
int inst;
indom = pmInDom_build(FORQA, 11);
sts = pmdaCacheOp(indom, PMDA_CACHE_LOAD);
if (sts < 0) {
fprintf(stderr, "PMDA_CACHE_LOAD failed: %s\n", pmErrStr(sts));
return;
}
j = 1;
for (i = 0; i < 10; i++) {
pmsprintf(nbuf, sizeof(nbuf), "boring-instance-%03d", i);
inst = pmdaCacheStore(indom, PMDA_CACHE_ADD, nbuf, (void *)((__psint_t)(0xcaffe000+i)));
if (inst < 0)
fprintf(stderr, "PMDA_CACHE_ADD failed for \"%s\": %s\n", nbuf, pmErrStr(inst));
if (i == j) {
j <<= 1;
inst = pmdaCacheStore(indom, PMDA_CACHE_HIDE, nbuf, NULL);
if (inst < 0)
fprintf(stderr, "PMDA_CACHE_HIDE failed for \"%s\": %s\n", nbuf, pmErrStr(inst));
}
}
sts = pmdaCacheOp(indom, PMDA_CACHE_SAVE);
fprintf(stderr, "Save -> %d\n", sts);
fprintf(stderr, "Before purge ...\n");
__pmdaCacheDump(stderr, indom, 0);
sleep(1);
sts = pmdaCachePurge(indom, since);
if (sts < 0) {
fprintf(stderr, "pmdaCachePurge failed: %s\n", pmErrStr(sts));
return;
}
fprintf(stderr, "Purged %d entries\nAfter purge ...\n", sts);
sts = pmdaCacheOp(indom, PMDA_CACHE_SAVE);
fprintf(stderr, "Save -> %d\n", sts);
__pmdaCacheDump(stderr, indom, 0);
}
示例10: main
int
main(int argc, char **argv)
{
char *msg;
char buffer[512];
__pmHashCtl attrs;
pmHostSpec *hosts;
int count, sts, i, j;
if (argc != 2) {
fprintf(stderr, "Usage: parsehostattrs spec\n");
exit(1);
}
__pmHashInit(&attrs);
printf("pmParseHostAttrsSpec(\"%s\", ...)\n", argv[1]);
sts = __pmParseHostAttrsSpec(argv[1], &hosts, &count, &attrs, &msg);
if (sts < 0) {
if (sts == PM_ERR_GENERIC)
printf("pmParseHostAttrsSpec error:\n%s\n", msg);
else
printf("Error: %s\n", pmErrStr(sts));
exit(1);
}
for (i = 0; i < count; i++) {
printf("host[%d]: \"%s\"", i, hosts[i].name);
if (hosts[i].nports == 1)
printf(" port:");
else if (hosts[i].nports > 1)
printf(" ports:");
for (j = 0; j < hosts[i].nports; j++)
printf(" %d", hosts[i].ports[j]);
putchar('\n');
}
__pmHashWalkCB(print_attribute, NULL, &attrs);
sts = __pmUnparseHostAttrsSpec(hosts, count, &attrs, buffer, sizeof(buffer));
if (sts < 0) {
printf("pmUnparseHostAttrsSpec: %s\n", pmErrStr(sts));
exit(1);
}
printf("pmUnparseHostAttrsSpec(\"%s\") -> \"%s\"\n", argv[1], buffer);
__pmFreeHostAttrsSpec(hosts, count, &attrs);
__pmHashClear(&attrs);
exit(0);
}
示例11: refresh_net_dev_hw_addr
static int
refresh_net_dev_hw_addr(pmInDom indom)
{
int sts;
DIR *dp;
char *devname;
struct dirent *dentry;
char path[MAXPATHLEN];
net_addr_t *netip;
static uint32_t cache_err;
snprintf(path, sizeof(path), "%s/sys/class/net", linux_statspath);
if ((dp = opendir(path)) != NULL) {
while ((dentry = readdir(dp)) != NULL) {
if (dentry->d_name[0] == '.')
continue;
devname = dentry->d_name;
sts = pmdaCacheLookupName(indom, devname, NULL, (void **)&netip);
if (sts == PM_ERR_INST || (sts >= 0 && netip == NULL)) {
/* first time since re-loaded, else new one */
netip = (net_addr_t *)calloc(1, sizeof(net_addr_t));
}
else if (sts < 0) {
if (cache_err++ < 10) {
fprintf(stderr, "refresh_net_dev_hw_addr: "
"pmdaCacheLookupName(%s, %s, ...) failed: %s\n",
pmInDomStr(indom), devname, pmErrStr(sts));
}
continue;
}
if ((sts = pmdaCacheStore(indom, PMDA_CACHE_ADD, devname, (void *)netip)) < 0) {
if (cache_err++ < 10) {
fprintf(stderr, "refresh_net_dev_hw_addr: "
"pmdaCacheStore(%s, PMDA_CACHE_ADD, %s, "
PRINTF_P_PFX "%p) failed: %s\n",
pmInDomStr(indom), devname, netip, pmErrStr(sts));
}
continue;
}
refresh_net_hw_addr(devname, netip);
}
closedir(dp);
}
return 0;
}
示例12: main
int
main(int argc, char *argv[])
{
int ctx;
int sts;
char buf[1024];
char *name = buf;
char *p;
pmID pmid;
pmDesc desc;
ctx = pmNewContext(PM_CONTEXT_HOST, "local:");
if (ctx < 0) {
fprintf(stderr, "Error: pmNewContext %s\n", pmErrStr(ctx));
exit(1);
}
printf("/* This file is automatically generated .. do not edit! */\n");
printf("#include \"metrics.h\"\n\n");
printf("metric_t metrics[] = {\n");
while (fgets(buf, sizeof(buf), stdin)) {
if ((p = strrchr(buf, '\n')) != NULL)
*p = '\0';
if ((sts = pmLookupName(1, &name, &pmid)) < 0) {
fprintf(stderr, "Error: pmLookupName \"%s\": %s\n", name, pmErrStr(sts));
exit(1);
}
if ((sts = pmLookupDesc(pmid, &desc)) < 0) {
fprintf(stderr, "Error: pmLookupDesc \"%s\": %s\n", name, pmErrStr(sts));
exit(1);
}
printf(" /* %-8s */ { \"%s\", { 0x%04x, PM_TYPE_%s, %s, %s,\n"
" { .dimSpace=%d, .dimTime=%d, .dimCount=%d, "
".scaleSpace=%d, .scaleTime=%d, .scaleCount=%d } } },\n",
pmIDStr(desc.pmid), name, desc.pmid, pmTypeStr(desc.type),
indomStr(desc.indom), semStr[desc.sem], desc.units.dimSpace,
desc.units.dimTime, desc.units.dimCount, desc.units.scaleSpace,
desc.units.scaleTime, desc.units.scaleCount);
}
printf(" { NULL }\n};\n");
exit(0);
}
示例13: traverse
static int
traverse(const char *str, double scale)
{
pmMetricSpec *theMetric;
char *msg;
int sts = 0;
sts = pmParseMetricSpec((char *)str, 0, (char *)0, &theMetric, &msg);
if (sts < 0) {
pmprintf("%s: Error: Unable to parse metric spec:\n%s\n",
pmProgname, msg);
free(msg);
return sts;
}
// If the metric has instances, then it cannot be traversed
if (theMetric->ninst) {
QmcMetric *metric = group->addMetric(theMetric, scale);
if (metric->status() >= 0) {
checkUnits(metric);
metrics.append(metric);
numValues += metric->numValues();
}
else
sts = -1;
}
else {
if (theMetric->isarch == 0)
doMetricType = PM_CONTEXT_HOST;
else if (theMetric->isarch == 1)
doMetricType = PM_CONTEXT_ARCHIVE;
else if (theMetric->isarch == 2)
doMetricType = PM_CONTEXT_LOCAL;
else {
pmprintf("%s: Error: invalid metric source (%d): %s\n",
pmProgname, theMetric->isarch, theMetric->metric);
sts = -1;
}
doMetricSource = theMetric->source;
if (sts >= 0)
sts = group->use(doMetricType, doMetricSource);
if (sts >= 0) {
doMetricScale = scale;
sts = pmTraversePMNS(theMetric->metric, dometric);
if (sts >= 0 && doMetricFlag == false)
sts = -1;
else if (sts < 0) {
pmprintf("%s: Error: %s: %s\n",
pmProgname, theMetric->metric, pmErrStr(sts));
}
}
}
free(theMetric);
return sts;
}
示例14: mydump
static void
mydump(const char *name, pmDesc *dp, pmValueSet *vsp)
{
int j;
char *p;
if (vsp->numval == 0) {
if (verbose)
printf("%s: No value(s) available!\n", name);
return;
}
else if (vsp->numval < 0) {
printf("%s: Error: %s\n", name, pmErrStr(vsp->numval));
return;
}
printf(" %s", name);
for (j = 0; j < vsp->numval; j++) {
pmValue *vp = &vsp->vlist[j];
if (dp->indom != PM_INDOM_NULL) {
if (vsp->numval > 1)
printf("\n ");
if ((p = lookup(dp->indom, vp->inst)) == NULL)
printf("[%d]", vp->inst);
else
printf("[\"%s\"]", p);
}
putchar(' ');
switch (dp->type) {
case PM_TYPE_AGGREGATE:
case PM_TYPE_AGGREGATE_STATIC: {
/*
* pinched from pmPrintValue, just without the preamble of
* floating point values
*/
char *p;
int i;
putchar('[');
p = &vp->value.pval->vbuf[0];
for (i = 0; i < vp->value.pval->vlen - PM_VAL_HDR_SIZE; i++, p++)
printf("%02x", *p & 0xff);
putchar(']');
putchar('\n');
break;
}
case PM_TYPE_EVENT:
case PM_TYPE_HIGHRES_EVENT:
/* odd, nested event type! */
myeventdump(vsp, j, dp->type != PM_TYPE_EVENT);
break;
default:
pmPrintValue(stdout, vsp->valfmt, dp->type, vp, 1);
putchar('\n');
}
}
}
示例15: setup_context
/*
* PMAPI context creation and initial command line option handling.
*/
static int
setup_context(pmOptions *opts)
{
char *source;
int sts, ctx;
if (opts->context == PM_CONTEXT_ARCHIVE)
source = opts->archives[0];
else if (opts->context == PM_CONTEXT_HOST)
source = opts->hosts[0];
else if (opts->context == PM_CONTEXT_LOCAL)
source = NULL;
else
{
opts->context = PM_CONTEXT_HOST;
source = "local:";
}
if ((sts = ctx = pmNewContext(opts->context, source)) < 0)
{
if (opts->context == PM_CONTEXT_HOST)
pmprintf(
"%s: Cannot connect to pmcd on host \"%s\": %s\n",
pmProgname, source, pmErrStr(sts));
else if (opts->context == PM_CONTEXT_LOCAL)
pmprintf(
"%s: Cannot make standalone connection on localhost: %s\n",
pmProgname, pmErrStr(sts));
else
pmprintf(
"%s: Cannot open archive \"%s\": %s\n",
pmProgname, source, pmErrStr(sts));
}
else if ((sts = pmGetContextOptions(ctx, opts)) == 0)
sts = setup_origin(opts);
if (sts < 0)
{
pmflush();
cleanstop(1);
}
return ctx;
}