<commit_before>/*
This file is part of liblnxproc.

 liblnxproc 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 3 of the License, or
 (at your option) any later version.

 liblnxproc 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.

 You should have received a copy of the GNU General Public License
 along with liblnxproc.  If not, see <http://www.gnu.org/licenses/>.

 Copyright 2013 <NAME>, <EMAIL>

/proc/[pid]/statm
              Provides information about memory usage, measured in pages.  The columns are:

                  size       total program size
                             (same as VmSize in /proc/[pid]/status)
                  resident   resident set size
                             (same as VmRSS in /proc/[pid]/status)
                  share      shared pages (from shared mappings)
                  text       text (code)
                  lib        library (unused in Linux 2.6)
                  data       data + stack
                  dt         dirty pages (unused in Linux 2.6)

/proc/pid/statm:

5899 1235 471 225 0 761 0
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "strlcpy.h"
#include "error_private.h"
#include "limits_private.h"
#include "array_private.h"
#include "results_private.h"
#include "interface_private.h"
#include "base_private.h"
#include "modules.h"

static int
proc_pid_statm_normalize(_LNXPROC_BASE_T *base)
{
    _LNXPROC_BASE_DATA_T *data = base->current;
    _LNXPROC_RESULTS_T *results = data->results;
    _LNXPROC_ARRAY_T *array = data->array;

    size_t nrows = array->vector->length;

    _LNXPROC_DEBUG("Current data is %d at %p\n", data->id, data);
    _LNXPROC_DEBUG("Current results is at %p\n", results);
    _LNXPROC_DEBUG("Nrows %zd\n", nrows);
    char ***values = (char ***) array->vector->values;

    int i, j;

    static const char *colkey[] = {
        "size", "resident", "share", "test", "lib",
        "data", "dt",
    };
    char key[64];

    int n1 = 0;

    STRLCAT(key, "/", n1, sizeof(key));

    _lnxproc_results_init(results, nrows);
    for (i = 0; i < nrows; i++) {
        char **value1 = (char **) values[i];
        char *rowkey = value1[0];

        if (!rowkey)
            continue;

        size_t ncols = array->vector->children[i]->length;

        _LNXPROC_DEBUG("%d:ncols %zd\n", i, ncols);

        _LNXPROC_DEBUG("%d:Rowkey value %s\n", i, rowkey);
        int n2 = n1;

        STRLCAT(key, rowkey, n2, sizeof(key));
        STRLCAT(key, "/", n2, sizeof(key));

        for (j = 1; j < ncols; j++) {
            char *val = value1[j];

            if (!val)
                continue;

            int n3 = n2;

            STRLCAT(key, colkey[j - 1], n3, sizeof(key));

            int value = atoi(val) * results->page_size;

            _LNXPROC_DEBUG("%d,%d:%s value %s int %d\n", i, j, key, val, value);
            _lnxproc_results_add_int(results, key, value);
        }
    }

    return LNXPROC_OK;
}

int
_lnxproc_proc_pid_statm_new(_LNXPROC_BASE_T **base, LNXPROC_OPT_T *optional)
{

    _LNXPROC_LIMITS_T *limits = NULL;
    int ret = _lnxproc_limits_new(&limits, 2);

    if (ret) {
        return ret;
    }<commit_msg>proc_pid_statm - unsigned long values<commit_after>/*
This file is part of liblnxproc.

 liblnxproc 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 3 of the License, or
 (at your option) any later version.

 liblnxproc 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.

 You should have received a copy of the GNU General Public License
 along with liblnxproc.  If not, see <http://www.gnu.org/licenses/>.

 Copyright 2013 <NAME>, <EMAIL>

/proc/[pid]/statm
              Provides information about memory usage, measured in pages.  The columns are:

                  size       total program size
                             (same as VmSize in /proc/[pid]/status)
                  resident   resident set size
                             (same as VmRSS in /proc/[pid]/status)
                  share      shared pages (from shared mappings)
                  text       text (code)
                  lib        library (unused in Linux 2.6)
                  data       data + stack
                  dt         dirty pages (unused in Linux 2.6)

/proc/pid/statm:

5899 1235 471 225 0 761 0
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "strlcpy.h"
#include "error_private.h"
#include "limits_private.h"
#include "array_private.h"
#include "results_private.h"
#include "interface_private.h"
#include "base_private.h"
#include "modules.h"

static int
proc_pid_statm_normalize(_LNXPROC_BASE_T *base)
{
    _LNXPROC_BASE_DATA_T *data = base->current;
    _LNXPROC_RESULTS_T *results = data->results;
    _LNXPROC_ARRAY_T *array = data->array;

    size_t nrows = array->vector->length;

    _LNXPROC_DEBUG("Current data is %d at %p\n", data->id, data);
    _LNXPROC_DEBUG("Current results is at %p\n", results);
    _LNXPROC_DEBUG("Nrows %zd\n", nrows);
    char ***values = (char ***) array->vector->values;

    int i, j;

    static const char *colkey[] = {
        "size", "resident", "share", "test", "lib",
        "data", "dt",
    };
    char key[64];

    int n1 = 0;

    STRLCAT(key, "/", n1, sizeof(key));

    _lnxproc_results_init(results, nrows);
    for (i = 0; i < nrows; i++) {
        char **value1 = (char **) values[i];
        char *rowkey = value1[0];

        if (!rowkey)
            continue;

        size_t ncols = array->vector->children[i]->length;

        _LNXPROC_DEBUG("%d:ncols %zd\n", i, ncols);

        _LNXPROC_DEBUG("%d:Rowkey value %s\n", i, rowkey);
        int n2 = n1;

        STRLCAT(key, rowkey, n2, sizeof(key));
        STRLCAT(key, "/", n2, sizeof(key));

        for (j = 1; j < ncols; j++) {
            char *val = value1[j];

            if (!val)
                continue;

            int n3 = n2;

            STRLCAT(key, colkey[j - 1], n3, sizeof(key));

            unsigned long value = strtoul(val, NULL, 0) * results->page_size;

            _LNXPROC_DEBUG("%d,%d:%s value %s int %lu\n", i, j, key, val,
                           value);
            _lnxproc_results_add_unsigned_long(results, key, value);
        }
    }

    return LNXPROC_OK;
}

int
_lnxproc_proc_pid_statm_new(_LNXPROC_BASE_T **base, LNXPROC_OPT_T *optional)
{

    _LNXPROC_LIMITS_T *limits = NULL;
    int ret = _lnxproc_limits_new(&limits, 2);

    if (ret) {
        return ret;
    }
{'fraction_non_alphanumeric': 0.11470504417212882, 'fraction_numerical': 0.013821601595896267, 'mean_word_length': 2.3077285579641846, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3473650', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2229, 'n_words': 698}