diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-30 22:02:59 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-30 22:02:59 -0400 |
commit | 55bcab46955644d5a8149a9b3cc9752a336e02f8 (patch) | |
tree | a45593603de9265cb0624043ab36f4e0f98823fc /tools/perf/util/run-command.c | |
parent | 58580c86450bc09ff101f0d23fd8a162c146bc64 (diff) | |
parent | 7bec7a9134c25cecb0d7029199b59f7b1bef35b8 (diff) |
Merge branch 'perfcounters-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perfcounters-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (47 commits)
perf report: Add --symbols parameter
perf report: Add --comms parameter
perf report: Add --dsos parameter
perf_counter tools: Adjust only prelinked symbol's addresses
perf_counter: Provide a way to enable counters on exec
perf_counter tools: Reduce perf stat measurement overhead/skew
perf stat: Use percentages for scaling output
perf_counter, x86: Update x86_pmu after WARN()
perf stat: Micro-optimize the code: memcpy is only required if no event is selected and !null_run
perf stat: Improve output
perf stat: Fix multi-run stats
perf stat: Add -n/--null option to run without counters
perf_counter tools: Remove dead code
perf_counter: Complete counter swap
perf report: Print sorted callchains per histogram entries
perf_counter tools: Prepare a small callchain framework
perf record: Fix unhandled io return value
perf_counter tools: Add alias for 'l1d' and 'l1i'
perf-report: Add bare minimum PERF_EVENT_READ parsing
perf-report: Add modes for inherited stats and no-samples
...
Diffstat (limited to 'tools/perf/util/run-command.c')
-rw-r--r-- | tools/perf/util/run-command.c | 95 |
1 files changed, 2 insertions, 93 deletions
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c index b2f5e854f40a..a3935343091a 100644 --- a/tools/perf/util/run-command.c +++ b/tools/perf/util/run-command.c | |||
@@ -65,7 +65,6 @@ int start_command(struct child_process *cmd) | |||
65 | cmd->err = fderr[0]; | 65 | cmd->err = fderr[0]; |
66 | } | 66 | } |
67 | 67 | ||
68 | #ifndef __MINGW32__ | ||
69 | fflush(NULL); | 68 | fflush(NULL); |
70 | cmd->pid = fork(); | 69 | cmd->pid = fork(); |
71 | if (!cmd->pid) { | 70 | if (!cmd->pid) { |
@@ -118,71 +117,6 @@ int start_command(struct child_process *cmd) | |||
118 | } | 117 | } |
119 | exit(127); | 118 | exit(127); |
120 | } | 119 | } |
121 | #else | ||
122 | int s0 = -1, s1 = -1, s2 = -1; /* backups of stdin, stdout, stderr */ | ||
123 | const char **sargv = cmd->argv; | ||
124 | char **env = environ; | ||
125 | |||
126 | if (cmd->no_stdin) { | ||
127 | s0 = dup(0); | ||
128 | dup_devnull(0); | ||
129 | } else if (need_in) { | ||
130 | s0 = dup(0); | ||
131 | dup2(fdin[0], 0); | ||
132 | } else if (cmd->in) { | ||
133 | s0 = dup(0); | ||
134 | dup2(cmd->in, 0); | ||
135 | } | ||
136 | |||
137 | if (cmd->no_stderr) { | ||
138 | s2 = dup(2); | ||
139 | dup_devnull(2); | ||
140 | } else if (need_err) { | ||
141 | s2 = dup(2); | ||
142 | dup2(fderr[1], 2); | ||
143 | } | ||
144 | |||
145 | if (cmd->no_stdout) { | ||
146 | s1 = dup(1); | ||
147 | dup_devnull(1); | ||
148 | } else if (cmd->stdout_to_stderr) { | ||
149 | s1 = dup(1); | ||
150 | dup2(2, 1); | ||
151 | } else if (need_out) { | ||
152 | s1 = dup(1); | ||
153 | dup2(fdout[1], 1); | ||
154 | } else if (cmd->out > 1) { | ||
155 | s1 = dup(1); | ||
156 | dup2(cmd->out, 1); | ||
157 | } | ||
158 | |||
159 | if (cmd->dir) | ||
160 | die("chdir in start_command() not implemented"); | ||
161 | if (cmd->env) { | ||
162 | env = copy_environ(); | ||
163 | for (; *cmd->env; cmd->env++) | ||
164 | env = env_setenv(env, *cmd->env); | ||
165 | } | ||
166 | |||
167 | if (cmd->perf_cmd) { | ||
168 | cmd->argv = prepare_perf_cmd(cmd->argv); | ||
169 | } | ||
170 | |||
171 | cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env); | ||
172 | |||
173 | if (cmd->env) | ||
174 | free_environ(env); | ||
175 | if (cmd->perf_cmd) | ||
176 | free(cmd->argv); | ||
177 | |||
178 | cmd->argv = sargv; | ||
179 | if (s0 >= 0) | ||
180 | dup2(s0, 0), close(s0); | ||
181 | if (s1 >= 0) | ||
182 | dup2(s1, 1), close(s1); | ||
183 | if (s2 >= 0) | ||
184 | dup2(s2, 2), close(s2); | ||
185 | #endif | ||
186 | 120 | ||
187 | if (cmd->pid < 0) { | 121 | if (cmd->pid < 0) { |
188 | int err = errno; | 122 | int err = errno; |
@@ -288,14 +222,6 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const | |||
288 | return run_command(&cmd); | 222 | return run_command(&cmd); |
289 | } | 223 | } |
290 | 224 | ||
291 | #ifdef __MINGW32__ | ||
292 | static __stdcall unsigned run_thread(void *data) | ||
293 | { | ||
294 | struct async *async = data; | ||
295 | return async->proc(async->fd_for_proc, async->data); | ||
296 | } | ||
297 | #endif | ||
298 | |||
299 | int start_async(struct async *async) | 225 | int start_async(struct async *async) |
300 | { | 226 | { |
301 | int pipe_out[2]; | 227 | int pipe_out[2]; |
@@ -304,7 +230,6 @@ int start_async(struct async *async) | |||
304 | return error("cannot create pipe: %s", strerror(errno)); | 230 | return error("cannot create pipe: %s", strerror(errno)); |
305 | async->out = pipe_out[0]; | 231 | async->out = pipe_out[0]; |
306 | 232 | ||
307 | #ifndef __MINGW32__ | ||
308 | /* Flush stdio before fork() to avoid cloning buffers */ | 233 | /* Flush stdio before fork() to avoid cloning buffers */ |
309 | fflush(NULL); | 234 | fflush(NULL); |
310 | 235 | ||
@@ -319,33 +244,17 @@ int start_async(struct async *async) | |||
319 | exit(!!async->proc(pipe_out[1], async->data)); | 244 | exit(!!async->proc(pipe_out[1], async->data)); |
320 | } | 245 | } |
321 | close(pipe_out[1]); | 246 | close(pipe_out[1]); |
322 | #else | 247 | |
323 | async->fd_for_proc = pipe_out[1]; | ||
324 | async->tid = (HANDLE) _beginthreadex(NULL, 0, run_thread, async, 0, NULL); | ||
325 | if (!async->tid) { | ||
326 | error("cannot create thread: %s", strerror(errno)); | ||
327 | close_pair(pipe_out); | ||
328 | return -1; | ||
329 | } | ||
330 | #endif | ||
331 | return 0; | 248 | return 0; |
332 | } | 249 | } |
333 | 250 | ||
334 | int finish_async(struct async *async) | 251 | int finish_async(struct async *async) |
335 | { | 252 | { |
336 | #ifndef __MINGW32__ | ||
337 | int ret = 0; | 253 | int ret = 0; |
338 | 254 | ||
339 | if (wait_or_whine(async->pid)) | 255 | if (wait_or_whine(async->pid)) |
340 | ret = error("waitpid (async) failed"); | 256 | ret = error("waitpid (async) failed"); |
341 | #else | 257 | |
342 | DWORD ret = 0; | ||
343 | if (WaitForSingleObject(async->tid, INFINITE) != WAIT_OBJECT_0) | ||
344 | ret = error("waiting for thread failed: %lu", GetLastError()); | ||
345 | else if (!GetExitCodeThread(async->tid, &ret)) | ||
346 | ret = error("cannot get thread exit code: %lu", GetLastError()); | ||
347 | CloseHandle(async->tid); | ||
348 | #endif | ||
349 | return ret; | 258 | return ret; |
350 | } | 259 | } |
351 | 260 | ||