Changeset b05530c4ff96e00046ae4e9555794b66265081b2

Show
Ignore:
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:
1 modified

Legend:

Unmodified
Added
Removed
  • lv2_ui.c

    r51bb400 rb05530c  
    2626#define UI_URI        "http://nedko.aranaudov.org/soft/filter/2/gui" 
    2727 
     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 
    2840#include <stdbool.h> 
    2941#include <stdio.h> 
     
    3244 
    3345#include <sys/types.h> 
     46#if defined(FORK_TIME_MEASURE) 
     47# include <sys/time.h> 
     48#endif 
    3449#include <unistd.h> 
    3550#include <fcntl.h> 
     
    182197#undef control_ptr 
    183198 
     199#if defined(FORK_TIME_MEASURE) 
     200static 
     201uint64_t 
     202get_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 
    184230static 
    185231LV2UI_Handle 
     
    201247  char ui_send_pipe[100]; 
    202248  int oldflags; 
     249  FORK_TIME_MEASURE_VAR; 
    203250 
    204251  //printf("instantiate('%s', '%s') called\n", plugin_uri, bundle_path); 
     
    259306  control_ptr->visible = false; 
    260307 
    261   switch (vfork()) 
     308  FORK_TIME_MEASURE_BEGIN; 
     309 
     310  switch (FORK()) 
    262311  { 
    263312  case 0:                       /* child process */ 
    264313    /* fork duplicated the handles, close pipe ends that are used by parent process */ 
     314#if !defined(USE_VFORK) 
    265315    /* 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 
    268319 
    269320    execlp( 
     
    284335  } 
    285336 
     337  FORK_TIME_MEASURE_END(FORK_STR "() time"); 
     338 
    286339  /* fork duplicated the handles, close pipe ends that are used by the child process */ 
    287340  close(pipe1[0]);