Esempio n. 1
0
unsigned long getLinuxVersionCode()
{
	struct utsname uts;

	// cleared in case sscanf() < 3
	unsigned x = 0;
	unsigned y = 0;
	unsigned z = 0;

	// failure most likely implies impending death
	if(uname(&uts) == -1)
	{
		logError("uname() failed [%d]\n", __LINE__);
	}

	if(sscanf(uts.release, "%u.%u.%u", &x, &y, &z) < 3)
	{
		logWarning(
			"Non-standard uts for running kernel:\nrelease %s=%u.%u.%u gives version code %d\n",
			uts.release, x, y, z, LINUX_VERSION_CODE(x,y,z)
		);
	}

	if(LINUX_VERSION_CODE(x, y, z) >= LINUX_VERSION_CODE(2, 6, 0) && !hasSysFS())
	{
		logWarning("You're running a 2.6 kernel without /sys. You should mount it [%d]\n", __LINE__);
	}

    return LINUX_VERSION_CODE(x, y, z);
}
Esempio n. 2
0
void
glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf, pid_t pid)
{
	char buffer [BUFSIZ], *p;
    memset (buf, 0, sizeof (glibtop_proc_io));

    if (server->os_version_code < LINUX_VERSION_CODE(2, 6, 20))
      return;

	if (proc_file_to_buffer(buffer, sizeof buffer, "/proc/%d/io", pid))
		return;

	p = skip_token (buffer);
    buf->disk_rchar = g_ascii_strtoull (p, &p, 10);
    p = skip_line (p);
    p = skip_token (p);
    buf->disk_wchar = g_ascii_strtoull (p, &p, 10);
    p = skip_line (p);
    p = skip_line (p);
    p = skip_line (p);
    p = skip_token (p);
    buf->disk_rbytes = g_ascii_strtoull (p, &p, 10);
    p = skip_line (p);
    p = skip_token (p);
    buf->disk_wbytes = g_ascii_strtoull (p, &p, 10);    

    buf->flags = _glibtop_sysdeps_proc_io;
}
Esempio n. 3
0
static int
set_linux_version ()
{
  struct utsname uts;
  unsigned x = 0, y = 0, z = 0;

  if (uname (&uts) == -1)	/* failure most likely implies impending death */
    return -1;
  sscanf (uts.release, "%u.%u.%u", &x, &y, &z);
  if (LINUX_VERSION_CODE (x, y, z) >= LINUX_VERSION_CODE (2, 6, 0)
      && !has_sysfs ())
    return -1;

  os_version_code = LINUX_VERSION_CODE (x, y, z);
  return 0;
}
Esempio n. 4
0
void get_cpu (dbgov_cpu * buf)
{
  char buffer[BUFSIZ], *p;

  memset (buf, 0, sizeof (dbgov_cpu));

  int res = try_file_to_buffer (buffer, FILENAME);
  if (res == TRY_FILE_TO_BUFFER_OK_IOSTAT)
    {
      p = skip_token (buffer);
      buf->user = strtoull (p, &p, 0);
      buf->nice = strtoull (p, &p, 0);
      buf->sys = strtoull (p, &p, 0);
      buf->idle = strtoull (p, &p, 0);
      buf->total = buf->user + buf->nice + buf->sys + buf->idle;

      /* 2.6 kernel */
      if (os_version_code >= LINUX_VERSION_CODE (2, 6, 0))
	{
	  buf->iowait = strtoull (p, &p, 0);
	  buf->irq = strtoull (p, &p, 0);
	  buf->softirq = strtoull (p, &p, 0);

	  buf->total += buf->iowait + buf->irq + buf->softirq;
	}

      buf->frequency = 100;
    }
}
Esempio n. 5
0
/**
 * XXX: IMPORTANt - result will show in Kb
 */
void getSwapUsage(monita_swap* buf)
{
    char buffer [BUFSIZ];
    char* p;

    memset(buf, 0, sizeof (monita_swap));

    fileToBuffer(buffer, sizeof buffer, MEMINFO);

    // XXX: IMPORTANT - Kernel 2.6 with multiple lines
    buf->total	= getScaled(buffer, "SwapTotal:");
    buf->free	= getScaled(buffer, "SwapFree:");
    buf->cached	= getScaled(buffer, "Cached:");
    buf->used	= buf->total - buf->free;

    unsigned long osVersionCode = getLinuxVersionCode();

    if(osVersionCode >= LINUX_VERSION_CODE(2, 6, 0))
    {
        fileToBuffer(buffer, sizeof buffer, PROC_VMSTAT);

        p = strstr(buffer, "\npswpin");

        if(p)
        {
            p = skipToken(p);
            buf->pagein  = strtoull(p, &p, 0);

            p = skipToken(p);
            buf->pageout = strtoull(p, &p, 0);
        }
    }
    else // Linux 2.4
    {
        fileToBuffer(buffer, sizeof buffer, PROC_STAT);

        p = strstr(buffer, "\nswap");

        if(p)
        {
            p = skipToken(p);

            buf->pagein  = strtoull(p, &p, 0);
            buf->pageout = strtoull(p, &p, 0);
        }
    }
}
Esempio n. 6
0
void
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
{
	char buffer [BUFSIZ], *p;

	memset (buf, 0, sizeof (glibtop_proc_uid));

	if (proc_status_to_buffer(buffer, sizeof buffer, pid))
		return;

	/* Search substring 'Pid:' */

	p = strstr (buffer, "\nPid:");
	if (!p) return;

	p = skip_token (p); /* "Pid:" */
	buf->pid = strtol (p, &p, 0);

	p = skip_token (p); /* "PPid:" */
	buf->ppid = strtol (p, &p, 0);

	/* Maybe future Linux versions place something between
	 * "PPid" and "Uid", so we catch this here. */
	p = strstr (p, "\nUid:");
	if (!p) return;

	p = skip_token (p); /* "Uid:" */
	buf->uid  = strtol (p, &p, 0);
	buf->euid = strtol (p, &p, 0);

	/* We don't know how many entries on the "Uid:" line
	 * future Linux version will have, so we catch this here. */
	p = strstr (p, "\nGid:");
	if (!p) return;

	p = skip_token (p); /* "Gid:" */
	buf->gid  = strtol (p, &p, 0);
	buf->egid = strtol (p, &p, 0);

	buf->flags = _glibtop_sysdeps_proc_uid;

	if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
		return;

	p = proc_stat_after_cmd (buffer);
	if (!p) return;

	p = skip_multiple_token (p, 2);

	buf->pgrp    = strtol (p, &p, 0);
	buf->session = strtol (p, &p, 0);
	buf->tty     = strtol (p, &p, 0);
	buf->tpgid   = strtol (p, &p, 0);

	p = skip_multiple_token (p, 9);

	buf->priority = strtol (p, &p, 0);
	buf->nice     = strtol (p, &p, 0);

	if (buf->tty == 0)
		/* the old notty val, update elsewhere bef. moving to 0 */
		buf->tty = -1;

	if (server->os_version_code < LINUX_VERSION_CODE(1,3,39)) {
		/* map old meanings to new */
		buf->priority = 2*15 - buf->priority;
		buf->nice = 15 - buf->nice;
	}
	else if (server->os_version_code < LINUX_VERSION_CODE(1,1,30) && buf->tty != -1)
		/* when tty wasn't full devno */
		buf->tty = 4*0x100 + buf->tty;

	buf->flags |= _glibtop_sysdeps_proc_uid_stat;
}