1594df7543e669d75f45c92bb3d0d6b4b9d034b6
2 * Copyright (C) 2011 Mathieu Bain <mathieu.bain@polymtl.ca>
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;
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.
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,
19 #include <babeltrace/babeltrace.h>
21 #include "lttngtoptypes.h"
23 #include "iostreamtop.h"
27 int update_iostream_ret(struct lttngtop
*ctx
, int tid
, char *comm
,
28 unsigned long timestamp
, int cpu_id
, int ret
)
30 struct processtop
*tmp
;
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
;
44 free(tmp
->iostream
->syscall_info
);
45 tmp
->iostream
->syscall_info
= NULL
;
51 enum bt_cb_ret
handle_exit_syscall(struct bt_ctf_event
*call_data
,
54 struct definition
*scope
;
55 unsigned long timestamp
;
60 timestamp
= bt_ctf_get_timestamp(call_data
);
61 if (timestamp
== -1ULL)
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
,
68 if (bt_ctf_field_get_error()) {
69 fprintf(stderr
, "Missing procname context info\n");
73 tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
75 if (bt_ctf_field_get_error()) {
76 fprintf(stderr
, "Missing tid context info\n");
80 scope
= bt_ctf_get_top_level_scope(call_data
,
82 ret
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
84 if (bt_ctf_field_get_error()) {
85 fprintf(stderr
, "Missing ret context info\n");
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
,
93 if (bt_ctf_field_get_error()) {
94 fprintf(stderr
, "Missing cpu_id context info\n");
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
102 if ((update_iostream_ret(<tngtop
, tid
, comm
, timestamp
, cpu_id
, ret
)) < 0)
103 return BT_CB_ERROR_CONTINUE
;
108 return BT_CB_ERROR_STOP
;
112 enum bt_cb_ret
handle_sys_write(struct bt_ctf_event
*call_data
,
115 struct definition
*scope
;
116 struct processtop
*tmp
;
117 struct syscalls
*syscall_info
;
118 unsigned long timestamp
;
123 timestamp
= bt_ctf_get_timestamp(call_data
);
124 if (timestamp
== -1ULL)
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");
136 tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
138 if (bt_ctf_field_get_error()) {
139 fprintf(stderr
, "Missing tid context info\n");
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
,
147 if (bt_ctf_field_get_error()) {
148 fprintf(stderr
, "Missing cpu_id context info\n");
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(<tngtop
, tid
, comm
, timestamp
);
157 tmp
->iostream
->syscall_info
= syscall_info
;
162 return BT_CB_ERROR_STOP
;
165 enum bt_cb_ret
handle_sys_read(struct bt_ctf_event
*call_data
,
168 struct processtop
*tmp
;
169 struct definition
*scope
;
170 struct syscalls
* syscall_info
;
171 unsigned long timestamp
;
176 timestamp
= bt_ctf_get_timestamp(call_data
);
177 if (timestamp
== -1ULL)
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");
189 tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
191 if (bt_ctf_field_get_error()) {
192 fprintf(stderr
, "Missing tid context info\n");
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
,
200 if (bt_ctf_field_get_error()) {
201 fprintf(stderr
, "Missing cpu_id context info\n");
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(<tngtop
, tid
, comm
, timestamp
);
210 tmp
->iostream
->syscall_info
= syscall_info
;
215 return BT_CB_ERROR_STOP
;
This page took 0.033745 seconds and 3 git commands to generate.