2 * Copyright (C) 2011 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"
24 void update_cputop_data(unsigned long timestamp
, int64_t cpu
, int prev_pid
,
25 int next_pid
, char *prev_comm
, char *next_comm
)
27 struct cputime
*tmpcpu
;
28 unsigned long elapsed
;
30 tmpcpu
= get_cpu(cpu
);
32 if (tmpcpu
->current_task
&& tmpcpu
->current_task
->pid
== prev_pid
) {
33 elapsed
= timestamp
- tmpcpu
->task_start
;
34 tmpcpu
->current_task
->totalcpunsec
+= elapsed
;
35 tmpcpu
->current_task
->threadstotalcpunsec
+= elapsed
;
36 if (tmpcpu
->current_task
->pid
!= tmpcpu
->current_task
->tid
)
37 tmpcpu
->current_task
->threadparent
->threadstotalcpunsec
+= elapsed
;
41 tmpcpu
->current_task
= get_proc(<tngtop
, next_pid
, next_comm
, timestamp
);
43 tmpcpu
->current_task
= NULL
;
45 tmpcpu
->task_start
= timestamp
;
48 enum bt_cb_ret
handle_sched_switch(struct bt_ctf_event
*call_data
,
51 struct definition
*scope
;
52 unsigned long timestamp
;
54 char *prev_comm
, *next_comm
;
55 int prev_tid
, next_tid
;
57 timestamp
= bt_ctf_get_timestamp(call_data
);
58 if (timestamp
== -1ULL)
61 scope
= bt_ctf_get_top_level_scope(call_data
,
63 prev_comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
64 scope
, "_prev_comm"));
65 if (bt_ctf_field_get_error()) {
66 fprintf(stderr
, "Missing prev_comm context info\n");
70 next_comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
71 scope
, "_next_comm"));
72 if (bt_ctf_field_get_error()) {
73 fprintf(stderr
, "Missing next_comm context info\n");
77 prev_tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
79 if (bt_ctf_field_get_error()) {
80 fprintf(stderr
, "Missing prev_tid context info\n");
84 next_tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
86 if (bt_ctf_field_get_error()) {
87 fprintf(stderr
, "Missing next_tid context info\n");
91 cpu_id
= get_cpu_id(call_data
);
93 update_cputop_data(timestamp
, cpu_id
, prev_tid
, next_tid
,
94 prev_comm
, next_comm
);
99 return BT_CB_ERROR_STOP
;
102 enum bt_cb_ret
handle_sched_process_free(struct bt_ctf_event
*call_data
,
105 struct definition
*scope
;
106 unsigned long timestamp
;
110 timestamp
= bt_ctf_get_timestamp(call_data
);
111 if (timestamp
== -1ULL)
114 scope
= bt_ctf_get_top_level_scope(call_data
,
116 comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
118 if (bt_ctf_field_get_error()) {
119 fprintf(stderr
, "Missing procname context info\n");
123 tid
= get_context_tid(call_data
);
124 death_proc(<tngtop
, tid
, comm
, timestamp
);
129 return BT_CB_ERROR_STOP
;
This page took 0.042955 seconds and 5 git commands to generate.