|
Packit Service |
407539 |
/* Copyright (C) 1998-99 Martin Baulig
|
|
Packit Service |
407539 |
This file is part of LibGTop 1.0.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
LibGTop is free software; you can redistribute it and/or modify it
|
|
Packit Service |
407539 |
under the terms of the GNU General Public License as published by
|
|
Packit Service |
407539 |
the Free Software Foundation; either version 2 of the License,
|
|
Packit Service |
407539 |
or (at your option) any later version.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit Service |
407539 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
Packit Service |
407539 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit Service |
407539 |
for more details.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
407539 |
along with LibGTop; see the file COPYING. If not, write to the
|
|
Packit Service |
407539 |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit Service |
407539 |
Boston, MA 02110-1301, USA.
|
|
Packit Service |
407539 |
*/
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <config.h>
|
|
Packit Service |
407539 |
#include <glibtop.h>
|
|
Packit Service |
407539 |
#include <glibtop/cpu.h>
|
|
Packit Service |
407539 |
#include <glibtop/open.h>
|
|
Packit Service |
407539 |
#include <glibtop/error.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include "glibtop_private.h"
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* ======================================================= */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#define FILENAME "/proc/stat"
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
void
|
|
Packit Service |
407539 |
glibtop_open_s (glibtop *server, const char *program_name,
|
|
Packit Service |
407539 |
const unsigned long features,
|
|
Packit Service |
407539 |
const unsigned flags)
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
char buffer [BUFSIZ], *p = buffer;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
server->name = program_name;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
file_to_buffer(server, buffer, sizeof buffer, FILENAME);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
p = skip_line(p); /* cpu */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
for (server->real_ncpu = 0; /* nop */; server->real_ncpu++) {
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
if (!check_cpu_line(server, p, server->real_ncpu)) {
|
|
Packit Service |
407539 |
server->real_ncpu--;
|
|
Packit Service |
407539 |
break;
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
p = skip_line(p);
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
server->ncpu = MIN(GLIBTOP_NCPU - 1, server->real_ncpu);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
if (server->real_ncpu != server->ncpu) {
|
|
Packit Service |
407539 |
glibtop_warn_r(server,
|
|
Packit Service |
407539 |
"This machine has %d CPUs, "
|
|
Packit Service |
407539 |
"%d are being monitored.",
|
|
Packit Service |
407539 |
server->real_ncpu + 1,
|
|
Packit Service |
407539 |
server->ncpu + 1);
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
}
|