<commit_before>/*
 * Copyright (c) 1995-2000,2009 Silicon Graphics, Inc. All Rights Reserved.
 * Copyright (c) 2009 Aconex. 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.
 *
 *
 * MMV PMDA
 *
 * This PMDA uses specially formatted files in either /var/tmp/mmv or 
 * some other directory, as specified on the command line. Each file represent
 * a separate "cluster" of values with flat name structure for each cluster.
 * names for the metrics are prepended with mmv and name of the file.
 */

#include "pmapi.h"
#include "impl.h"
#include "pmda.h"
#include "mmv_stats.h"
#include "./domain.h"
#include <sys/stat.h>

static pmdaInterface	dispatch;

static pmdaMetric * metrics;
static int mcnt;
static pmdaIndom * indoms;
static int incnt;
static int reload;

static time_t conf_ts = -1;         /* last mmv.conf timestamp */
static time_t statsdir_ts = -1;     /* last statsdir timestamp */

static char *pcptmpdir;		/* probably /var/tmp */
static char *pcpvardir;		/* probably /var/pcp */
static char *pcppmdasdir;	/* probably /var/pcp/pmdas */
static char pmnsdir[MAXPATHLEN];   /* pcpvardir/pmns */
static char statsdir[MAXPATHLEN];   /* pcptmpdir/mmv */
static char confpath[MAXPATHLEN];   /* pcppmdasdir/mmv/mmv.conf */

static struct stats_s {
    char *	name;		/* strdup client name */
    void *	addr;		/* mmap */
    mmv_stats_hdr_t *	hdr;	/* header in mmap */
    mmv_stats_value_t *	values;	/* values in mmap */
    __int64_t *	extra;		/* per value value. holds old DISCRETE value */
    int		vcnt;		/* number of values */
    int		fd;		/* mmap fd */
    int		len;		/* mmap region len */
    time_t	ts;		/* mmap file timestamp */
    int		moff;		/* Index of the first metric in the array */
    int		mcnt;		/* How many metrics have we got */
    int		cluster;	/* cluster id */
    __uint64_t	gen;		/* generation number on open */
} * slist;

static int scnt;

static int
update_names(void)
{
    char script[MAXPATHLEN];
    int sep = __pmPathSeparator();

    snprintf (script, sizeof(script),
		"%s%c" "lib" "%c" "ReplacePmnsSubtree mmv %s%c" "mmv.new",
		pmGetConfig("PCP_SHARE_DIR"), sep, sep, pcppmdasdir, sep);
    if (system (script) == -1) {
	__pmNotifyErr (LOG_ERR, "%s: cannot exec %s", pmProgname, script);
	return 1;
    }
    return 0;
}

static void
map_stats(void)
{
    char path[MAXPATHLEN], tmppath[MAXPATHLEN];
    char * fname;
    FILE *f = NULL;
    FILE * conf;
    int sep = __pmPathSeparator();
    int i;
 
    putenv("TMPDIR=");	/* temp file must be in pmnsdir, for rename */

#if HAVE_MKSTEMP
    sprintf(tmppath, "%s%cmmv-XXXXXX", pmnsdir, __pmPathSeparator());
    fname = tmppath;
    i = mkstemp(fname);
    if (i != -1)
	f = fdopen(i, "w");<commit_msg>Fix update_names routine in pmdammv, regressed recently.<commit_after>/*
 * Copyright (c) 1995-2000,2009 Silicon Graphics, Inc. All Rights Reserved.
 * Copyright (c) 2009 Aconex. 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.
 *
 *
 * MMV PMDA
 *
 * This PMDA uses specially formatted files in either /var/tmp/mmv or 
 * some other directory, as specified on the command line. Each file represent
 * a separate "cluster" of values with flat name structure for each cluster.
 * names for the metrics are prepended with mmv and name of the file.
 */

#include "pmapi.h"
#include "impl.h"
#include "pmda.h"
#include "mmv_stats.h"
#include "./domain.h"
#include <sys/stat.h>

static pmdaInterface	dispatch;

static pmdaMetric * metrics;
static int mcnt;
static pmdaIndom * indoms;
static int incnt;
static int reload;

static time_t conf_ts = -1;         /* last mmv.conf timestamp */
static time_t statsdir_ts = -1;     /* last statsdir timestamp */

static char *pcptmpdir;		/* probably /var/tmp */
static char *pcpvardir;		/* probably /var/pcp */
static char *pcppmdasdir;	/* probably /var/pcp/pmdas */
static char pmnsdir[MAXPATHLEN];   /* pcpvardir/pmns */
static char statsdir[MAXPATHLEN];   /* pcptmpdir/mmv */
static char confpath[MAXPATHLEN];   /* pcppmdasdir/mmv/mmv.conf */

static struct stats_s {
    char *	name;		/* strdup client name */
    void *	addr;		/* mmap */
    mmv_stats_hdr_t *	hdr;	/* header in mmap */
    mmv_stats_value_t *	values;	/* values in mmap */
    __int64_t *	extra;		/* per value value. holds old DISCRETE value */
    int		vcnt;		/* number of values */
    int		fd;		/* mmap fd */
    int		len;		/* mmap region len */
    time_t	ts;		/* mmap file timestamp */
    int		moff;		/* Index of the first metric in the array */
    int		mcnt;		/* How many metrics have we got */
    int		cluster;	/* cluster id */
    __uint64_t	gen;		/* generation number on open */
} * slist;

static int scnt;

static int
update_names(void)
{
    char script[MAXPATHLEN];
    int sep = __pmPathSeparator();

    snprintf (script, sizeof(script),
		"%s%c" "lib" "%c" "ReplacePmnsSubtree mmv %s%c" "mmv.new",
		pmGetConfig("PCP_SHARE_DIR"), sep, sep, pmnsdir, sep);
    if (system (script) == -1) {
	__pmNotifyErr (LOG_ERR, "%s: cannot exec %s", pmProgname, script);
	return 1;
    }
    snprintf (script, sizeof(script),
		"%s%c" "pmsignal -a -s HUP pmcd",
		pmGetConfig("PCP_BINADM_DIR"), sep);
    if (system (script) == -1) {
	__pmNotifyErr (LOG_ERR, "%s: cannot exec %s", pmProgname, script);
	return 1;
    }
    return 0;
}

static void
map_stats(void)
{
    char path[MAXPATHLEN], tmppath[MAXPATHLEN];
    char * fname;
    FILE *f = NULL;
    FILE * conf;
    int sep = __pmPathSeparator();
    int i;
 
    putenv("TMPDIR=");	/* temp file must be in pmnsdir, for rename */

#if HAVE_MKSTEMP
    sprintf(tmppath, "%s%cmmv-XXXXXX", pmnsdir, __pmPathSeparator());
    fname = tmppath;
    i = mkstemp(fname);
    if (i != -1)
	f = fdopen(i, "w");
{'fraction_non_alphanumeric': 0.11661631419939578, 'fraction_numerical': 0.008459214501510574, 'mean_word_length': 3.203809523809524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2182620', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2278, 'n_words': 791}