'\"macro stdmacro .\" .\" Copyright (c) 2010 Ken McDonell. All Rights Reserved. .\" Copyright (c) 2018,2022 Red Hat. .\" .\" This program is free software; you can redistribute it and/or modify it .\" under the terms of the GNU General Public License as published by the .\" Free Software Foundation; either version 2 of the License, or (at your .\" option) any later version. .\" .\" This program is distributed in the hope that it will be useful, but .\" WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY .\" or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License .\" for more details. .\" .\" .TH PMISTART 3 "" "Performance Co-Pilot" .SH NAME \f3pmiStart\f1 \- establish a new LOGIMPORT context .SH "C SYNOPSIS" .ft 3 .ad l .hy 0 #include .br #include .sp int pmiStart(const char *\fIarchive\fP, int \fIflags\fP); .sp cc ... \-lpcp_import \-lpcp .hy .ad .ft 1 .SH "Perl SYNOPSIS" .ft 3 .ad l .hy 0 use PCP::LogImport; .sp pmiStart($\fIarchive\fP, $\fIflags\fP); .hy .ad .ft 1 .SH "Python SYNOPSIS" .ft 3 .ad l .hy 0 from pcp import pmi .sp log = pmi.pmiLogImport(\fIarchive\fP, \fIflags\fP) .hy .ad .ft 1 .SH DESCRIPTION As part of the Performance Co-Pilot Log Import API (see .BR LOGIMPORT (3)), .B pmiStart creates a new context. Each context maintains the following state and metadata: .IP \(bu 3n The base name (\c .IR archive ) for the physical files that constitute the output PCP archive. .IP \(bu 3n The source hostname for the data that will be written to the PCP archive. Defaults to the hostname of the localhost, but can be set using .BR pmiSetHostname (3). .IP \(bu 3n The source timezone for the PCP archive. Defaults to the timezone of the localhost, but can be set using .BR pmiSetTimezone (3). .IP \(bu 3n The output archive version number for the PCP archive. Defaults to the traditional version 2 format, but can be set using .BR pmiSetVersion (3). .IP \(bu 3n Metrics and instance domains, as defined by .BR pmiAddMetric (3). .IP \(bu 3n Instances for each instance domain, as defined by .BR pmiAddInstance (3). .IP \(bu 3n Handles as defined by .BR pmiGetHandle (3). Each handle is a metric-instance pair, and each metric-instance pair may have an associated value in each record written to the output PCP archive. .IP \(bu 3n An optional set of data values for one or more metric-instance pairs (ready for the next record to be written to the output PCP archive) as defined by calls to .BR pmiPutValue (3) or .BR pmiPutValueHandle (3). .PP The .I flags argument is a bitwise-OR of zero or more of the following constants: .TP .B PMI_INHERIT The new context will inherit any and all metadata (metrics, instance domains, instances and handles) from the current context. The basename for the output PCP archive, the source hostname, the source timezone and any data values from the current context are .B not inherited. If this is the first call to .B pmiStart the metadata will be empty independent of whether .B PMI_INHERIT is set. .TP .B PMI_APPEND Open an existing PCP archive for appending rather than creating a new one. The archive label (hostname, timezone, version, start timestamp) is read from the existing .IR archive .meta file and used to initialise the new context. The temporal index is read to seed the last-written timestamp; all subsequent .BR pmiWrite (3) calls must use timestamps strictly later than this value. The .IR archive .meta and .IR archive .index files are opened in read/write mode and positioned at end-of-file; the highest-numbered data volume is opened in append mode. Metrics and instance domains must still be registered via .BR pmiAddMetric (3) and .BR pmiAddInstance (3) before calling .BR pmiPutValue (3) \(em if the metric descriptor is already present in the archive the duplicate entry in .I archive .meta is harmless and will be ignored by readers. If the archive files do not yet exist, .B PMI_APPEND behaves identically to creating a new archive (no flags). .PP .B PMI_APPEND and .B PMI_INHERIT may be used together. The inherited metric and instance-domain definitions are carried into the new context, and when the archive is opened on the first .BR pmiWrite (3) call, each inherited descriptor is checked against what is already on disk: compatible descriptors are silently skipped (no duplicate written); incompatible ones are rejected with an appropriate error (e.g. .BR PM_ERR_LOGCHANGETYPE ). When the previous context was writing to the same archive, every inherited descriptor already exists on disk so the combination is effectively a no-op beyond convenience. .PP If .I flags is zero, or neither .B PMI_INHERIT nor .B PMI_APPEND is set, the new context is created with no metadata and a new archive will be created from scratch. .PP Since no physical files for the output PCP archive will be created until the first call to .BR pmiWrite (3) or .BR pmiPutResult(3), .I archive could be NULL to create a convenience context that is populated with metadata to be inherited by subsequent contexts. .PP The return value is a context identifier that could be used in a subsequent call to .BR pmUseContext (3) and the new context becomes the current context which persists for all subsequent calls up to either another .B pmiStart call or a call to .BR pmiUseContext (3) or a call to .BR pmiEnd (3). .SH DIAGNOSTICS When creating a new archive (neither .B PMI_APPEND nor any other flag that implies file creation), it is an error if the physical files \fIarchive\fR.\fB0\fR and/or \fIarchive\fR.\fBindex\fR and/or \fIarchive\fR.\fBmeta\fR already exist, but this is not discovered until the first attempt is made to output some data by calling .BR pmiWrite (3) or .BR pmiPutResult(3), so .B pmiStart always returns a positive context identifier. .PP When .B PMI_APPEND is set and the archive files do not exist, .B pmiStart silently falls back to creating a new archive, making it safe to use .B PMI_APPEND unconditionally on the first invocation of a data collector. .SH SEE ALSO .BR LOGIMPORT (3), .BR PMAPI (3), .BR pmiAddInstance (3), .BR pmiAddMetric (3), .BR pmiEnd (3), .BR pmiErrStr (3), .BR pmiGetHandle (3), .BR pmiPutLabel (3), .BR pmiPutResult (3), .BR pmiPutText (3), .BR pmiPutValue (3), .BR pmiPutValueHandle (3), .BR pmiSetHostname (3), .BR pmiSetTimezone (3), .BR pmiSetVersion (3), .BR pmiUseContext (3) and .BR pmiWrite (3).