<commit_before>/*
 * CPU usage plugin to fbpanel
 *
 * Copyright (C) 2004 by <NAME> <<EMAIL>>
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 */
/*A little bug fixed by Mykola <<EMAIL>>:) */


#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <sys/sysinfo.h>
#include <stdlib.h>

#include "misc.h"
#include "../chart/chart.h"

//#define DEBUG
#include "dbg.h"



/* cpu.c */
struct cpu_stat {
    gulong u, n, s, i;
};

typedef struct {
    chart_t chart;
    struct cpu_stat cpu_prev;
    int timer;
} cpu_t;

static chart_class_t *k;

static int
cpu_get_load(cpu_t *c)
{
    gfloat a, b;
    struct cpu_stat cpu, cpu_diff;
    FILE *stat;
    float total;

    ENTER;
    stat = fopen("/proc/stat", "r");
    if(!stat)
        RET(TRUE);
    fscanf(stat, "cpu %lu %lu %lu %lu", &cpu.u, &cpu.n, &cpu.s, &cpu.i);
    fclose(stat);

    cpu_diff.u = cpu.u - c->cpu_prev.u;
    cpu_diff.n = cpu.n - c->cpu_prev.n;
    cpu_diff.s = cpu.s - c->cpu_prev.s;
    cpu_diff.i = cpu.i - c->cpu_prev.i;
    c->cpu_prev = cpu;

    a = cpu_diff.u + cpu_diff.n + cpu_diff.s;
    b = a + cpu_diff.i;
    total = b ?  a / b : 1.0;
    DBG("total=%f a=%f b=%f\n", total, a, b);
    k->add_tick(&c->chart, &total);
    RET(TRUE);

}


static int
cpu_constructor(plugin *p)<commit_msg>acounting cpu wait time in load calculation<commit_after>/*
 * CPU usage plugin to fbpanel
 *
 * Copyright (C) 2004 by <NAME> <<EMAIL>>
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 */
/*A little bug fixed by Mykola <<EMAIL>>:) */


#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <sys/sysinfo.h>
#include <stdlib.h>

#include "misc.h"
#include "../chart/chart.h"

//#define DEBUG
#include "dbg.h"



/* cpu.c */
struct cpu_stat {
    gulong u, n, s, i, w; // user, nice, system, idle, wait
};

typedef struct {
    chart_t chart;
    struct cpu_stat cpu_prev;
    int timer;
} cpu_t;

static chart_class_t *k;

static int
cpu_get_load(cpu_t *c)
{
    gfloat a, b;
    struct cpu_stat cpu, cpu_diff;
    FILE *stat;
    float total;

    ENTER;
    stat = fopen("/proc/stat", "r");
    if(!stat)
        RET(TRUE);
    fscanf(stat, "cpu %lu %lu %lu %lu %lu", &cpu.u, &cpu.n, &cpu.s, &cpu.i, &cpu.w);
    fclose(stat);

    cpu_diff.u = cpu.u - c->cpu_prev.u;
    cpu_diff.n = cpu.n - c->cpu_prev.n;
    cpu_diff.s = cpu.s - c->cpu_prev.s;
    cpu_diff.i = cpu.i - c->cpu_prev.i;
    cpu_diff.w = cpu.w - c->cpu_prev.w;
    c->cpu_prev = cpu;

    a = cpu_diff.u + cpu_diff.n + cpu_diff.s;
    b = a + cpu_diff.i + cpu_diff.w;
    total = b ?  a / b : 1.0;
    DBG("total=%f a=%f b=%f\n", total, a, b);
    k->add_tick(&c->chart, &total);
    RET(TRUE);

}


static int
cpu_constructor(plugin *p)
{'fraction_non_alphanumeric': 0.13526211671612265, 'fraction_numerical': 0.010385756676557863, 'mean_word_length': 2.9501953125, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 38, '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': '3695258', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1438, 'n_words': 501}