Changeset b05530c4ff96e00046ae4e9555794b66265081b2
- Timestamp:
- 07/11/09 12:23:28 (3 years ago)
- Author:
- Nedko Arnaudov <nedko@…>
- Children:
- 97022e24935605949cb7664b5d9193ed7c1c499c
- Parents:
- 51bb400466101d3a545817ba7e27f9d25568ab51
- git-committer:
- Nedko Arnaudov <nedko@arnaudov.name> / 2009-07-11T12:23:28Z+0300
- Message:
-
fork/vfork time measure and easy switch
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r51bb400
|
rb05530c
|
|
| 26 | 26 | #define UI_URI "http://nedko.aranaudov.org/soft/filter/2/gui" |
| 27 | 27 | |
| | 28 | //#define FORK_TIME_MEASURE |
| | 29 | #define USE_VFORK |
| | 30 | |
| | 31 | #if defined(USE_VFORK) |
| | 32 | #define FORK vfork |
| | 33 | #define FORK_STR "vfork" |
| | 34 | #else |
| | 35 | #define FORK fork |
| | 36 | #define FORK_STR "fork" |
| | 37 | #endif |
| | 38 | |
| | 39 | |
| 28 | 40 | #include <stdbool.h> |
| 29 | 41 | #include <stdio.h> |
| … |
… |
|
| 32 | 44 | |
| 33 | 45 | #include <sys/types.h> |
| | 46 | #if defined(FORK_TIME_MEASURE) |
| | 47 | # include <sys/time.h> |
| | 48 | #endif |
| 34 | 49 | #include <unistd.h> |
| 35 | 50 | #include <fcntl.h> |
| … |
… |
|
| 182 | 197 | #undef control_ptr |
| 183 | 198 | |
| | 199 | #if defined(FORK_TIME_MEASURE) |
| | 200 | static |
| | 201 | uint64_t |
| | 202 | get_current_time() |
| | 203 | { |
| | 204 | struct timeval time; |
| | 205 | |
| | 206 | if (gettimeofday(&time, NULL) != 0) |
| | 207 | return 0; |
| | 208 | |
| | 209 | return (uint64_t)time.tv_sec * 1000000 + (uint64_t)time.tv_usec; |
| | 210 | } |
| | 211 | |
| | 212 | #define FORK_TIME_MEASURE_VAR_NAME ____t |
| | 213 | |
| | 214 | #define FORK_TIME_MEASURE_VAR uint64_t FORK_TIME_MEASURE_VAR_NAME |
| | 215 | #define FORK_TIME_MEASURE_BEGIN FORK_TIME_MEASURE_VAR_NAME = get_current_time() |
| | 216 | #define FORK_TIME_MEASURE_END(msg) \ |
| | 217 | { \ |
| | 218 | FORK_TIME_MEASURE_VAR_NAME = get_current_time() - FORK_TIME_MEASURE_VAR_NAME; \ |
| | 219 | fprintf(stderr, msg ": %llu us\n", (unsigned long long)FORK_TIME_MEASURE_VAR_NAME); \ |
| | 220 | } |
| | 221 | |
| | 222 | #else |
| | 223 | |
| | 224 | #define FORK_TIME_MEASURE_VAR |
| | 225 | #define FORK_TIME_MEASURE_BEGIN |
| | 226 | #define FORK_TIME_MEASURE_END(msg) |
| | 227 | |
| | 228 | #endif |
| | 229 | |
| 184 | 230 | static |
| 185 | 231 | LV2UI_Handle |
| … |
… |
|
| 201 | 247 | char ui_send_pipe[100]; |
| 202 | 248 | int oldflags; |
| | 249 | FORK_TIME_MEASURE_VAR; |
| 203 | 250 | |
| 204 | 251 | //printf("instantiate('%s', '%s') called\n", plugin_uri, bundle_path); |
| … |
… |
|
| 259 | 306 | control_ptr->visible = false; |
| 260 | 307 | |
| 261 | | switch (vfork()) |
| | 308 | FORK_TIME_MEASURE_BEGIN; |
| | 309 | |
| | 310 | switch (FORK()) |
| 262 | 311 | { |
| 263 | 312 | case 0: /* child process */ |
| 264 | 313 | /* fork duplicated the handles, close pipe ends that are used by parent process */ |
| | 314 | #if !defined(USE_VFORK) |
| 265 | 315 | /* it looks we cant do this for vfork() */ |
| 266 | | //close(pipe1[1]); |
| 267 | | //close(pipe2[0]); |
| | 316 | close(pipe1[1]); |
| | 317 | close(pipe2[0]); |
| | 318 | #endif |
| 268 | 319 | |
| 269 | 320 | execlp( |
| … |
… |
|
| 284 | 335 | } |
| 285 | 336 | |
| | 337 | FORK_TIME_MEASURE_END(FORK_STR "() time"); |
| | 338 | |
| 286 | 339 | /* fork duplicated the handles, close pipe ends that are used by the child process */ |
| 287 | 340 | close(pipe1[0]); |