Initial import of code.
[lttngtop.git] / lttngtop / iostreamtop.c
CommitLineData
1fc22eb4
JD
1/*
2 * Copyright (C) 2011 Mathieu Bain <mathieu.bain@polymtl.ca>
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
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19#include <babeltrace/babeltrace.h>
20
21#include "lttngtoptypes.h"
22#include "common.h"
23#include "iostreamtop.h"
24
25#include <stdlib.h>
26
27int update_iostream_ret(struct lttngtop *ctx, int tid, char *comm,
28 unsigned long timestamp, int cpu_id, int ret)
29{
30 struct processtop *tmp;
31 int err = 0;
32
33 tmp = get_proc(ctx, tid, comm, timestamp);
34 if ((tmp->iostream->syscall_info != NULL) && (tmp->iostream->syscall_info->cpu_id == cpu_id)) {
35 if (tmp->iostream->syscall_info->type == __NR_read && ret > 0) {
36 tmp->iostream->ret_read += ret;
37 tmp->iostream->ret_total += ret;
38 } else if(tmp->iostream->syscall_info->type == __NR_write && ret > 0) {
39 tmp->iostream->ret_write += ret;
40 tmp->iostream->ret_total += ret;
41 } else{
42 err = -1;
43 }
44 free(tmp->iostream->syscall_info);
45 tmp->iostream->syscall_info = NULL;
46 }
47
48 return err;
49}
50
51enum bt_cb_ret handle_exit_syscall(struct bt_ctf_event *call_data,
52 void *private_data)
53{
54 struct definition *scope;
55 unsigned long timestamp;
56 char *comm;
57 uint64_t ret, tid;
58 int64_t cpu_id;
59
60 timestamp = bt_ctf_get_timestamp(call_data);
61 if (timestamp == -1ULL)
62 goto error;
63
64 scope = bt_ctf_get_top_level_scope(call_data,
65 BT_STREAM_EVENT_CONTEXT);
66 comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
67 scope, "_procname"));
68 if (bt_ctf_field_get_error()) {
69 fprintf(stderr, "Missing procname context info\n");
70 goto error;
71 }
72
73 tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
74 scope, "_tid"));
75 if (bt_ctf_field_get_error()) {
76 fprintf(stderr, "Missing tid context info\n");
77 goto error;
78 }
79
80 scope = bt_ctf_get_top_level_scope(call_data,
81 BT_EVENT_FIELDS);
82 ret = bt_ctf_get_int64(bt_ctf_get_field(call_data,
83 scope, "_ret"));
84 if (bt_ctf_field_get_error()) {
85 fprintf(stderr, "Missing ret context info\n");
86 goto error;
87 }
88
89 scope = bt_ctf_get_top_level_scope(call_data,
90 BT_STREAM_PACKET_CONTEXT);
91 cpu_id = bt_ctf_get_uint64(bt_ctf_get_field(call_data,
92 scope, "cpu_id"));
93 if (bt_ctf_field_get_error()) {
94 fprintf(stderr, "Missing cpu_id context info\n");
95 goto error;
96 }
97
98 /*
99 * if we encounter an exit_syscall and it is not for a syscall read or write
100 * we just abort the execution of this callback
101 */
102 if ((update_iostream_ret(&lttngtop, tid, comm, timestamp, cpu_id, ret)) < 0)
103 return BT_CB_ERROR_CONTINUE;
104
105 return BT_CB_OK;
106
107error:
108 return BT_CB_ERROR_STOP;
109}
110
111
112enum bt_cb_ret handle_sys_write(struct bt_ctf_event *call_data,
113 void *private_data)
114{
115 struct definition *scope;
116 struct processtop *tmp;
117 struct syscalls *syscall_info;
118 unsigned long timestamp;
119 uint64_t cpu_id;
120 char *comm;
121 int64_t tid;
122
123 timestamp = bt_ctf_get_timestamp(call_data);
124 if (timestamp == -1ULL)
125 goto error;
126
127 scope = bt_ctf_get_top_level_scope(call_data,
128 BT_STREAM_EVENT_CONTEXT);
129 comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
130 scope, "_procname"));
131 if (bt_ctf_field_get_error()) {
132 fprintf(stderr, "Missing procname context info\n");
133 goto error;
134 }
135
136 tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
137 scope, "_tid"));
138 if (bt_ctf_field_get_error()) {
139 fprintf(stderr, "Missing tid context info\n");
140 goto error;
141 }
142
143 scope = bt_ctf_get_top_level_scope(call_data,
144 BT_STREAM_PACKET_CONTEXT);
145 cpu_id = bt_ctf_get_uint64(bt_ctf_get_field(call_data,
146 scope, "cpu_id"));
147 if (bt_ctf_field_get_error()) {
148 fprintf(stderr, "Missing cpu_id context info\n");
149 goto error;
150 }
151
152 syscall_info = malloc(sizeof(struct syscalls));
153 syscall_info->cpu_id = cpu_id;
154 syscall_info->type = __NR_write;
155 syscall_info->tid = tid;
156 tmp = get_proc(&lttngtop, tid, comm, timestamp);
157 tmp->iostream->syscall_info = syscall_info;
158
159 return BT_CB_OK;
160
161error:
162 return BT_CB_ERROR_STOP;
163}
164
165enum bt_cb_ret handle_sys_read(struct bt_ctf_event *call_data,
166 void *private_data)
167{
168 struct processtop *tmp;
169 struct definition *scope;
170 struct syscalls * syscall_info;
171 unsigned long timestamp;
172 uint64_t cpu_id;
173 char *comm;
174 int64_t tid;
175
176 timestamp = bt_ctf_get_timestamp(call_data);
177 if (timestamp == -1ULL)
178 goto error;
179
180 scope = bt_ctf_get_top_level_scope(call_data,
181 BT_STREAM_EVENT_CONTEXT);
182 comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
183 scope, "_procname"));
184 if (bt_ctf_field_get_error()) {
185 fprintf(stderr, "Missing procname context info\n");
186 goto error;
187 }
188
189 tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
190 scope, "_tid"));
191 if (bt_ctf_field_get_error()) {
192 fprintf(stderr, "Missing tid context info\n");
193 goto error;
194 }
195
196 scope = bt_ctf_get_top_level_scope(call_data,
197 BT_STREAM_PACKET_CONTEXT);
198 cpu_id = bt_ctf_get_uint64(bt_ctf_get_field(call_data,
199 scope, "cpu_id"));
200 if (bt_ctf_field_get_error()) {
201 fprintf(stderr, "Missing cpu_id context info\n");
202 goto error;
203 }
204
205 syscall_info = malloc(sizeof(struct syscalls));
206 syscall_info->cpu_id = cpu_id;
207 syscall_info->type = __NR_read;
208 syscall_info->tid = tid;
209 tmp = get_proc(&lttngtop, tid, comm, timestamp);
210 tmp->iostream->syscall_info = syscall_info;
211
212 return BT_CB_OK;
213
214error:
215 return BT_CB_ERROR_STOP;
216}
217
This page took 0.042513 seconds and 4 git commands to generate.