'\"macro stdmacro
.\"
.\" Copyright (c) 2016,2022 Red Hat.
.\" Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
.\"
.\" 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 PMGETARCHIVELABEL 3 "PCP" "Performance Co-Pilot"
.SH NAME
\f3pmGetArchiveLabel\f1,
\f3pmGetHighResArchiveLabel\f1 \- fetch the label record from a set of performance metrics archive logs
.SH "C SYNOPSIS"
.ft 3
#include <pcp/pmapi.h>
.sp
.nf
int pmGetArchiveLabel(pmLogLabel *\fIlp\fP);
.br
int pmGetHighResArchiveLabel(pmHighResLogLabel *\fIlp\fP);
.fi
.sp
cc ... \-lpcp
.ft 1
.SH DESCRIPTION
.de CW
.ie t \f(CW\\$1\f1\\$2
.el \fI\\$1\f1\\$2
..
Within the framework of the
Performance Co-Pilot (PCP), archive logs of performance metrics
values may be accumulated and saved using the program
.BR pmlogger (1)
and the
.BR LOGIMPORT (3)
programming interface.
.PP
The routines
.B pmGetArchiveLabel
and
.B pmGetHighResArchiveLabel
may be used to fetch the label record from a set of archive logs
that has already been opened using
.BR pmNewContext (3),
or
.BR pmDupContext (3),
and thereby associated with the current
Performance Metrics Application Programming Interface (PMAPI)
context.
.PP
It is recommended that new applications use the high resolution API
and existing applications transition to this interface over time.
.PP
The result returned via the pointer
.I lp
is a structure that must be pre-allocated by the caller
and has one of the following two formats (defined in
.BR pmapi.h ).
.PP
.in +0.2i
.ft CW
.nf
typedef struct {
  int        magic;       /* PM_LOG_MAGIC | log format version no. */
  pid_t      pid;         /* PID of logger */
  struct timespec start;  /* start of this log */
  char       hostname[PM_MAX_HOSTNAMELEN];   /* collection host full name */
  char       timezone[PM_MAX_TIMEZONELEN];   /* generic, squashed $TZ */
  char       zoneinfo[PM_MAX_ZONEINFOLEN];   /* local platform $TZ */
} pmHighResLogLabel;

typedef struct {
  int        ll_magic;    /* PM_LOG_MAGIC | log format version no. */
  pid_t      ll_pid;      /* PID of logger */
  struct timeval ll_start;/* start of this log */
  char       ll_hostname[PM_LOG_MAXHOSTLEN]; /* name of collection host */
  char       ll_tz[40];   /* $TZ at collection host */
} pmLogLabel;
.fi
.ft 1
.in
.PP
Both forms can be used with either version 2 or version 3 archive logs.
However, the pmHighResLogLabel structure provides the higher resolution
start time stored in the newer format, as well as the full timezone and
extended length host name fields.
For detailed information about the log archive on-disk format, refer to
.BR LOGARCHIVE (5).
.PP
For an application using
.BR pmGetHighResArchiveLabel ,
the most useful information from the archive label
is likely to be in the fields
.CW start ,
.CW hostname ,
.CW timezone ,
and
.CW zoneinfo .
.PP
The
.CW zoneinfo
field contains the most detailed timezone information available,
and should be used if present (non-zero length string).
It will only not be present in the case of version 2 archives \-
this is a new field added as part of the version 3 format.
The
.CW timezone
field will always be present, however it is the 'squashed' timezone
value and in certain situations is not the most accurate timezone.
.PP
For older applications using
.BR pmGetArchiveLabel ,
the most useful information from the archive label
is likely to be in the fields
.CW ll_start ,
.CW ll_hostname
or
.CW ll_tz .
Note that the size of the
.CW ll_hostname
field is
.CW PM_LOG_MAXHOSTLEN
(64 bytes)
which is less than
.BR MAXHOSTNAMELEN
(see
.BR gethostbyname (3))
on some platforms.
These semantics are necessary to retain backwards compatibility with
the PCP archive file format.
.PP
Both
.B pmGetArchiveLabel
and
.B pmGetHighResArchiveLabel
return zero for success.
.SH DIAGNOSTICS
.IP \f3PM_ERR_NOCONTEXT\f1
the current PMAPI context
is either invalid, or not associated with a set of archive logs
.SH "PCP ENVIRONMENT"
Environment variables with the prefix
.B PCP_
are used to parameterize the file and directory names
used by PCP.
On each installation, the file
.I /etc/pcp.conf
contains the local values for these variables.
The
.B $PCP_CONF
variable may be used to specify an alternative
configuration file,
as described in
.BR pcp.conf (5).
Values for these variables may be obtained programmatically
using the
.BR pmGetConfig (3)
function.
.SH SEE ALSO
.BR pmlogger (1),
.BR LOGIMPORT (3),
.BR PMAPI (3),
.BR pmDupContext (3),
.BR pmGetConfig (3),
.BR pmNewContext (3),
.BR LOGARCHIVE (5),
.BR pcp.conf (5)
and
.BR pcp.env (5).