Lines Matching refs:lf
39 static int scan_lines(struct lnstat_file *lf, int i) in scan_lines() argument
43 for (j = 0; j < lf->num_fields; j++) in scan_lines()
44 lf->fields[j].values[i] = 0; in scan_lines()
46 while(!feof(lf->fp)) { in scan_lines()
52 fgets(buf, sizeof(buf)-1, lf->fp); in scan_lines()
53 gettimeofday(&lf->last_read, NULL); in scan_lines()
55 for (j = 0; j < lf->num_fields; j++) { in scan_lines()
58 lf->fields[j].values[i] = f; in scan_lines()
60 lf->fields[j].values[i] += f; in scan_lines()
83 struct lnstat_file *lf; in lnstat_update() local
89 for (lf = lnstat_files; lf; lf = lf->next) { in lnstat_update()
90 if (time_after(&lf->last_read, &lf->interval, &tv)) { in lnstat_update()
94 rewind(lf->fp); in lnstat_update()
95 if (!lf->compat) { in lnstat_update()
97 fgets(buf, sizeof(buf)-1, lf->fp); in lnstat_update()
99 scan_lines(lf, 1); in lnstat_update()
101 for (i = 0, lfi = &lf->fields[i]; in lnstat_update()
102 i < lf->num_fields; i++, lfi = &lf->fields[i]) { in lnstat_update()
107 / lf->interval.tv_sec; in lnstat_update()
110 rewind(lf->fp); in lnstat_update()
111 fgets(buf, sizeof(buf)-1, lf->fp); in lnstat_update()
112 scan_lines(lf, 0); in lnstat_update()
120 static int __lnstat_scan_fields(struct lnstat_file *lf, char *buf) in __lnstat_scan_fields() argument
127 lf->fields[i].file = lf; in __lnstat_scan_fields()
128 strncpy(lf->fields[i].name, tok, LNSTAT_MAX_FIELD_NAME_LEN); in __lnstat_scan_fields()
133 lf->num_fields = i+1; in __lnstat_scan_fields()
140 static int lnstat_scan_fields(struct lnstat_file *lf) in lnstat_scan_fields() argument
144 rewind(lf->fp); in lnstat_scan_fields()
145 fgets(buf, sizeof(buf)-1, lf->fp); in lnstat_scan_fields()
147 return __lnstat_scan_fields(lf, buf); in lnstat_scan_fields()
151 static int lnstat_scan_compat_rtstat_fields(struct lnstat_file *lf) in lnstat_scan_compat_rtstat_fields() argument
157 return __lnstat_scan_fields(lf, buf); in lnstat_scan_compat_rtstat_fields()
174 struct lnstat_file *lf; in alloc_and_open() local
177 lf = malloc(sizeof(*lf)); in alloc_and_open()
178 if (!lf) in alloc_and_open()
182 memset(lf, 0, sizeof(*lf)); in alloc_and_open()
185 strcpy(lf->basename, file); in alloc_and_open()
186 strcpy(lf->path, path); in alloc_and_open()
187 strcat(lf->path, "/"); in alloc_and_open()
188 strcat(lf->path, lf->basename); in alloc_and_open()
191 lf->interval.tv_sec = 1; in alloc_and_open()
194 lf->fp = fopen(lf->path, "r"); in alloc_and_open()
195 if (!lf->fp) { in alloc_and_open()
196 free(lf); in alloc_and_open()
200 return lf; in alloc_and_open()
217 struct lnstat_file *lf; in lnstat_scan_dir() local
236 lf = alloc_and_open("/proc/net", "rt_cache_stat"); in lnstat_scan_dir()
237 if (!lf) in lnstat_scan_dir()
239 lf->compat = 1; in lnstat_scan_dir()
240 strncpy(lf->basename, "rt_cache", sizeof(lf->basename)); in lnstat_scan_dir()
243 if (lnstat_scan_compat_rtstat_fields(lf) < 0) in lnstat_scan_dir()
246 lf->next = lnstat_files; in lnstat_scan_dir()
247 lnstat_files = lf; in lnstat_scan_dir()
252 struct lnstat_file *lf; in lnstat_scan_dir() local
261 lf = alloc_and_open(path, de->d_name); in lnstat_scan_dir()
262 if (!lf) in lnstat_scan_dir()
266 if (lnstat_scan_fields(lf) < 0) in lnstat_scan_dir()
270 lf->next = lnstat_files; in lnstat_scan_dir()
271 lnstat_files = lf; in lnstat_scan_dir()
280 struct lnstat_file *lf; in lnstat_dump() local
282 for (lf = lnstat_files; lf; lf = lf->next) { in lnstat_dump()
285 fprintf(outfd, "%s:\n", lf->path); in lnstat_dump()
287 for (i = 0; i < lf->num_fields; i++) in lnstat_dump()
288 fprintf(outfd, "\t%2u: %s\n", i+1, lf->fields[i].name); in lnstat_dump()
297 struct lnstat_file *lf; in lnstat_find_field() local
311 for (lf = lnstat_files; lf; lf = lf->next) { in lnstat_find_field()
314 if (file && strcmp(file, lf->basename)) in lnstat_find_field()
317 for (i = 0; i < lf->num_fields; i++) { in lnstat_find_field()
318 if (!strcmp(field, lf->fields[i].name)) { in lnstat_find_field()
319 ret = &lf->fields[i]; in lnstat_find_field()