2 * Copyright (C) 2011-2012 Julien Desfossez
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 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.
18 #include <babeltrace/babeltrace.h>
20 #include "lttngtoptypes.h"
25 void update_cputop_data(unsigned long timestamp
, int64_t cpu
, int prev_pid
,
26 int next_pid
, char *prev_comm
, char *next_comm
, char *hostname
)
28 struct cputime
*tmpcpu
;
29 unsigned long elapsed
;
31 tmpcpu
= get_cpu(cpu
);
33 if (tmpcpu
->current_task
&& tmpcpu
->current_task
->pid
== prev_pid
) {
34 elapsed
= timestamp
- tmpcpu
->task_start
;
35 tmpcpu
->current_task
->totalcpunsec
+= elapsed
;
36 tmpcpu
->current_task
->threadstotalcpunsec
+= elapsed
;
37 if (tmpcpu
->current_task
->threadparent
&&
38 tmpcpu
->current_task
->pid
!= tmpcpu
->current_task
->tid
)
39 tmpcpu
->current_task
->threadparent
->threadstotalcpunsec
+= elapsed
;
43 tmpcpu
->current_task
= get_proc(<tngtop
, next_pid
, next_comm
,
46 tmpcpu
->current_task
= NULL
;
48 tmpcpu
->task_start
= timestamp
;
51 enum bt_cb_ret
handle_sched_switch(struct bt_ctf_event
*call_data
,
54 const struct bt_definition
*scope
;
55 unsigned long timestamp
;
57 char *prev_comm
, *next_comm
;
58 int prev_tid
, next_tid
;
59 char *hostname
= NULL
;
61 timestamp
= bt_ctf_get_timestamp(call_data
);
62 if (timestamp
== -1ULL)
65 scope
= bt_ctf_get_top_level_scope(call_data
,
67 prev_comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
68 scope
, "_prev_comm"));
69 if (bt_ctf_field_get_error()) {
70 fprintf(stderr
, "Missing prev_comm context info\n");
74 next_comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
75 scope
, "_next_comm"));
76 if (bt_ctf_field_get_error()) {
77 fprintf(stderr
, "Missing next_comm context info\n");
81 prev_tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
83 if (bt_ctf_field_get_error()) {
84 fprintf(stderr
, "Missing prev_tid context info\n");
88 next_tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
90 if (bt_ctf_field_get_error()) {
91 fprintf(stderr
, "Missing next_tid context info\n");
95 cpu_id
= get_cpu_id(call_data
);
97 update_cputop_data(timestamp
, cpu_id
, prev_tid
, next_tid
,
98 prev_comm
, next_comm
, hostname
);
103 return BT_CB_ERROR_STOP
;
106 enum bt_cb_ret
handle_sched_process_free(struct bt_ctf_event
*call_data
,
109 const struct bt_definition
*scope
;
110 unsigned long timestamp
;
114 timestamp
= bt_ctf_get_timestamp(call_data
);
115 if (timestamp
== -1ULL)
118 scope
= bt_ctf_get_top_level_scope(call_data
,
120 comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
122 if (bt_ctf_field_get_error()) {
123 fprintf(stderr
, "Missing procname context info\n");
127 tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
129 if (bt_ctf_field_get_error()) {
130 fprintf(stderr
, "Missing tid field\n");
133 if (tid
== opt_exec_pid
) {
137 death_proc(<tngtop
, tid
, comm
, timestamp
);
142 return BT_CB_ERROR_STOP
;
146 enum bt_cb_ret
handle_sched_process_fork(struct bt_ctf_event
*call_data
,
149 const struct bt_definition
*scope
;
150 struct processtop
*tmp
;
151 int tid
, *hash_tid
, parent_pid
;
152 unsigned long timestamp
;
155 timestamp
= bt_ctf_get_timestamp(call_data
);
156 if (timestamp
== -1ULL)
159 scope
= bt_ctf_get_top_level_scope(call_data
,
161 comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
162 scope
, "_child_comm"));
163 if (bt_ctf_field_get_error()) {
164 fprintf(stderr
, "Missing procname context info\n");
168 tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
169 scope
, "_child_tid"));
170 if (bt_ctf_field_get_error()) {
171 fprintf(stderr
, "Missing child_tid field\n");
175 parent_pid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
176 scope
, "_parent_pid"));
177 if (bt_ctf_field_get_error()) {
178 fprintf(stderr
, "Missing parent_pid field\n");
182 tmp
= get_proc(<tngtop
, tid
, comm
, timestamp
, NULL
);
185 hash_tid
= lookup_filter_tid_list(parent_pid
);
187 add_filter_tid_list(tmp
);
194 return BT_CB_ERROR_STOP
;
This page took 0.03344 seconds and 4 git commands to generate.