| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #define _GNU_SOURCE |
| 20 | #include <errno.h> |
| 21 | #include <limits.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <urcu/list.h> |
| 26 | |
| 27 | #include "lttngerr.h" |
| 28 | #include "trace.h" |
| 29 | #include "session.h" |
| 30 | |
| 31 | /* |
| 32 | * find_session_ust_trace_by_pid |
| 33 | * |
| 34 | * Iterate over the session ust_traces and |
| 35 | * return a pointer or NULL if not found. |
| 36 | */ |
| 37 | struct ltt_ust_trace *find_session_ust_trace_by_pid(struct ltt_session *session, pid_t pid) |
| 38 | { |
| 39 | struct ltt_ust_trace *iter; |
| 40 | |
| 41 | cds_list_for_each_entry(iter, &session->ust_traces, list) { |
| 42 | if (iter->pid == pid) { |
| 43 | /* Found */ |
| 44 | return iter; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return NULL; |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * get_trace_count_per_session |
| 53 | * |
| 54 | * Return the total count of traces (ust and kernel) |
| 55 | * for the specified session. |
| 56 | */ |
| 57 | int get_trace_count_per_session(struct ltt_session *session) |
| 58 | { |
| 59 | return session->ust_trace_count + session->kern_trace_count; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * get_traces_per_session |
| 64 | * |
| 65 | * Fill the lttng_trace array of all the |
| 66 | * available trace of the session. |
| 67 | */ |
| 68 | void get_traces_per_session(struct ltt_session *session, struct lttng_trace *traces) |
| 69 | { |
| 70 | int i = 0; |
| 71 | struct ltt_ust_trace *ust_iter; |
| 72 | struct ltt_kernel_trace *kern_iter; |
| 73 | struct lttng_trace trace; |
| 74 | |
| 75 | DBG("Getting userspace traces for session %s", session->name); |
| 76 | |
| 77 | /* Getting userspace traces */ |
| 78 | cds_list_for_each_entry(ust_iter, &session->ust_traces, list) { |
| 79 | trace.type = USERSPACE; |
| 80 | trace.pid = ust_iter->pid; |
| 81 | strncpy(trace.name, ust_iter->name, sizeof(trace.name)); |
| 82 | trace.name[sizeof(trace.name) - 1] = '\0'; |
| 83 | memcpy(&traces[i], &trace, sizeof(trace)); |
| 84 | memset(&trace, 0, sizeof(trace)); |
| 85 | i++; |
| 86 | } |
| 87 | |
| 88 | DBG("Getting kernel traces for session %s", session->name); |
| 89 | |
| 90 | /* Getting kernel traces */ |
| 91 | cds_list_for_each_entry(kern_iter, &session->kernel_traces, list) { |
| 92 | trace.type = KERNEL; |
| 93 | strncpy(trace.name, kern_iter->name, sizeof(trace.name)); |
| 94 | trace.name[sizeof(trace.name) - 1] = '\0'; |
| 95 | memcpy(&traces[i], &trace, sizeof(trace)); |
| 96 | memset(&trace, 0, sizeof(trace)); |
| 97 | i++; |
| 98 | } |
| 99 | } |