Cleanup : removed F4 and F5 empty panels
[lttngtop.git] / src / cputop.c
CommitLineData
1fc22eb4
JD
1/*
2 * Copyright (C) 2011 Julien Desfossez
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
48enum bt_cb_ret handle_sched_switch(struct bt_ctf_event *call_data,
49 void *private_data)
50{
3ba84bed 51 const struct 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
57 timestamp = bt_ctf_get_timestamp(call_data);
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
102enum bt_cb_ret handle_sched_process_free(struct bt_ctf_event *call_data,
103 void *private_data)
104{
3ba84bed 105 const struct definition *scope;
1fc22eb4
JD
106 unsigned long timestamp;
107 char *comm;
108 int tid;
109
110 timestamp = bt_ctf_get_timestamp(call_data);
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
1dec520a 123 tid = get_context_tid(call_data);
1fc22eb4
JD
124 death_proc(&lttngtop, tid, comm, timestamp);
125
126 return BT_CB_OK;
127
128error:
129 return BT_CB_ERROR_STOP;
130
131}
132
This page took 0.037819 seconds and 4 git commands to generate.