resolve fd to filename if possible with -y
[lttngtop.git] / src / common.c
1 /*
2 * Copyright (C) 2011-2012 Julien Desfossez
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include <babeltrace/ctf/events.h>
19 #include <stdlib.h>
20 #include <linux/unistd.h>
21 #include <string.h>
22 #include "common.h"
23
24 uint64_t get_cpu_id(const struct bt_ctf_event *event)
25 {
26 const struct bt_definition *scope;
27 uint64_t cpu_id;
28
29 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_PACKET_CONTEXT);
30 cpu_id = bt_ctf_get_uint64(bt_ctf_get_field(event, scope, "cpu_id"));
31 if (bt_ctf_field_get_error()) {
32 fprintf(stderr, "[error] get cpu_id\n");
33 return -1ULL;
34 }
35
36 return cpu_id;
37 }
38
39 uint64_t get_context_tid(const struct bt_ctf_event *event)
40 {
41 const struct bt_definition *scope;
42 uint64_t tid;
43
44 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
45 tid = bt_ctf_get_int64(bt_ctf_get_field(event,
46 scope, "_tid"));
47 if (bt_ctf_field_get_error()) {
48 fprintf(stderr, "Missing tid context info\n");
49 return -1ULL;
50 }
51
52 return tid;
53 }
54
55 uint64_t get_context_pid(const struct bt_ctf_event *event)
56 {
57 const struct bt_definition *scope;
58 uint64_t pid;
59
60 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
61 pid = bt_ctf_get_int64(bt_ctf_get_field(event,
62 scope, "_pid"));
63 if (bt_ctf_field_get_error()) {
64 fprintf(stderr, "Missing pid context info\n");
65 return -1ULL;
66 }
67
68 return pid;
69 }
70
71 uint64_t get_context_ppid(const struct bt_ctf_event *event)
72 {
73 const struct bt_definition *scope;
74 uint64_t ppid;
75
76 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
77 ppid = bt_ctf_get_int64(bt_ctf_get_field(event,
78 scope, "_ppid"));
79 if (bt_ctf_field_get_error()) {
80 fprintf(stderr, "Missing ppid context info\n");
81 return -1ULL;
82 }
83
84 return ppid;
85 }
86
87 uint64_t get_context_vtid(const struct bt_ctf_event *event)
88 {
89 const struct bt_definition *scope;
90 uint64_t vtid;
91
92 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
93 vtid = bt_ctf_get_int64(bt_ctf_get_field(event,
94 scope, "_vtid"));
95 if (bt_ctf_field_get_error()) {
96 return -1ULL;
97 }
98
99 return vtid;
100 }
101
102 uint64_t get_context_vpid(const struct bt_ctf_event *event)
103 {
104 const struct bt_definition *scope;
105 uint64_t vpid;
106
107 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
108 vpid = bt_ctf_get_int64(bt_ctf_get_field(event,
109 scope, "_vpid"));
110 if (bt_ctf_field_get_error()) {
111 return -1ULL;
112 }
113
114 return vpid;
115 }
116
117 uint64_t get_context_vppid(const struct bt_ctf_event *event)
118 {
119 const struct bt_definition *scope;
120 uint64_t vppid;
121
122 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
123 vppid = bt_ctf_get_int64(bt_ctf_get_field(event,
124 scope, "_vppid"));
125 if (bt_ctf_field_get_error()) {
126 return -1ULL;
127 }
128
129 return vppid;
130 }
131
132 char *get_context_comm(const struct bt_ctf_event *event)
133 {
134 const struct bt_definition *scope;
135 char *comm;
136
137 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
138 comm = bt_ctf_get_char_array(bt_ctf_get_field(event,
139 scope, "_procname"));
140 if (bt_ctf_field_get_error()) {
141 fprintf(stderr, "Missing comm context info\n");
142 return NULL;
143 }
144
145 return comm;
146 }
147
148 char *get_context_hostname(const struct bt_ctf_event *event)
149 {
150 const struct bt_definition *scope;
151 char *hostname;
152
153 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
154 hostname = bt_ctf_get_char_array(bt_ctf_get_field(event,
155 scope, "_hostname"));
156 if (bt_ctf_field_get_error()) {
157 return NULL;
158 }
159
160 return hostname;
161 }
162
163 /*
164 * To get the parent process, put the pid in the tid field
165 * because the parent process gets pid = tid
166 */
167 struct processtop *find_process_tid(struct lttngtop *ctx, int tid, const char *comm)
168 {
169 struct processtop *tmp;
170
171 tmp = g_hash_table_lookup(ctx->process_hash_table,
172 (gconstpointer) (unsigned long) tid);
173
174 return tmp;
175 }
176
177 struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm,
178 unsigned long timestamp, char *hostname)
179 {
180 struct processtop *newproc;
181 struct host *host;
182
183 /* if the PID already exists, we just rename the process */
184 /* FIXME : need to integrate with clone/fork/exit to be accurate */
185 newproc = find_process_tid(ctx, tid, comm);
186
187 if (!newproc) {
188 newproc = g_new0(struct processtop, 1);
189 newproc->tid = tid;
190 newproc->birth = timestamp;
191 newproc->process_files_table = g_ptr_array_new();
192 newproc->files_history = NULL;
193 newproc->totalfileread = 0;
194 newproc->totalfilewrite = 0;
195 newproc->fileread = 0;
196 newproc->filewrite = 0;
197 newproc->syscall_info = NULL;
198 newproc->threadparent = NULL;
199 newproc->threads = g_ptr_array_new();
200 newproc->perf = g_hash_table_new(g_str_hash, g_str_equal);
201 g_ptr_array_add(ctx->process_table, newproc);
202 g_hash_table_insert(ctx->process_hash_table,
203 (gpointer) (unsigned long) tid, newproc);
204 if (lookup_tid_list(tid)) {
205 add_filter_tid_list(newproc);
206 }
207 ctx->nbnewthreads++;
208 ctx->nbthreads++;
209 }
210 newproc->comm = strdup(comm);
211 if (hostname) {
212 host = lookup_hostname_list(hostname);
213 if (!host)
214 host = add_hostname_list(hostname, 0);
215 if (!newproc->host || (newproc->host != host))
216 newproc->host = host;
217 if (is_hostname_filtered(hostname)) {
218 add_filter_tid_list(newproc);
219 }
220 }
221
222 return newproc;
223 }
224
225 struct processtop* update_proc(struct processtop* proc, int pid, int tid,
226 int ppid, int vpid, int vtid, int vppid, char *comm, char *hostname)
227 {
228 struct host *host;
229
230 if (proc) {
231 proc->pid = pid;
232 proc->tid = tid;
233 proc->ppid = ppid;
234 proc->vpid = vpid;
235 proc->vtid = vtid;
236 proc->vppid = vppid;
237 if (strcmp(proc->comm, comm) != 0) {
238 free(proc->comm);
239 proc->comm = strdup(comm);
240 }
241 if (hostname && !proc->host) {
242 host = lookup_hostname_list(hostname);
243 if (!host)
244 host = add_hostname_list(hostname, 0);
245 if (!proc->host || (proc->host != host))
246 proc->host = host;
247 if (is_hostname_filtered(hostname)) {
248 add_filter_tid_list(proc);
249 }
250 }
251 }
252 return proc;
253 }
254
255 /*
256 * This function just sets the time of death of a process.
257 * When we rotate the cputime we remove it from the process list.
258 */
259 void death_proc(struct lttngtop *ctx, int tid, char *comm,
260 unsigned long timestamp)
261 {
262 struct processtop *tmp;
263 tmp = find_process_tid(ctx, tid, comm);
264
265 g_hash_table_remove(ctx->process_hash_table,
266 (gpointer) (unsigned long) tid);
267 if (tmp && strcmp(tmp->comm, comm) == 0) {
268 tmp->death = timestamp;
269 ctx->nbdeadthreads++;
270 ctx->nbthreads--;
271 }
272 }
273
274 struct processtop* get_proc(struct lttngtop *ctx, int tid, char *comm,
275 unsigned long timestamp, char *hostname)
276 {
277 struct processtop *tmp;
278
279 tmp = find_process_tid(ctx, tid, comm);
280 if (tmp && strcmp(tmp->comm, comm) == 0) {
281 return tmp;
282 }
283 return add_proc(ctx, tid, comm, timestamp, hostname);
284 }
285
286 struct processtop *get_proc_pid(struct lttngtop *ctx, int tid, int pid,
287 unsigned long timestamp, char *hostname)
288 {
289 struct processtop *tmp;
290 tmp = find_process_tid(ctx, tid, NULL);
291 if (tmp && tmp->pid == pid)
292 return tmp;
293 return add_proc(ctx, tid, "Unknown", timestamp, hostname);
294 }
295
296 void add_thread(struct processtop *parent, struct processtop *thread)
297 {
298 gint i;
299 struct processtop *tmp;
300
301 if (!parent)
302 return;
303
304 for (i = 0; i < parent->threads->len; i++) {
305 tmp = g_ptr_array_index(parent->threads, i);
306 if (tmp == thread)
307 return;
308 }
309 g_ptr_array_add(parent->threads, thread);
310 }
311
312 struct cputime* add_cpu(int cpu)
313 {
314 struct cputime *newcpu;
315
316 newcpu = g_new0(struct cputime, 1);
317 newcpu->id = cpu;
318 newcpu->current_task = NULL;
319 newcpu->perf = g_hash_table_new(g_str_hash, g_str_equal);
320
321 g_ptr_array_add(lttngtop.cpu_table, newcpu);
322
323 return newcpu;
324 }
325 struct cputime* get_cpu(int cpu)
326 {
327 gint i;
328 struct cputime *tmp;
329
330 for (i = 0; i < lttngtop.cpu_table->len; i++) {
331 tmp = g_ptr_array_index(lttngtop.cpu_table, i);
332 if (tmp->id == cpu)
333 return tmp;
334 }
335
336 return add_cpu(cpu);
337 }
338
339 /*
340 * At the end of a sampling period, we need to display the cpu time for each
341 * process and to reset it to zero for the next period
342 */
343 void rotate_cputime(unsigned long end)
344 {
345 gint i;
346 struct cputime *tmp;
347 unsigned long elapsed;
348
349 for (i = 0; i < lttngtop.cpu_table->len; i++) {
350 tmp = g_ptr_array_index(lttngtop.cpu_table, i);
351 elapsed = end - tmp->task_start;
352 if (tmp->current_task) {
353 tmp->current_task->totalcpunsec += elapsed;
354 tmp->current_task->threadstotalcpunsec += elapsed;
355 if (tmp->current_task->pid != tmp->current_task->tid &&
356 tmp->current_task->threadparent) {
357 tmp->current_task->threadparent->threadstotalcpunsec += elapsed;
358 }
359 }
360 tmp->task_start = end;
361 }
362 }
363
364 void reset_perf_counter(gpointer key, gpointer value, gpointer user_data)
365 {
366 ((struct perfcounter*) value)->count = 0;
367 }
368
369 void copy_perf_counter(gpointer key, gpointer value, gpointer new_table)
370 {
371 struct perfcounter *newperf;
372
373 newperf = g_new0(struct perfcounter, 1);
374 newperf->count = ((struct perfcounter *) value)->count;
375 newperf->visible = ((struct perfcounter *) value)->visible;
376 newperf->sort = ((struct perfcounter *) value)->sort;
377 g_hash_table_insert((GHashTable *) new_table, strdup(key), newperf);
378 }
379
380 void copy_process_table(gpointer key, gpointer value, gpointer new_table)
381 {
382 g_hash_table_insert((GHashTable *) new_table, key, value);
383 }
384
385 void rotate_perfcounter() {
386 int i;
387 struct processtop *tmp;
388
389 for (i = 0; i < lttngtop.process_table->len; i++) {
390 tmp = g_ptr_array_index(lttngtop.process_table, i);
391 g_hash_table_foreach(tmp->perf, reset_perf_counter, NULL);
392 }
393 }
394
395 void cleanup_processtop()
396 {
397 gint i, j;
398 struct processtop *tmp;
399 struct files *tmpf; /* a temporary file */
400
401 for (i = 0; i < lttngtop.process_table->len; i++) {
402 tmp = g_ptr_array_index(lttngtop.process_table, i);
403 tmp->totalcpunsec = 0;
404 tmp->threadstotalcpunsec = 0;
405 tmp->fileread = 0;
406 tmp->filewrite = 0;
407
408 for (j = 0; j < tmp->process_files_table->len; j++) {
409 tmpf = g_ptr_array_index(tmp->process_files_table, j);
410 if (tmpf != NULL) {
411 tmpf->read = 0;
412 tmpf->write = 0;
413
414 if (tmpf->flag == __NR_close)
415 g_ptr_array_index(
416 tmp->process_files_table, j
417 ) = NULL;
418 }
419 }
420 }
421 }
422
423 void reset_global_counters()
424 {
425 lttngtop.nbnewproc = 0;
426 lttngtop.nbdeadproc = 0;
427 lttngtop.nbnewthreads = 0;
428 lttngtop.nbdeadthreads = 0;
429 lttngtop.nbnewfiles = 0;
430 lttngtop.nbclosedfiles = 0;
431 }
432
433 void copy_global_counters(struct lttngtop *dst)
434 {
435 dst->nbproc = lttngtop.nbproc;
436 dst->nbnewproc = lttngtop.nbnewproc;
437 dst->nbdeadproc = lttngtop.nbdeadproc;
438 dst->nbthreads = lttngtop.nbthreads;
439 dst->nbnewthreads = lttngtop.nbnewthreads;
440 dst->nbdeadthreads = lttngtop.nbdeadthreads;
441 dst->nbfiles = lttngtop.nbfiles;
442 dst->nbnewfiles = lttngtop.nbnewfiles;
443 dst->nbclosedfiles = lttngtop.nbclosedfiles;
444 reset_global_counters();
445 }
446
447 struct lttngtop* get_copy_lttngtop(unsigned long start, unsigned long end)
448 {
449 gint i, j;
450 unsigned long time;
451 struct lttngtop *dst;
452 struct processtop *tmp, *tmp2, *new;
453 struct cputime *tmpcpu, *newcpu;
454 struct files *tmpfile, *newfile;
455 struct kprobes *tmpprobe, *newprobe;
456
457 dst = g_new0(struct lttngtop, 1);
458 dst->start = start;
459 dst->end = end;
460 copy_global_counters(dst);
461 dst->process_table = g_ptr_array_new();
462 dst->files_table = g_ptr_array_new();
463 dst->cpu_table = g_ptr_array_new();
464 dst->kprobes_table = g_ptr_array_new();
465 dst->process_hash_table = g_hash_table_new(g_direct_hash, g_direct_equal);
466 g_hash_table_foreach(lttngtop.process_hash_table, copy_process_table,
467 dst->process_hash_table);
468
469 rotate_cputime(end);
470
471 for (i = 0; i < lttngtop.process_table->len; i++) {
472 tmp = g_ptr_array_index(lttngtop.process_table, i);
473 new = g_new0(struct processtop, 1);
474
475 memcpy(new, tmp, sizeof(struct processtop));
476 new->threads = g_ptr_array_new();
477 new->comm = strdup(tmp->comm);
478 new->process_files_table = g_ptr_array_new();
479 new->files_history = tmp->files_history;
480 new->perf = g_hash_table_new(g_str_hash, g_str_equal);
481 g_hash_table_foreach(tmp->perf, copy_perf_counter, new->perf);
482
483 /* compute the stream speed */
484 if (end - start != 0) {
485 time = (end - start) / NSEC_PER_SEC;
486 new->fileread = new->fileread/(time);
487 new->filewrite = new->filewrite/(time);
488 }
489
490 for (j = 0; j < tmp->process_files_table->len; j++) {
491 tmpfile = g_ptr_array_index(tmp->process_files_table, j);
492
493 newfile = malloc(sizeof(struct files));
494
495 if (tmpfile != NULL) {
496 memcpy(newfile, tmpfile, sizeof(struct files));
497 newfile->name = strdup(tmpfile->name);
498 newfile->ref = new;
499 g_ptr_array_add(new->process_files_table,
500 newfile);
501 g_ptr_array_add(dst->files_table, newfile);
502 } else {
503 g_ptr_array_add(new->process_files_table, NULL);
504 g_ptr_array_add(dst->files_table, NULL);
505 }
506 /*
507 * if the process died during the last period, we remove all
508 * files associated with if after the copy
509 */
510 if (tmp->death > 0 && tmp->death < end) {
511 /* FIXME : close the files before */
512 g_ptr_array_remove(tmp->process_files_table, tmpfile);
513 g_free(tmpfile);
514 }
515 }
516 g_ptr_array_add(dst->process_table, new);
517
518 /*
519 * if the process died during the last period, we remove it from
520 * the current process list after the copy
521 */
522 if (tmp->death > 0 && tmp->death < end) {
523 g_ptr_array_remove(lttngtop.process_table, tmp);
524 /* FIXME : TRUE does not mean clears the object in it */
525 g_ptr_array_free(tmp->threads, TRUE);
526 free(tmp->comm);
527 g_ptr_array_free(tmp->process_files_table, TRUE);
528 /* FIXME : clear elements */
529 g_hash_table_destroy(tmp->perf);
530 g_free(tmp);
531 }
532 }
533 rotate_perfcounter();
534
535 for (i = 0; i < lttngtop.cpu_table->len; i++) {
536 tmpcpu = g_ptr_array_index(lttngtop.cpu_table, i);
537 newcpu = g_new0(struct cputime, 1);
538 memcpy(newcpu, tmpcpu, sizeof(struct cputime));
539 newcpu->perf = g_hash_table_new(g_str_hash, g_str_equal);
540 g_hash_table_foreach(tmpcpu->perf, copy_perf_counter, newcpu->perf);
541 /*
542 * note : we don't care about the current process pointer in the copy
543 * so the reference is invalid after the memcpy
544 */
545 g_ptr_array_add(dst->cpu_table, newcpu);
546 }
547 if (lttngtop.kprobes_table) {
548 for (i = 0; i < lttngtop.kprobes_table->len; i++) {
549 tmpprobe = g_ptr_array_index(lttngtop.kprobes_table, i);
550 newprobe = g_new0(struct kprobes, 1);
551 memcpy(newprobe, tmpprobe, sizeof(struct kprobes));
552 tmpprobe->count = 0;
553 g_ptr_array_add(dst->kprobes_table, newprobe);
554 }
555 }
556 /* FIXME : better algo */
557 /* create the threads index if required */
558 for (i = 0; i < dst->process_table->len; i++) {
559 tmp = g_ptr_array_index(dst->process_table, i);
560 if (tmp->pid == tmp->tid) {
561 for (j = 0; j < dst->process_table->len; j++) {
562 tmp2 = g_ptr_array_index(dst->process_table, j);
563 if (tmp2->pid == tmp->pid) {
564 tmp2->threadparent = tmp;
565 g_ptr_array_add(tmp->threads, tmp2);
566 }
567 }
568 }
569 }
570
571 // update_global_stats(dst);
572 cleanup_processtop();
573
574 return dst;
575 }
576
577
578 enum bt_cb_ret handle_statedump_process_state(struct bt_ctf_event *call_data,
579 void *private_data)
580 {
581 const struct bt_definition *scope;
582 struct processtop *proc;
583 unsigned long timestamp;
584 int64_t pid, tid, ppid, vtid, vpid, vppid;
585 char *procname, *hostname = NULL;
586
587 timestamp = bt_ctf_get_timestamp(call_data);
588 if (timestamp == -1ULL)
589 goto error;
590
591 scope = bt_ctf_get_top_level_scope(call_data,
592 BT_EVENT_FIELDS);
593 pid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
594 scope, "_pid"));
595 if (bt_ctf_field_get_error()) {
596 fprintf(stderr, "Missing pid context info\n");
597 goto error;
598 }
599 ppid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
600 scope, "_ppid"));
601 if (bt_ctf_field_get_error()) {
602 fprintf(stderr, "Missing ppid context info\n");
603 goto error;
604 }
605 tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
606 scope, "_tid"));
607 if (bt_ctf_field_get_error()) {
608 fprintf(stderr, "Missing tid context info\n");
609 goto error;
610 }
611 vtid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
612 scope, "_vtid"));
613 if (bt_ctf_field_get_error()) {
614 fprintf(stderr, "Missing vtid context info\n");
615 goto error;
616 }
617 vpid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
618 scope, "_vpid"));
619 if (bt_ctf_field_get_error()) {
620 fprintf(stderr, "Missing vpid context info\n");
621 goto error;
622 }
623 vppid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
624 scope, "_vppid"));
625 if (bt_ctf_field_get_error()) {
626 fprintf(stderr, "Missing vppid context info\n");
627 goto error;
628 }
629
630 scope = bt_ctf_get_top_level_scope(call_data,
631 BT_EVENT_FIELDS);
632 procname = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
633 scope, "_name"));
634 if (bt_ctf_field_get_error()) {
635 fprintf(stderr, "Missing process name context info\n");
636 goto error;
637 }
638
639 proc = find_process_tid(&lttngtop, tid, procname);
640 if (proc == NULL)
641 proc = add_proc(&lttngtop, tid, procname, timestamp, hostname);
642 update_proc(proc, pid, tid, ppid, vpid, vtid, vppid, procname, hostname);
643
644 if (proc) {
645 free(proc->comm);
646 proc->comm = strdup(procname);
647 proc->pid = pid;
648 }
649
650 return BT_CB_OK;
651
652 error:
653 return BT_CB_ERROR_STOP;
654 }
655
656 struct tm format_timestamp(uint64_t timestamp)
657 {
658 struct tm tm;
659 uint64_t ts_sec = 0, ts_nsec;
660 time_t time_s;
661
662 ts_nsec = timestamp;
663 ts_sec += ts_nsec / NSEC_PER_SEC;
664 ts_nsec = ts_nsec % NSEC_PER_SEC;
665
666 time_s = (time_t) ts_sec;
667
668 localtime_r(&time_s, &tm);
669
670 return tm;
671 }
672
673 int *lookup_tid_list(int tid)
674 {
675 if (!tid_filter_list)
676 return NULL;
677
678 return g_hash_table_lookup(tid_filter_list, (gpointer) &tid);
679 }
680
681 struct host *lookup_hostname_list(const char *hostname)
682 {
683 if (!hostname || !global_host_list)
684 return NULL;
685
686 return g_hash_table_lookup(global_host_list, (gpointer) hostname);
687 }
688
689 int is_hostname_filtered(const char *hostname)
690 {
691 struct host *host;
692
693 host = lookup_hostname_list(hostname);
694 if (host)
695 return host->filter;
696 return 0;
697 }
698
699 int *lookup_filter_tid_list(int tid)
700 {
701 return g_hash_table_lookup(global_filter_list, (gpointer) &tid);
702 }
703
704 void add_filter_tid_list(struct processtop *proc)
705 {
706 unsigned long *hash_tid;
707
708 hash_tid = malloc(sizeof(unsigned long));
709 *hash_tid = proc->tid;
710 g_hash_table_insert(global_filter_list,
711 (gpointer) (unsigned long) hash_tid, proc);
712 }
713
714 void remove_filter_tid_list(int tid)
715 {
716 g_hash_table_remove(global_filter_list,
717 (gpointer) (unsigned long) &tid);
718 }
719
720 struct host *add_hostname_list(char *hostname, int filter)
721 {
722 struct host *host;
723
724 host = lookup_hostname_list(hostname);
725 if (host)
726 return host;
727
728 host = g_new0(struct host, 1);
729 host->hostname = strdup(hostname);
730 host->filter = filter;
731 g_hash_table_insert(global_host_list,
732 (gpointer) host->hostname,
733 (gpointer) host);
734
735 return host;
736 }
737
738 void update_hostname_filter(struct host *host)
739 {
740 struct processtop *tmp;
741 int i;
742
743 for (i = 0; i < lttngtop.process_table->len; i++) {
744 tmp = g_ptr_array_index(lttngtop.process_table, i);
745 if (tmp->host == host) {
746 if (host->filter)
747 add_filter_tid_list(tmp);
748 else
749 remove_filter_tid_list(tmp->tid);
750 }
751 }
752 }
This page took 0.043178 seconds and 4 git commands to generate.