/* _get_process_io_data_line() - get line of data from /proc/<pid>/io * * IN: in - input file descriptor * OUT: prec - the destination for the data * * RETVAL: ==0 - no valid data * !=0 - data are valid * * /proc/<pid>/io content format is: * rchar: <# of characters read> * wrchar: <# of characters written> * . . . */ static int _get_process_io_data_line(int in, jag_prec_t *prec) { char sbuf[256]; char f1[7], f3[7]; int num_read, nvals; uint64_t rchar, wchar; num_read = read(in, sbuf, (sizeof(sbuf) - 1)); if (num_read <= 0) return 0; sbuf[num_read] = '\0'; nvals = sscanf(sbuf, "%s %"PRIu64" %s %"PRIu64"", f1, &rchar, f3, &wchar); if (nvals < 4) return 0; if (_is_a_lwp(prec->pid) > 0) return 0; /* Copy the values that slurm records into our data structure */ prec->disk_read = (double)rchar / (double)1048576; prec->disk_write = (double)wchar / (double)1048576; return 1; }
/* _get_process_io_data_line() - get line of data from /proc/<pid>/io * * IN: in - input file descriptor * OUT: prec - the destination for the data * * RETVAL: ==0 - no valid data * !=0 - data are valid * * /proc/<pid>/io content format is: * rchar: <# of characters read> * wrchar: <# of characters written> * . . . */ static int _get_process_io_data_line(int in, jag_prec_t *prec) { char sbuf[256]; char f1[7], f3[7]; int num_read, nvals; uint64_t rchar, wchar; num_read = read(in, sbuf, (sizeof(sbuf) - 1)); if (num_read <= 0) return 0; sbuf[num_read] = '\0'; nvals = sscanf(sbuf, "%s %"PRIu64" %s %"PRIu64"", f1, &rchar, f3, &wchar); if (nvals < 4) return 0; if (_is_a_lwp(prec->pid) > 0) return 0; /* keep real value here since we aren't doubles */ prec->tres_data[TRES_ARRAY_FS_DISK].size_read = rchar; prec->tres_data[TRES_ARRAY_FS_DISK].size_write = wchar; return 1; }
/* _get_process_data_line() - get line of data from /proc/<pid>/stat * * IN: in - input file descriptor * OUT: prec - the destination for the data * * RETVAL: ==0 - no valid data * !=0 - data are valid * * Based upon stat2proc() from the ps command. It can handle arbitrary * executable file basenames for `cmd', i.e. those with embedded whitespace or * embedded ')'s. Such names confuse %s (see scanf(3)), so the string is split * and %39c is used instead. (except for embedded ')' "(%[^)]c)" would work. */ static int _get_process_data_line(int in, jag_prec_t *prec) { char sbuf[256], *tmp; int num_read, nvals; char cmd[40], state[1]; int ppid, pgrp, session, tty_nr, tpgid; long unsigned flags, minflt, cminflt, majflt, cmajflt; long unsigned utime, stime, starttime, vsize; long int cutime, cstime, priority, nice, timeout, itrealvalue, rss; long unsigned f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13; int exit_signal, last_cpu; num_read = read(in, sbuf, (sizeof(sbuf) - 1)); if (num_read <= 0) return 0; sbuf[num_read] = '\0'; tmp = strrchr(sbuf, ')'); /* split into "PID (cmd" and "<rest>" */ *tmp = '\0'; /* replace trailing ')' with NUL */ /* parse these two strings separately, skipping the leading "(". */ nvals = sscanf(sbuf, "%d (%39c", &prec->pid, cmd); if (nvals < 2) return 0; nvals = sscanf(tmp + 2, /* skip space after ')' too */ "%c %d %d %d %d %d " "%lu %lu %lu %lu %lu " "%lu %lu %ld %ld %ld %ld " "%ld %ld %lu %lu %ld " "%lu %lu %lu %lu %lu " "%lu %lu %lu %lu %lu " "%lu %lu %lu %d %d ", state, &ppid, &pgrp, &session, &tty_nr, &tpgid, &flags, &minflt, &cminflt, &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &priority, &nice, &timeout, &itrealvalue, &starttime, &vsize, &rss, &f1, &f2, &f3, &f4, &f5 ,&f6, &f7, &f8, &f9, &f10, &f11, &f12, &f13, &exit_signal, &last_cpu); /* There are some additional fields, which we do not scan or use */ if ((nvals < 37) || (rss < 0)) return 0; /* If current pid corresponds to a Light Weight Process (Thread POSIX) */ /* skip it, we will only account the original process (pid==tgid) */ if (_is_a_lwp(prec->pid) > 0) return 0; /* Copy the values that slurm records into our data structure */ prec->ppid = ppid; prec->pages = majflt; prec->usec = utime; prec->ssec = stime; prec->vsize = vsize / 1024; /* convert from bytes to KB */ prec->rss = rss * my_pagesize;/* convert from pages to KB */ prec->last_cpu = last_cpu; return 1; }