/* * Handle a sample callback from the PkaSourceSimple. */ static inline void cpu_sample (PkaSourceSimple *source, gpointer user_data) { CpuData *cpud = user_data; gchar *curr; gchar fileBuf[1024]; gint cpuData[10]; /* * Create and deliver our manifest if it has not yet been done. */ if (G_UNLIKELY(!cpud->manifest)) { cpud->manifest = pka_manifest_sized_new(17); pka_manifest_append(cpud->manifest, "CPU Number", G_TYPE_INT); pka_manifest_append(cpud->manifest, "User", G_TYPE_INT); pka_manifest_append(cpud->manifest, "Nice", G_TYPE_INT); pka_manifest_append(cpud->manifest, "System", G_TYPE_INT); pka_manifest_append(cpud->manifest, "Idle", G_TYPE_INT); pka_manifest_append(cpud->manifest, "I/O Wait", G_TYPE_INT); pka_manifest_append(cpud->manifest, "IRQ", G_TYPE_INT); pka_manifest_append(cpud->manifest, "Soft IRQ", G_TYPE_INT); pka_manifest_append(cpud->manifest, "VM Stolen", G_TYPE_INT); pka_manifest_append(cpud->manifest, "VM Guest", G_TYPE_INT); pka_source_deliver_manifest(PKA_SOURCE(source), cpud->manifest); } // Read in /proc/stat first. src_utils_read_file("/proc/stat", fileBuf, 1024); curr = fileBuf; while (curr != NULL) { gchar *next = src_utils_str_tok('\n', curr); PkaSample *s; gint i; if (parse_cpu_stat_line(curr, cpuData)) { // Then cpuData has valid data. Return a sample. s = pka_sample_new(); for (i = 0; i < 10; i++) pka_sample_append_int(s, i+1, cpuData[i]); pka_source_deliver_sample(PKA_SOURCE(source), s); pka_sample_unref(s); } curr = next; } }
/** * pka_manifest_new: * * Creates a new instance of #PkaManifest. * * Returns: The newly created instance of PkaManifest. * * Side effects: None. */ PkaManifest* pka_manifest_new (void) { ENTRY; RETURN(pka_manifest_sized_new(4)); }