cdc1bdf1e0251875e008b231cf0db6b7fb37c328
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
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"
25 void update_cputop_data(unsigned long timestamp
, int64_t cpu
, int prev_pid
,
26 int next_pid
, char *prev_comm
, char *next_comm
)
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
->pid
!= tmpcpu
->current_task
->tid
)
38 tmpcpu
->current_task
->threadparent
->threadstotalcpunsec
+= elapsed
;
42 tmpcpu
->current_task
= get_proc(<tngtop
, next_pid
, next_comm
, timestamp
);
44 tmpcpu
->current_task
= NULL
;
46 tmpcpu
->task_start
= timestamp
;
49 enum bt_cb_ret
handle_sched_switch(struct bt_ctf_event
*call_data
,
52 struct definition
*scope
;
53 unsigned long timestamp
;
55 char *prev_comm
, *next_comm
;
56 int prev_tid
, next_tid
;
58 timestamp
= bt_ctf_get_timestamp(call_data
);
59 if (timestamp
== -1ULL)
62 scope
= bt_ctf_get_top_level_scope(call_data
,
64 prev_comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
65 scope
, "_prev_comm"));
66 if (bt_ctf_field_get_error()) {
67 fprintf(stderr
, "Missing prev_comm context info\n");
71 next_comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
72 scope
, "_next_comm"));
73 if (bt_ctf_field_get_error()) {
74 fprintf(stderr
, "Missing next_comm context info\n");
78 prev_tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
80 if (bt_ctf_field_get_error()) {
81 fprintf(stderr
, "Missing prev_tid context info\n");
85 next_tid
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
87 if (bt_ctf_field_get_error()) {
88 fprintf(stderr
, "Missing next_tid context info\n");
92 cpu_id
= get_cpu_id(call_data
);
94 update_cputop_data(timestamp
, cpu_id
, prev_tid
, next_tid
,
95 prev_comm
, next_comm
);
100 return BT_CB_ERROR_STOP
;
103 enum bt_cb_ret
handle_sched_process_free(struct bt_ctf_event
*call_data
,
106 struct definition
*scope
;
107 unsigned long timestamp
;
111 timestamp
= bt_ctf_get_timestamp(call_data
);
112 if (timestamp
== -1ULL)
115 scope
= bt_ctf_get_top_level_scope(call_data
,
117 comm
= bt_ctf_get_char_array(bt_ctf_get_field(call_data
,
119 if (bt_ctf_field_get_error()) {
120 fprintf(stderr
, "Missing procname context info\n");
124 tid
= get_context_tid(call_data
);
125 death_proc(<tngtop
, tid
, comm
, timestamp
);
130 return BT_CB_ERROR_STOP
;
This page took 0.055301 seconds and 4 git commands to generate.