static void collect_pmc_cpu(struct stats_type *type, char *cpu) { struct stats *stats = NULL; char msr_path[80]; int msr_fd = -1; stats = get_current_stats(type, cpu); if (stats == NULL) goto out; TRACE("cpu %s\n", cpu); snprintf(msr_path, sizeof(msr_path), "/dev/cpu/%s/msr", cpu); msr_fd = open(msr_path, O_RDONLY); if (msr_fd < 0) { ERROR("cannot open `%s': %m\n", msr_path); goto out; } #define X(k,r...) \ ({ \ uint64_t val = 0; \ if (pread(msr_fd, &val, sizeof(val), IA32_##k) < 0) \ ERROR("cannot read `%s' (%08X) through `%s': %m\n", #k, IA32_##k, msr_path); \ else \ stats_set(stats, #k, val); \ }) KEYS; #undef X out: if (msr_fd >= 0) close(msr_fd); }
static void vm_collect(struct stats_type *type) { struct stats *stats = NULL; stats = get_current_stats(type, NULL); if (stats == NULL) return; path_collect_key_value("/proc/vmstat", stats); }
static void ps_collect(struct stats_type *type) { struct stats *stats = NULL; stats = get_current_stats(type, NULL); if (stats == NULL) return; ps_collect_proc_stat(stats); ps_collect_loadavg(stats); }
void write_daily_stats(statistics_t *stat) { char cct[BUFSIZE], sct[BUFSIZE]; statistics_t running; char timebuf[BUFSIZE]; get_current_stats(&running); add_stats(stat, &running, 0); strncpy(cct, connect_average (stat->client_connect_time, stat->client_connections + info.num_clients, timebuf), BUFSIZE); strncpy(sct, connect_average (stat->source_connect_time, stat->source_connections + info.num_sources, timebuf), BUFSIZE); }
static void collect_block_dev(struct stats_type *type, const char *dev) { struct stats *stats = get_current_stats(type, dev); if (stats == NULL) return; char path[80]; snprintf(path, sizeof(path), "/sys/block/%s/stat", dev); #define X(k,r...) #k collect_key_list(stats, path, KEYS, NULL); #undef X }
static void intel_hsw_imc_collect_dev(struct stats_type *type, char *bus_dev, char *socket_dev) { struct stats *stats = NULL; char pci_path[80]; int pci_fd = -1; stats = get_current_stats(type, socket_dev); if (stats == NULL) goto out; TRACE("bus/dev %s\n", bus_dev); snprintf(pci_path, sizeof(pci_path), "/proc/bus/pci/%s", bus_dev); pci_fd = open(pci_path, O_RDONLY); if (pci_fd < 0) { ERROR("cannot open `%s': %m\n", pci_path); goto out; } #define X(k,r...) \ ({ \ uint32_t val; \ if ( pread(pci_fd, &val, sizeof(val), MC_##k) < 0 ) \ ERROR("cannot read `%s' (%08X) through `%s': %m\n", #k, MC_##k, pci_path); \ else \ stats_set(stats, #k, val); \ }) CTL_KEYS; #undef X #define X(k,r...) \ ({ \ uint32_t val_a, val_b; \ uint64_t val = 0x0ULL; \ if ( pread(pci_fd, &val_a, sizeof(val_a), MC_A_##k) < 0 || pread(pci_fd, &val_b, sizeof(val_b), MC_B_##k) < 0 ) \ ERROR("cannot read `%s' (%08X,%08X) through `%s': %m\n", #k, MC_A_##k, MC_B_##k, pci_path); \ else \ val = val_a; stats_set(stats, #k, (val<<32) + val_b); \ }) CTR_KEYS; #undef X out: if (pci_fd >= 0) close(pci_fd); }
static void collect_sysv_shm(struct stats_type *type) { struct stats *stats = NULL; const char *path = "/proc/sysvipc/shm"; FILE *file = NULL; char file_buf[4096]; char *line_buf = NULL; size_t line_buf_size = 0; stats = get_current_stats(type, NULL); if (stats == NULL) goto out; file = fopen(path, "r"); if (file == NULL) { ERROR("cannot open `%s': %m\n", path); goto out; } setvbuf(file, file_buf, _IOFBF, sizeof(file_buf)); /* Skip header. */ getline(&line_buf, &line_buf_size, file); unsigned long long mem_used = 0, segs_used = 0; while (getline(&line_buf, &line_buf_size, file) >= 0) { unsigned long long seg_size = 0; if (sscanf(line_buf, "%*d %*d %*o %llu", &seg_size) < 1) continue; mem_used += seg_size; segs_used++; } stats_set(stats, "mem_used", mem_used); stats_set(stats, "segs_used", segs_used); out: free(line_buf); if (file != NULL) fclose(file); }
//! Collect values in counters for a CBo static void intel_snb_cbo_collect_box(struct stats_type *type, char *cpu, char* cpu_box, int box) { struct stats *stats = NULL; char msr_path[80]; int msr_fd = -1; int offset; offset = 32*box; stats = get_current_stats(type, cpu_box); if (stats == NULL) goto out; TRACE("cpu %s\n", cpu); TRACE("socket/box %s\n", cpu_box); snprintf(msr_path, sizeof(msr_path), "/dev/cpu/%s/msr", cpu); msr_fd = open(msr_path, O_RDONLY); if (msr_fd < 0) { ERROR("cannot open `%s': %m\n", msr_path); goto out; } #define X(k,r...) \ ({ \ uint64_t val = 0; \ if (pread(msr_fd, &val, sizeof(val), k + offset) < 0) \ ERROR("cannot read `%s' (%08X) through `%s': %m\n", #k, k + offset, msr_path); \ else \ stats_set(stats, #k, val); \ }) KEYS; #undef X out: if (msr_fd >= 0) close(msr_fd); }
static void collect_mdc(struct stats_type *type) { const char *mdc_dir_path = MDC_DIR_PATH; DIR *mdc_dir = NULL; mdc_dir = opendir(mdc_dir_path); if (mdc_dir == NULL) { ERROR("cannot open `%s': %m\n", mdc_dir_path); goto out; } struct dirent *de; while ((de = readdir(mdc_dir)) != NULL) { struct stats *stats = NULL; const char *mnt; if (de->d_type != DT_DIR || *de->d_name == '.') continue; mnt = lustre_obd_to_mnt(de->d_name); if (mnt == NULL) continue; TRACE("d_name `%s', mnt `%s'\n", de->d_name, mnt); stats = get_current_stats(type, mnt); if (stats == NULL) continue; collect_mdc_fs(stats, de->d_name); } out: if (mdc_dir != NULL) closedir(mdc_dir); }
static void proc_collect_pid(struct stats_type *type, const char *pid) { struct stats *stats = NULL; char path[32]; char process[512]; FILE *file = NULL; char file_buf[4096]; char *line = NULL; size_t line_size = 0; char name[16]; char cmask[512]; char mmask[32]; TRACE("pid %s\n", pid); snprintf(path, sizeof(path), "/proc/%s/status", pid); file = fopen(path, "r"); if (file == NULL) { ERROR("cannot open `%s': %m\n",path); goto out; } setvbuf(file, file_buf, _IOFBF, sizeof(file_buf)); while (getline(&line, &line_size, file) >= 0) { char *key, *rest = line; key = wsep(&rest); if (key == NULL || rest == NULL) continue; rest[strlen(rest) - 1] = '\0'; if (strcmp(key, "Name:") == 0) { if (!strcmp("bash", rest) || !strcmp("ssh", rest) || !strcmp("sshd", rest) || !strcmp("metacity", rest)) goto out; strcpy(name, rest); } else if (strcmp(key, "Cpus_allowed_list:") == 0) { strcpy(cmask, rest); } else if (strcmp(key, "Mems_allowed_list:") == 0) { strcpy(mmask, rest); } } snprintf(process, sizeof(process), "%s/%s/%s/%s", name, pid, cmask, mmask); stats = get_current_stats(type, process); if (stats == NULL) goto out; fseek(file, 0, SEEK_SET); while (getline(&line, &line_size, file) >= 0) { char *key, *rest = line; key = wsep(&rest); if (key == NULL || rest == NULL) continue; errno = 0; key[strlen(key) - 1] = '\0'; unsigned long long val = strtoull(rest, NULL, 0); if (errno == 0) stats_set(stats, key, val); } out: free(line); if (file != NULL) fclose(file); }
// Computes the quality statistics for the tetrahedral mesh void Vol2mesh :: get_all_quality_stats(vtkMeshQuality* q, matrix & q_mat, vector<string> & q_name){ // Edge ratio q->SetTetQualityMeasureToEdgeRatio(); q->Update(); q_name.push_back("Edge ratio"); q_mat.push_back(get_current_stats(q)); // Aspect ratio q->SetTetQualityMeasureToAspectRatio(); q->Update(); q_name.push_back("Aspect ratio"); q_mat.push_back(get_current_stats(q)); // Radius ratio q->SetTetQualityMeasureToRadiusRatio(); q->Update(); q_name.push_back("Radius ratio"); q_mat.push_back(get_current_stats(q)); // Aspect Frobenius q->SetTetQualityMeasureToAspectFrobenius(); q->Update(); q_name.push_back("Aspect Frobenius"); q_mat.push_back(get_current_stats(q)); // Minimal dihedral angle q->SetTetQualityMeasureToMinAngle(); q->Update(); q_name.push_back("Minimal dihedral angle"); q_mat.push_back(get_current_stats(q)); // Collapse ratio q->SetTetQualityMeasureToCollapseRatio(); q->Update(); q_name.push_back("Collapse ratio"); q_mat.push_back(get_current_stats(q)); // Aspect beta q->SetTetQualityMeasureToAspectBeta(); q->Update(); q_name.push_back("Aspect beta"); q_mat.push_back(get_current_stats(q)); // Volume q->SetTetQualityMeasureToVolume(); q->Update(); q_name.push_back("Volume"); q_mat.push_back(get_current_stats(q)); // Condition q->SetTetQualityMeasureToCondition(); q->Update(); q_name.push_back("Condition"); q_mat.push_back(get_current_stats(q)); // Jacobian q->SetTetQualityMeasureToJacobian(); q->Update(); q_name.push_back("Jacobian"); q_mat.push_back(get_current_stats(q)); // Scaled jacobian q->SetTetQualityMeasureToScaledJacobian(); q->Update(); q_name.push_back("Scaled jacobian"); q_mat.push_back(get_current_stats(q)); // Shape q->SetTetQualityMeasureToShape(); q->Update(); q_name.push_back("Shape"); q_mat.push_back(get_current_stats(q)); // Relative size squared q->SetTetQualityMeasureToRelativeSizeSquared(); q->Update(); q_name.push_back("Relative size squared"); q_mat.push_back(get_current_stats(q)); // Shape and size q->SetTetQualityMeasureToShapeAndSize(); q->Update(); q_name.push_back("Shape and size"); q_mat.push_back(get_current_stats(q)); // Distortion q->SetTetQualityMeasureToDistortion(); q->Update(); q_name.push_back("Distortion"); q_mat.push_back(get_current_stats(q)); }
static void collect_irq_stats( struct stats_type *type, const char *path ) { FILE *file = NULL; char *line = NULL; size_t line_size = 0; file = fopen( path, "r" ); if ( file == NULL ) { //ERROR( "cannot open `%s': %m\n", path ); goto out; } while ( 0 <= getline( &line, &line_size, file ) ) { char *rest = line; char *key = wsep( &rest ); if ( key == NULL || rest == NULL ) continue; if ( ! strncasecmp( key, "cpu0", 4 ) ) continue; #define X(k,r...) k = 0 unsigned long long KEYS; #undef X if ( 0 < sscanf( rest, #define X(k,r...) " %llu" JOIN( KEYS ) #undef X #define X(k,r...) &k , KEYS ) ) { #undef X /* remove the colon */ char *t = key; do { if ( ':' == *t ) *t = '\0'; } while ( *t++ ); /* check if the key is a number of not */ strtoul( key, &t, 10 ); if ( '\0' == *t ) { /* so the key is a number, e.g. like the following CPU0 CPU1 CPU2 CPU3 0: 198 1 0 0 IO-APIC-edge timer 1: 0 2 2 3 IO-APIC-edge i8042 4: 0 0 4 0 IO-APIC-edge serial 6: 0 0 1 1 IO-APIC-edge floppy 8: 0 0 1 0 IO-APIC-edge rtc0 ... */ /* get the real device name from the last column(s) */ /* An x86 IRQ description is of form "%s-%s %s" where the first %s is from the "name" field, e.g. in arch/x86/kernel/apic/io_apic.c : static struct irq_chip ioapic_chip __read_mostly = { .name = "IO-APIC", .irq_startup = startup_ioapic_irq, .irq_mask = mask_ioapic_irq, .irq_unmask = unmask_ioapic_irq, .irq_ack = ack_apic_edge, .irq_eoi = ack_apic_level, #ifdef CONFIG_SMP .irq_set_affinity = ioapic_set_affinity, #endif .irq_retrigger = ioapic_retrigger_irq, }; */ /* ignore interrupts from certain devices, e.g. keyboard, floppy, USB, etc */ if ( strstr( rest, " i8042" ) || strstr( rest, " floppy" ) || strstr( rest, ":usb" ) || strstr( rest, " serial" ) ) continue; size_t s = strspn( rest, "0123456789: \t\n\r" ); if ( '\0' == rest[s] ) continue; /* there is no last column; move on */ rest += s; wsep( &rest ); if ( NULL == rest ) continue; s = strspn( rest, " \t\n\r" ); if ( '\0' == rest[s] ) continue; /* replace every space with underscore */ t = key = rest + s; do { if ( '\r' == *t || '\n' == *t ) *t = '\0'; if ( isspace( *t ) ) *t = '_'; } while ( *t++ ); } struct stats *stats = get_current_stats( type, key ); if ( NULL == stats ) break; #define X(k,r...) stats_set(stats, #k, k) KEYS; #undef X } } out: if ( NULL != line ) free( line ); if ( NULL != file ) fclose( file ); }
static void collect_ib_sw(struct stats_type *type) { const char *ib_dir_path = "/sys/class/infiniband"; DIR *ib_dir = NULL; ib_dir = opendir(ib_dir_path); if (ib_dir == NULL) { ERROR("cannot open `%s': %m\n", ib_dir_path); goto out; } struct dirent *hca_ent; while ((hca_ent = readdir(ib_dir)) != NULL) { char *hca = hca_ent->d_name; char ports_path[80]; DIR *ports_dir = NULL; if (hca[0] == '.') goto next_hca; snprintf(ports_path, sizeof(ports_path), "%s/%s/ports", ib_dir_path, hca); ports_dir = opendir(ports_path); if (ports_dir == NULL) { ERROR("cannot open `%s': %m\n", ports_path); goto next_hca; } struct dirent *port_ent; while ((port_ent = readdir(ports_dir)) != NULL) { int port = atoi(port_ent->d_name); if (port <= 0) continue; /* Check that port is active. .../HCA/ports/PORT/state should read "4: ACTIVE." */ int state = -1; char state_path[80]; snprintf(state_path, sizeof(state_path), "/sys/class/infiniband/%s/ports/%d/state", hca, port); if (pscanf(state_path, "%d", &state) != 1) { ERROR("cannot read state of IB HCA `%s' port %d: %m\n", hca, port); continue; } if (state != 4) { TRACE("skipping inactive IB HCA `%s', port %d, state %d\n", hca, port, state); continue; } /* Create dev name (HCA/PORT) and get stats for dev. */ char dev[80]; snprintf(dev, sizeof(dev), "%s/%d", hca, port); TRACE("IB HCA `%s', port %d, dev `%s'\n", hca, port, dev); struct stats *stats = get_current_stats(type, dev); if (stats == NULL) continue; collect_hca_port(stats, hca, port); } next_hca: if (ports_dir != NULL) closedir(ports_dir); } out: if (ib_dir != NULL) closedir(ib_dir); }
static void ib_collect_dev(struct stats_type *type, const char *dev) { int port; for (port = 1; port <= 2; port++) { char path[80], id[80];//, cmd[160]; FILE *file = NULL; char file_buf[4096]; unsigned int lid; struct stats *stats = NULL; snprintf(path, sizeof(path), "/sys/class/infiniband/%s/ports/%i/state", dev, port); file = fopen(path, "r"); if (file == NULL) goto next; /* ERROR("cannot open `%s': %m\n", path); */ setvbuf(file, file_buf, _IOFBF, sizeof(file_buf)); char buf[80] = { 0 }; if (fgets(buf, sizeof(buf), file) == NULL) goto next; fclose(file); file = NULL; if (strstr(buf, "ACTIVE") == NULL) goto next; TRACE("dev %s, port %i\n", dev, port); snprintf(id, sizeof(id), "%s.%i", dev, port); /* XXX */ stats = get_current_stats(type, id); if (stats == NULL) goto next; snprintf(path, sizeof(path), "/sys/class/infiniband/%s/ports/%i/counters", dev, port); path_collect_key_value_dir(path, stats); /* Get the LID for perfquery. */ snprintf(path, sizeof(path), "/sys/class/infiniband/%s/ports/%i/lid", dev, port); file = fopen(path, "r"); if (file == NULL) goto next; setvbuf(file, file_buf, _IOFBF, sizeof(file_buf)); if (fscanf(file, "%x", &lid) != 1) goto next; fclose(file); file = NULL; /* Call perfquery to clear stats. Blech! */ /* snprintf(cmd, sizeof(cmd), "%s -R %#x %d", perfquery, lid, port); int cmd_rc = system(cmd); if (cmd_rc != 0) ERROR("`%s' exited with status %d\n", cmd, cmd_rc); */ next: if (file != NULL) fclose(file); file = NULL; } }