2 * blktrace output analysis: generate a timeline & gather statistics
4 * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define N_PID_HASH 128
26 #define PID_HASH(pid) ((pid) & (N_PID_HASH-1))
27 struct list_head *pid_heads = NULL;
29 static void init_pid_heads(void)
33 pid_heads = zmalloc(N_PID_HASH * sizeof(struct list_head));
34 for (i = 0; i < N_PID_HASH; i++)
35 INIT_LIST_HEAD(&pid_heads[i]);
38 static inline struct p_info *pid_to_proc(__u32 pid)
41 struct list_head *p, *head;
43 if (pid_heads == NULL) init_pid_heads();
45 head = &pid_heads[PID_HASH(pid)];
46 __list_for_each(p, head) {
47 pp = list_entry(p, struct p_pid, head);
55 void insert_proc_hash(struct p_info *pip, __u32 pid)
57 struct p_pid *pp = zmalloc(sizeof(*pp));
59 if (pid_heads == NULL) init_pid_heads();
64 list_add_tail(&pp->head, &pid_heads[PID_HASH(pid)]);
67 int __find_process_pid(__u32 pid)
69 return pid_to_proc(pid) != NULL;
72 struct p_info *find_process(__u32 pid, char *name)
77 if (pid != ((__u32)-1) && (pip = pid_to_proc(pid)))
81 __list_for_each(p, &all_procs) {
82 pip = list_entry(p, struct p_info, head);
83 if (name && !strcmp(pip->name, name)) {
84 if (pid != ((__u32)-1))
85 insert_proc_hash(pip, pid);
94 void add_process(__u32 pid, char *name)
96 struct p_info *pip = find_process(pid, name);
99 pip = zmalloc(sizeof(*pip));
101 list_add_tail(&pip->head, &all_procs);
102 insert_proc_hash(pip, pid);
103 pip->last_q = (__u64)-1;
104 pip->name = strdup(name);
105 init_region(&pip->regions);
109 void pip_update_q(struct io *iop)
112 update_lq(&iop->pip->last_q, &iop->pip->avgs.q2q, iop->t.time);
113 update_qregion(&iop->pip->regions, iop->t.time);