Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: main.c

Issue 6893111: Enhancements to ktop (Closed) Base URL: ssh://gitrw.chromium.org:9222/ktop.git@master
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ktop.h ('k') | mylib.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3 * Distributed under the terms of the GNU General Public License v2 3 * Distributed under the terms of the GNU General Public License v2
4 */ 4 */
5 5
6 6
7 #include <sys/syscall.h> 7 #include <sys/syscall.h>
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <stdio.h> 10 #include <stdio.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <string.h> 12 #include <string.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 14
15 #include <debug.h>
15 #include <eprintf.h> 16 #include <eprintf.h>
16 #include <style.h> 17 #include <style.h>
17 18
18 #include "ktop.h" 19 #include "ktop.h"
19 20
20 int Command; 21 bool Halt = FALSE;
21 22
22 bool Dump = FALSE; 23 bool Dump = FALSE;
23 bool Trace_exit = FALSE; 24 bool Trace_exit = TRUE;
24 bool Trace_self = FALSE; 25 bool Trace_self = FALSE;
25 26
27 display_fn Display = kernel_display;
28
26 pid_t gettid(void) { return syscall(__NR_gettid); } 29 pid_t gettid(void) { return syscall(__NR_gettid); }
27 30
28 u8 Ignore_pid[(MAX_PID + 4) / 8]; 31 u8 Ignore_pid[(MAX_PID + 4) / 8];
29 pthread_mutex_t Ignore_pid_lock = PTHREAD_MUTEX_INITIALIZER; 32 pthread_mutex_t Ignore_pid_lock = PTHREAD_MUTEX_INITIALIZER;
30 33
31 void ignore_pid(int pid) 34 void ignore_pid(int pid)
32 { 35 {
33 if ((pid < 0) || (pid >= MAX_PID)) warn("pid out of range %d", pid); 36 if ((pid < 0) || (pid >= MAX_PID)) warn("pid out of range %d", pid);
34 37
35 pthread_mutex_lock(&Ignore_pid_lock); 38 pthread_mutex_lock(&Ignore_pid_lock);
36 Ignore_pid[pid / 8] |= (1 << (pid & 0x7)); 39 Ignore_pid[pid / 8] |= (1 << (pid & 0x7));
37 pthread_mutex_unlock(&Ignore_pid_lock); 40 pthread_mutex_unlock(&Ignore_pid_lock);
38 } 41 }
39 42
40 bool do_ignore_pid(int pid) 43 bool do_ignore_pid(int pid)
41 { 44 {
42 if ((pid < 0) || (pid >= MAX_PID)) { 45 if ((pid < 0) || (pid >= MAX_PID)) {
43 warn("pid out of range %d", pid); 46 warn("pid out of range %d", pid);
44 return TRUE; 47 return TRUE;
45 } 48 }
46 return Ignore_pid[pid / 8] & (1 << (pid & 0x7)); 49 return Ignore_pid[pid / 8] & (1 << (pid & 0x7));
47 } 50 }
48 51
49 52
50 void cleanup(int sig) 53 void cleanup(int sig)
51 { 54 {
55 PRd(sig);
56 if (sig) {
57 fprintf(stderr, "died because %d\n", sig);
58 }
52 cleanup_collector(); 59 cleanup_collector();
53 cleanup_display(); 60 cleanup_display();
54 exit(0); 61 exit(0);
55 } 62 }
56 63
57 void set_signals(void) 64 void set_signals(void)
58 { 65 {
59 signal(SIGHUP, cleanup); 66 signal(SIGHUP, cleanup);
60 signal(SIGINT, cleanup); 67 signal(SIGINT, cleanup);
61 signal(SIGQUIT, cleanup); 68 signal(SIGQUIT, cleanup);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 default: 109 default:
103 fprintf(stderr, "unknown option %c\n", c); 110 fprintf(stderr, "unknown option %c\n", c);
104 usage(); 111 usage();
105 break; 112 break;
106 } 113 }
107 } 114 }
108 } 115 }
109 116
110 void quit(void) 117 void quit(void)
111 { 118 {
112 » Command = 1; 119 » Halt = TRUE;
113 } 120 }
114 121
115 void clear(void) 122 void clear(void)
116 { 123 {
117 » clear_display(); 124 » reset_reduce();
118 } 125 }
119 126
120 void commander(void) 127 void commander(void)
121 { 128 {
122 for (;;) { 129 for (;;) {
123 int c = getchar(); 130 int c = getchar();
124 if (c == EOF) cleanup(0); 131 if (c == EOF) cleanup(0);
125 switch (c) { 132 switch (c) {
126 case 'q': 133 case 'q':
127 quit(); 134 quit();
128 return; 135 return;
129 case 'c': 136 case 'c':
130 clear(); 137 clear();
131 break; 138 break;
139 case '<':
140 decrease_reduce_interval();
141 break;
142 case '>':
143 increase_reduce_interval();
144 break;
145 case 'i':
146 Display = internal_display;
147 break;
148 case 'k':
149 Display = kernel_display;
150 break;
151 case 'f':
152 Display = file_system_display;
153 break;
132 default: 154 default:
133 break; // ignore 155 break; // ignore
134 } 156 }
135 } 157 }
136 } 158 }
137 159
138 int main(int argc, char **argv) 160 int main(int argc, char **argv)
139 { 161 {
140 » pthread_t display_thread; 162 » pthread_t reduce_thread;
141 int rc; 163 int rc;
142 164
165 debugstderr();
166
143 init(argc, argv); 167 init(argc, argv);
144 168
145 ignore_pid(gettid()); 169 ignore_pid(gettid());
146 170
147 start_collector(); 171 start_collector();
148 172
149 if (!Dump) { 173 if (!Dump) {
150 » » rc = pthread_create(&display_thread, NULL, display, NULL); 174 » » rc = pthread_create(&reduce_thread, NULL, reduce, NULL);
151 } 175 }
152 commander(); 176 commander();
153 177
154 cleanup(0); 178 cleanup(0);
155 return 0; 179 return 0;
156 } 180 }
OLDNEW
« no previous file with comments | « ktop.h ('k') | mylib.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698