Reset selected_line while switching to process_details view and back
[lttngtop.git] / src / cputop.c
CommitLineData
1fc22eb4 1/*
aa15ac1c 2 * Copyright (C) 2011-2012 Julien Desfossez
1fc22eb4
JD
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 *
71bd7ce1
AM
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.
1fc22eb4
JD
16 */
17
18#include <babeltrace/babeltrace.h>
19
20#include "lttngtoptypes.h"
21#include "common.h"
22#include "cputop.h"
23
24void update_cputop_data(unsigned long timestamp, int64_t cpu, int prev_pid,
25 int next_pid, char *prev_comm, char *next_comm)
26{
27 struct cputime *tmpcpu;
28 unsigned long elapsed;
29
30 tmpcpu = get_cpu(cpu);
31
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;
38 }
39
40 if (next_pid != 0)
41 tmpcpu->current_task = get_proc(&lttngtop, next_pid, next_comm, timestamp);
42 else
43 tmpcpu->current_task = NULL;
44
45 tmpcpu->task_start = timestamp;
46}
47
4adc8274 48enum bt_cb_ret handle_sched_switch(struct bt_ctf_event *call_data,
1fc22eb4
JD
49 void *private_data)
50{
2e0a1190 51 const struct bt_definition *scope;
1fc22eb4
JD
52 unsigned long timestamp;
53 uint64_t cpu_id;
54 char *prev_comm, *next_comm;
55 int prev_tid, next_tid;
56
480b40ce 57 timestamp = bt_ctf_get_timestamp(call_data);
1fc22eb4
JD
58 if (timestamp == -1ULL)
59 goto error;
60
61 scope = bt_ctf_get_top_level_scope(call_data,
62 BT_EVENT_FIELDS);
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");
67 goto error;
68 }
69
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");
74 goto error;
75 }
76
77 prev_tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
78 scope, "_prev_tid"));
79 if (bt_ctf_field_get_error()) {
80 fprintf(stderr, "Missing prev_tid context info\n");
81 goto error;
82 }
83
84 next_tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
85 scope, "_next_tid"));
86 if (bt_ctf_field_get_error()) {
87 fprintf(stderr, "Missing next_tid context info\n");
88 goto error;
89 }
90
d67167cd 91 cpu_id = get_cpu_id(call_data);
1fc22eb4
JD
92
93 update_cputop_data(timestamp, cpu_id, prev_tid, next_tid,
94 prev_comm, next_comm);
95
96 return BT_CB_OK;
97
98error:
99 return BT_CB_ERROR_STOP;
100}
101
4adc8274 102enum bt_cb_ret handle_sched_process_free(struct bt_ctf_event *call_data,
1fc22eb4
JD
103 void *private_data)
104{
2e0a1190 105 const struct bt_definition *scope;
1fc22eb4
JD
106 unsigned long timestamp;
107 char *comm;
108 int tid;
109
480b40ce 110 timestamp = bt_ctf_get_timestamp(call_data);
1fc22eb4
JD
111 if (timestamp == -1ULL)
112 goto error;
113
114 scope = bt_ctf_get_top_level_scope(call_data,
115 BT_EVENT_FIELDS);
116 comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
117 scope, "_comm"));
118 if (bt_ctf_field_get_error()) {
119 fprintf(stderr, "Missing procname context info\n");
120 goto error;
121 }
122
e05a35a6
JD
123 tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
124 scope, "_tid"));
125 if (bt_ctf_field_get_error()) {
126 fprintf(stderr, "Missing tid field\n");
127 goto error;
128 }
129
1fc22eb4
JD
130 death_proc(&lttngtop, tid, comm, timestamp);
131
132 return BT_CB_OK;
133
134error:
135 return BT_CB_ERROR_STOP;
136
137}
138
This page took 0.029219 seconds and 4 git commands to generate.