Пример #1
0
int main(int argc,char **argv) {  
    int             c, i_tmp, status, remote, numEvents, errflg=0, verbose=0;
    size_t eventSize;
    unsigned short  serverPort = ET_SERVER_PORT, udpPort = ET_MULTICAST_PORT;
    char            et_name[ET_FILENAME_LENGTH], host[256], mcastAddr[16];
    et_sys_id       id;
    et_openconfig   openconfig;


    /* 4 multiple character command-line options */
    static struct option long_options[] =
    { {"host", 1, NULL, 1},
      {0,0,0,0}};
    
      memset(host, 0, 16);
      memset(mcastAddr, 0, 16);
      memset(et_name, 0, ET_FILENAME_LENGTH);

      while ((c = getopt_long_only(argc, argv, "vrn:p:u:f:", long_options, 0)) != EOF) {
      
          if (c == -1)
              break;

          switch (c) {
              case 'p':
                  i_tmp = atoi(optarg);
                  if (i_tmp > 1023 && i_tmp < 65535) {
                      serverPort = i_tmp;
                  } else {
                      printf("Invalid argument to -p. Must be < 65535 & > 1023.\n");
                      exit(-1);
                  }
                  break;

              case 'u':
                  i_tmp = atoi(optarg);
                  if (i_tmp > 1023 && i_tmp < 65535) {
                      udpPort = i_tmp;
                  } else {
                      printf("Invalid argument to -u. Must be < 65535 & > 1023.\n");
                      exit(-1);
                  }
                  break;

              case 'f':
                  if (strlen(optarg) >= ET_FILENAME_LENGTH) {
                      fprintf(stderr, "ET file name is too long\n");
                      exit(-1);
                  }
                  strcpy(et_name, optarg);
                  break;

              case 'r':
                  remote = 1;
                  break;

                  /* case host: */
              case 1:
                  if (strlen(optarg) >= 255) {
                      fprintf(stderr, "host name is too long\n");
                      exit(-1);
                  }
                  strcpy(host, optarg);
                  break;

              case 'v':
                  verbose = ET_DEBUG_INFO;
                  break;

              case ':':
              case 'h':
              case '?':
              default:
                  errflg++;
          }
      }
    
      if (optind < argc || errflg || strlen(host) < 1 || strlen(et_name) < 1) {
          fprintf(stderr, "usage: %s  %s\n\n", argv[0],
                  "-f <ET name> -host <ET host> [-h] [-v] [-r] [-p <server port>] [-u mcast port>");

          fprintf(stderr, "          -host ET system's host\n");
          fprintf(stderr, "          -f ET system's (memory-mapped file) name\n");
          fprintf(stderr, "          -h help\n");
          fprintf(stderr, "          -v verbose output\n");
          fprintf(stderr, "          -r as remote(network) client\n");
          fprintf(stderr, "          -p TCP server port\n");
          fprintf(stderr, "          -u UDP multicast port\n");
          fprintf(stderr, "          This consumer works by making a direct connection\n");
          fprintf(stderr, "          to the ET system's server port.\n\n");
          exit(2);
      }

      /* open ET system */
      et_open_config_init(&openconfig);

      /* EXAMPLE: multicasting to find ET */
    
      et_open_config_setcast(openconfig, ET_MULTICAST);
      et_open_config_addmulticast(openconfig, ET_MULTICAST_ADDR);
      et_open_config_setmultiport(openconfig, udpPort);
      et_open_config_sethost(openconfig, ET_HOST_ANYWHERE);
      et_open_config_setTTL(openconfig, 32);

      /* EXAMPLE: direct connection to ET */
      /*
      et_open_config_setcast(openconfig, ET_DIRECT);
      et_open_config_sethost(openconfig, host);
      et_open_config_setserverport(openconfig, serverPort);
      */
      
    if (remote) {
        et_open_config_setmode(openconfig, ET_HOST_AS_REMOTE);
    }
    if (et_open(&id, et_name, openconfig) != ET_OK) {
        printf("%s: et_open problems\n", argv[0]);
        exit(1);
    }
    et_open_config_destroy(openconfig);

    if (verbose) {
        et_system_setdebug(id, ET_DEBUG_INFO);
    }

    et_system_getnumevents(id, &numEvents);
    et_system_geteventsize(id, &eventSize);

    printf("Opened ET system with %d number of events, %d bytes each\n", numEvents, eventSize);
  

    if ((status = et_kill(id)) != ET_OK) {
        printf("%s: error in killing ET system\n", argv[0]);
    }

    return 0;
}
Пример #2
0
/*
 * Class:     org_jlab_coda_et_EtJniAccess
 * Method:    openLocalEtSystem
 * Signature: (Ljava/lang/String;)J
 */
JNIEXPORT void JNICALL Java_org_jlab_coda_et_EtJniAccess_openLocalEtSystem
        (JNIEnv *env, jobject thisObj, jstring fileName)
{
    int err;
    const char* mappedFile;
    et_sys_id id; /* (void *) */
    et_openconfig openconfig;
    jclass clazz, class1, classEventImpl;
    jmethodID mid;

    /* get C string from java arg */
    mappedFile = (*env)->GetStringUTFChars(env, fileName, NULL);
    if (mappedFile == NULL) {
        /* pending exception already thrown, need to return for it to complete */
        (*env)->ReleaseStringUTFChars(env, fileName, mappedFile);
        return;
    }
    
    /* open ET system */
    et_open_config_init(&openconfig);
    et_open_config_sethost(openconfig, ET_HOST_LOCAL); /* must be local host */
    err = et_open(&id, mappedFile, openconfig);
    if (err != ET_OK) {
        if (err == ET_ERROR_TIMEOUT) {
            clazz = (*env)->FindClass(env, "org/jlab/coda/et/exception/EtTimeoutException");
        }
        else {
            clazz = (*env)->FindClass(env, "org/jlab/coda/et/exception/EtException");
        }
        (*env)->ThrowNew(env, clazz, "openLocalEtSystem: cannot open ET system in native code");
        return;
    }
    et_open_config_destroy(openconfig);

    /* store byte order of local system */
    err = etNetLocalByteOrder(&localByteOrder);
    if (err != ET_OK) {
        localByteOrder = ET_ENDIAN_LITTLE;
    }

    /* store et id in object by calling this native method */
    class1 = (*env)->GetObjectClass(env, thisObj);
    mid    = (*env)->GetMethodID(env, class1, "setLocalEtId", "(J)V");
    (*env)->CallVoidMethod(env, thisObj, mid, (jlong)id);

    /*******************************************/
    /* cache objects for efficient, future use */
    /*******************************************/
    classEventImpl = (*env)->FindClass(env, "org/jlab/coda/et/EtEventImpl");
    eventImplClass = (*env)->NewGlobalRef(env, classEventImpl);
 
    /* find id's of all the fields that we'll read/write directly to */
    fid[0] = (*env)->GetFieldID(env, classEventImpl, "id",         "I");
    fid[1] = (*env)->GetFieldID(env, classEventImpl, "length",     "I");
    fid[2] = (*env)->GetFieldID(env, classEventImpl, "byteOrder",  "I");
    fid[3] = (*env)->GetFieldID(env, classEventImpl, "control",    "[I");

    /* methods to get event's enum values */
    getPriorityVal   = (*env)->GetMethodID(env, classEventImpl, "getPriorityValue",   "()I");
    getDataStatusVal = (*env)->GetMethodID(env, classEventImpl, "getDataStatusValue", "()I");

    /* get id's of a few different constructors */
    constrMethodId2 = (*env)->GetMethodID(env, classEventImpl, "<init>", "(IIIIIIIIZLjava/nio/ByteBuffer;)V");
    constrMethodId3 = (*env)->GetMethodID(env, classEventImpl, "<init>", "(IIIIIIIIII[IZLjava/nio/ByteBuffer;)V");
    
    if (debug) printf("\nopenLocalEtSystem (native) : done, opened ET system\n\n");
}
Пример #3
0
main(int argc,char **argv)
{  
  int *ev, len, i, j, status, numread, totalread=0, nevents_max, event_size, chunk;
  int con[ET_STATION_SELECT_INTS];
  et_event      **pe;
  et_openconfig   openconfig;
  et_statconfig   sconfig;
  et_att_id       attach;
  et_stat_id      my_stat;
  et_sys_id       id;
  sigset_t        sigblock;
  struct timespec timeout;
  pthread_t       tid;

  BOSIOptr BIOstream;
  char *ch;

  char *str1 =
"OPEN UNIT=11 FILE='/scratch/boiarino/test.A00' WRITE RECL=32768 SPLITMB=2047 RAW SEQ NEW BINARY";
/*"OPEN UNIT=11 FILE='/work/clas/disk1/boiarino/test.A00' WRITE RECL=32768 SPLITMB=2047 RAW SEQ NEW BINARY";*/
  
  if(argc != 3) {
    printf("Usage: et2bos_test <et_filename> <station_name>\n");
    exit(1);
  }

  timeout.tv_sec  = 0;
  timeout.tv_nsec = 1;
  
  /* setup signal handling */
  sigfillset(&sigblock);
  /* block all signals */
  status = pthread_sigmask(SIG_BLOCK, &sigblock, NULL);
  if (status != 0) {
    printf("et2bos: pthread_sigmask failure\n");
    exit(1);
  }
  #ifdef sun
    thr_setconcurrency(thr_getconcurrency() + 1);
  #endif
  /* spawn signal handling thread */
  pthread_create(&tid, NULL, signal_thread, (void *)NULL);
  

restartLinux:

  /* open ET system */
  et_open_config_init(&openconfig);
  et_open_config_setwait(openconfig, ET_OPEN_WAIT);
  if (et_open(&id, argv[1], openconfig) != ET_OK) {
    printf("et2bos: et_open problems\n");
    exit(1);
  }
  et_open_config_destroy(openconfig);


  /*
   * Now that we have access to an ET system, find out how many
   * events it has and what size they are. Then allocate an array
   * of pointers to use for reading, writing, and modifying these events.
   */
  
  if (et_system_getnumevents(id, &nevents_max) != ET_OK)
  {
    printf("et2bos: ET has died\n");
    exit(1);
  }
  if (et_system_geteventsize(id, &event_size) != ET_OK)
  {
    printf("et2bos: ET has died\n");
    exit(1);
  }
  
  if ( (pe = (et_event **) calloc(nevents_max, sizeof(et_event *))) == NULL)
  {
    printf("et2bos: cannot allocate memory\n");
    exit(1);
  }

  et_station_config_init(&sconfig);
  et_station_config_setuser(sconfig, ET_STATION_USER_MULTI);
  et_station_config_setrestore(sconfig, ET_STATION_RESTORE_OUT);
  et_station_config_setprescale(sconfig, 1);
 
  /* old "all" mode */
  et_station_config_setselect(sconfig, ET_STATION_SELECT_ALL);
  et_station_config_setblock(sconfig, ET_STATION_BLOCKING);
  et_station_config_setcue(sconfig, 150);  /* if ET_STATION_NONBLOCKING */

  /* set debug level */
  et_system_setdebug(id, ET_DEBUG_INFO);


  /* create station */
  if ((status = et_station_create(id, &my_stat, argv[2], sconfig)) < 0)
  {
    if (status == ET_ERROR_EXISTS)
    {
      /* my_stat contains pointer to existing station */;
      printf("et2bos: set ptr to the existing station\n");
    }
    else if (status == ET_ERROR_TOOMANY)
    {
      printf("et2bos: too many stations created\n");
      goto error;
    }
    else
    {
      printf("et2bos: error in station creation\n");
      goto error;
    }
  }

  printf("et2bos: station ready\n");




  if (et_station_attach(id, my_stat, &attach) < 0)
  {
    printf("et2bos: error in station attach\n");
    goto error;
  }

  /* open FPACK file for writing */
  /*if( (status = FParm(str1,&fd)) !=0)
  {
	printf("FParm status %d \n",status);
	printf("command was >%s<\n",str1);
	exit(1);
  }*/

  /* set file descriptor pointer */
  BIOstream = (BOSIOptr)fd;

  /* initialize BOS array */
  bosInit(jw,NBCS);


  while (et_alive(id))
  {
    /**************/
    /* read data  */
    /**************/

    /* example of single, timeout read */
    /* status = et_event_get(&id, attach, &pe[0], ET_TIMED, &timeout); */

    /* example of single, asynchronous read */
    /* status = et_event_get(&id, attach, &pe[0], ET_ASYNC, NULL);*/

    /* example of reading array of up to "chunk" events */
    /* chunk = 500; */
    /* numread = status = et_events_get(&id, attach, pe, ET_SLEEP, NULL, chunk, &numread);*/

    chunk   = 500;
    status = et_events_get(id, attach, pe, ET_SLEEP, NULL, chunk, &numread);
    if (status == ET_OK) {
      ;
    }
    else if (status == ET_ERROR_DEAD) {
      printf("et2bos: ET system is dead\n");
      goto end;
    }
    else if (status == ET_ERROR_TIMEOUT) {
      printf("et2bos: got timeout\n");
      goto end;
    }
    else if (status == ET_ERROR_EMPTY) {
      printf("et2bos: no events\n");
      goto end;
    }
    else if (status == ET_ERROR_BUSY) {
      printf("et2bos: station is busy\n");
      goto end;
    }
    else if (status == ET_ERROR_WAKEUP) {
      printf("et2bos: someone told me to wake up\n");
      goto end;
    }
    else if ((status == ET_ERROR_WRITE) || (status == ET_ERROR_READ)) {
      printf("et2bos: socket communication error\n");
      goto end;
    }
    else if (status != ET_OK) {
      printf("et2bos: get error\n");
      goto error;
    }

    /****************************************/
    /* print data, write data to FPACK file */
    /****************************************/

    for (j=0; j<numread; j++)
    {
      et_event_getdata(pe[j], (void **) &ev);

/*
      et_event_getlength(pe[j], &len);
      printf("et2bos: recname=>%4.4s%4.4s<, run#=%d, event#=%d, reclen=%d\n",
           (char *)&ev[3],(char *)&ev[4],ev[5],ev[6],ev[10]);
      printf(" temp = %d, pri = %d, len = %d\n",
           pe[j]->temp,et_event_getpriority(pe[j]),len);
      et_event_getcontrol(pe[j], con);
      for (i=0; i < ET_STATION_SELECT_INTS; i++)
      {
        printf("control[%d] = %d\n",i,con[i]);
      }
*/

      /* drop banks from previous event */

      bosLdrop(jw, "E");
      bosNgarbage(jw);
      bosWgarbage(jw);

      /* create banks in BOS array */

      status = et2bos(ev, jw, "E");
      if (status != 0)
      {
        printf ("et2bos_test: error %d in et2bos()\n",status);
        exit(1);
      }

      /* call next if want to use ET record header; otherwise
      record name will be "RUNEVENT" and other info from HEAD bank */

      /*bosWriteRecord(fd,&ev[3],ev[5],ev[6],ev[8]);*/

      /* write down BOS banks to file */
/*
      status = bosWrite(fd, jw, "E");
      if (status != 0)
      {
        printf ("et2bos_test: error %d in bosWrite()\n",status);
        exit(1);
      }
*/

    }

    /*********************/
    /* return data to ET */
    /*********************/

    /* example of writing single event */
    /* status = et_event_put(id, attach, pe[0]);*/

    /* example of writing array of events */
    status = et_events_put(id, attach, pe, numread);

    if (status == ET_ERROR_DEAD) {
      printf("et2bos: ET is dead\n");
      goto end;
    }
    else if ((status == ET_ERROR_WRITE) || (status == ET_ERROR_READ)) {
      printf("et2bos: socket communication error\n");
      goto end;
    }
    else if (status != ET_OK) {
      printf("et2bos: put error\n");
      goto error;
    }
    totalread += numread;

end:
    /* print something out after having read NUMEVENTS events */
    if (totalread >= NUMEVENTS)
    {
      totalread = 0;
      printf(" et2bos: %d events\n", NUMEVENTS);
    }

    /* if ET system is dead, wait here until it comes back */
	while (!et_alive(id)) {
	  status = et_wait_for_alive(id);
	  if (status == ET_OK) {
	    int locality;
	    et_system_getlocality(id, &locality);
	    /* if Linux, re-establish connection to ET system since socket broken */
	    if (locality == ET_LOCAL_NOSHARE) {
              printf("et2bos: try to reconnect Linux client\n");
	      et_forcedclose(id);
	      goto restartLinux;
	    }
	  }
	}



  } /* while(alive) */
    
error:
  free(pe);
  printf("et2bos: ERROR\n");
  exit(0);
}
Пример #4
0
int et_open(et_sys_id *id, const char *filename, et_openconfig openconfig)
{     
  int             status, auto_open=0, err;
  et_open_config *config;
  et_openconfig   auto_config = NULL;
  int             def_debug;

  if (openconfig == NULL) {
    auto_open = 1;
    if (et_open_config_init(&auto_config) == ET_ERROR) {
      et_logmsg("ERROR", "et_open, null arg for openconfig, cannot use default\n");
      return ET_ERROR;
    }
    openconfig = auto_config;
  }

  config = (et_open_config *) openconfig;

  err = ET_OK;
  /* argument checking */
  if ((filename == NULL) || (config->init != ET_STRUCT_OK)) {
    et_logmsg("ERROR", "et_open, bad argument\n");
    err = ET_ERROR;
  }
  else if (strlen(filename) > ET_FILENAME_LENGTH - 1) {
    et_logmsg("ERROR", "et_open, ET name too long\n");
    err = ET_ERROR;
  }

  if (err != ET_OK) {
    if (auto_open == 1) {
      et_open_config_destroy(auto_config);
    }
    return err;
  }
  
  /* initialize id */
  if (et_id_init(id) != ET_OK) {
    et_logmsg("ERROR", "et_open, cannot initialize id\n");
    return ET_ERROR;
  }

  if (et_open_config_getdebugdefault(openconfig, &def_debug) != ET_OK) {
    def_debug = ET_DEBUG_ERROR;
  }
  et_system_setdebug(*id, def_debug);
  
  /* We depart from the original version of et_open since
   * this ET client will attach to an ET system remotely by definition.
   * Force the configuration to make a tcp connection to the ET system,
   * even if it's not remote.
   */
  config->mode = ET_HOST_AS_REMOTE;
  status = etr_open(id, filename, openconfig);
 
  if (status != ET_OK) {
    et_id_destroy(*id);
  }
  
  if (auto_open == 1) {
    et_open_config_destroy(auto_config);
  }

  return status;
}
Пример #5
0
/**
 * This routine opens an ET system for client use.
 *
 * Given an ET system on the same host, this routine will map the system's shared memory into the
 * user's space. It also starts up a thread to produce a heartbeat and a second thread to monitor
 * the ET system's heartbeat. If the ET system is remote, a network connection is made to it.<p>
 *
 * The ET system is implemented as a single memory mapped file of the name, filename.
 * This routine should only be called once, before all other ET routines are used, or after a
 * system has been closed with a call to @ref et_close or @ref et_forcedclose. A successful return
 * from this routine assures connection to an ET system which is up and running.
 * <b><i>IT IS CRUCIAL THAT THE USER GET A RETURN VALUE OF "ET_OK" IF THE USER WANTS AN ET SYSTEM
 * GUARANTEED TO FUNCTION.</i></b><p>
 *
 * The user may open an ET system on a remote host. ET decides whether the user is on the same
 * as or a different machine than the system. If the determination is made that the user is on
 * another computer, then network connections are made to that system.<p>
 *
 * @param id          pointer to ET system id which gets filled in if ET system successfully opened.
 * @param filename    name of ET system file.
 * @param openconfig  ET system open configuration.
 *
 * @returns @ref ET_OK             if successful
 * @returns @ref ET_ERROR          if bad arg, ET name too long, cannot initialize id,
 *                                 creating/using shared memory, incompatible values for @ref ET_STATION_SELECT_INTS,
 *                                 or ET system is 32 bit and this program is 64 bit,
 * @returns @ref ET_ERROR_TIMEOUT if the ET system is still not active before the routine returns.
 * @returns @ref ET_ERROR_TOOMANY  if broad/multicasting and too many responses
 * @returns @ref ET_ERROR_REMOTE   if broad/multicasting and cannot find/connect to ET system or
 *                                 cannot allocate memory or ET system & user use different versions of ET, or
 *                                 the host has a strange byte order.
 * @returns @ref ET_ERROR_READ     if network read error.
 * @returns @ref ET_ERROR_WRITE    if network write error.
 */
int et_open(et_sys_id *id, const char *filename, et_openconfig openconfig) {

    int             status, auto_open=0, err, locality;
    et_open_config *config;
    et_openconfig   auto_config = NULL;
    int             def_debug;

    if (openconfig == NULL) {
        auto_open = 1;
        if (et_open_config_init(&auto_config) == ET_ERROR) {
            et_logmsg("ERROR", "et_open, null arg for openconfig, cannot use default\n");
            return ET_ERROR;
        }
        openconfig = auto_config;
    }

    config = (et_open_config *) openconfig;

    err = ET_OK;
    /* argument checking */
    if ((filename == NULL) || (config->init != ET_STRUCT_OK)) {
        et_logmsg("ERROR", "et_open, bad argument\n");
        err = ET_ERROR;
    }
    else if (strlen(filename) > ET_FILENAME_LENGTH - 1) {
        et_logmsg("ERROR", "et_open, ET name too long\n");
        err = ET_ERROR;
    }

    if (err != ET_OK) {
        if (auto_open == 1) {
            et_open_config_destroy(auto_config);
        }
        return err;
    }

    /* initialize id */
    if (et_id_init(id) != ET_OK) {
        et_logmsg("ERROR", "et_open, cannot initialize id\n");
        return ET_ERROR;
    }

    if (et_open_config_getdebugdefault(openconfig, &def_debug) != ET_OK) {
        def_debug = ET_DEBUG_ERROR;
    }
    et_system_setdebug(*id, def_debug);


    /* Decide whether we are looking for the ET system locally,
     * locally on some non-mutex-sharing operating
     * system, remotely, or anywhere.
     */
    locality = et_findlocality(filename, openconfig);
    /* if host is local ... */
    if (locality == ET_LOCAL) {
        status = etl_open(id, filename, openconfig);
        /* If this is a Java-based ET sys, try opening it as remote client. */
        if (status == ET_ERROR_JAVASYS) {
            et_logmsg("ERROR", "et_open: cannot open Java ET file, try as remote client\n");
            status = etr_open(id, filename, openconfig);
        }
    }
        /* else if host is remote ... */
    else if (locality == ET_REMOTE) {
        status = etr_open(id, filename, openconfig);
    }
        /* else if host is local on Linux ... */
    else if (locality == ET_LOCAL_NOSHARE) {
        status = etn_open(id, filename, openconfig);
    }
        /* else if too many systems responded and we have return error policy ... */
    else if ((locality == ET_ERROR_TOOMANY) && (config->policy == ET_POLICY_ERROR)) {
        if (auto_open == 1) {
            et_open_config_destroy(auto_config);
        }
        et_logmsg("ERROR", "et_open: too many ET systems of that name responded\n");
        return ET_ERROR;
    }
        /* else did not find ET system by broad/multicasting. In
         * this case, try to open a local system first then remote.
         */
    else {
        int shared = et_sharedmutex();
        /* if local operating system can share pthread mutexes ... */
        if (shared == ET_MUTEX_SHARE) {
            status = etl_open(id, filename, openconfig);
        }
        else {
            status = etn_open(id, filename, openconfig);
        }

        if (status != ET_OK) {
            status = etr_open(id, filename, openconfig);
        }
    }

    if (status != ET_OK) {
        et_id_destroy(*id);
    }

    if (auto_open == 1) {
        et_open_config_destroy(auto_config);
    }

    return status;
}
Пример #6
0
int main(int argc,char **argv)
{
    int             i, j, c, i_tmp, status, swappedData, numRead;
    int             startingVal=0, errflg=0, group=1, chunk=1, size=32, verbose=0;
    int             sendBufSize=0, recvBufSize=0, noDelay=0;
    unsigned short  serverPort = ET_SERVER_PORT;
    char            et_name[ET_FILENAME_LENGTH], host[256], mcastAddr[16], interface[16];
    void            *fakeData;

    et_att_id	    attach1;
    et_sys_id       id;
    et_openconfig   openconfig;
    et_event        **pe;
    struct timespec timeout;
#if defined __APPLE__
    struct timeval  t1, t2;
#else
    struct timespec t1, t2;
#endif
    pthread_t       tid;

    /* statistics variables */
    double          eventRate=0.0, avgEventRate=0.0;
    int64_t         eventCount=0, totalEventCount=0;
    
    double          byteRate=0.0, avgByteRate=0.0;
    int64_t         byteCount=0, totalByteCount=0;
    
    int64_t         totalT=0, time, time1, time2;
    

    /* multiple character command-line options */
    static struct option long_options[] = {
        {"host", 1, NULL, 0},
        {"rb",   1, NULL, 1},
        {"sb",   1, NULL, 2},
        {"nd",   0, NULL, 3},
        {0, 0, 0, 0}
    };

    memset(host, 0, 16);
    memset(mcastAddr, 0, 16);
    memset(et_name, 0, ET_FILENAME_LENGTH);

    while ((c = getopt_long_only(argc, argv, "vn:s:p:d:f:c:g:i:", long_options, 0)) != EOF) {
      
        if (c == -1)
            break;

        switch (c) {
            case 'c':
                i_tmp = atoi(optarg);
                if (i_tmp > 0 && i_tmp < 1001) {
                    chunk = i_tmp;
                    printf("Setting chunk to %d\n", chunk);
                } else {
                    printf("Invalid argument to -c. Must < 1001 & > 0.\n");
                    exit(-1);
                }
                break;

            case 's':
                i_tmp = atoi(optarg);
                if (i_tmp > 0) {
                    size = i_tmp;
                } else {
                    printf("Invalid argument to -s. Must be a positive integer.\n");
                    exit(-1);
                }
                break;

            case 'p':
                i_tmp = atoi(optarg);
                if (i_tmp > 1023 && i_tmp < 65535) {
                    serverPort = i_tmp;
                } else {
                    printf("Invalid argument to -p. Must be < 65535 & > 1023.\n");
                    exit(-1);
                }
                break;

            case 'g':
                i_tmp = atoi(optarg);
                if (i_tmp > 0 && i_tmp < 501) {
                    group = i_tmp;
                } else {
                    printf("Invalid argument to -g. Must be 501 > g > 0.\n");
                    exit(-1);
                }
                break;

            case 'f':
                if (strlen(optarg) >= ET_FILENAME_LENGTH) {
                    fprintf(stderr, "ET file name is too long\n");
                    exit(-1);
                }
                strcpy(et_name, optarg);
                break;

            case 'i':
                if (strlen(optarg) > 15 || strlen(optarg) < 7) {
                    fprintf(stderr, "interface address is bad\n");
                    exit(-1);
                }
                strcpy(interface, optarg);
                break;

            case 0:
                if (strlen(optarg) >= 255) {
                    fprintf(stderr, "host name is too long\n");
                    exit(-1);
                }
                strcpy(host, optarg);
                break;

            case 1:
                i_tmp = atoi(optarg);
                if (i_tmp < 1) {
                    printf("Invalid argument to -rb. Recv buffer size must be > 0.\n");
                    exit(-1);
                }
                recvBufSize = i_tmp;
                break;

            case 2:
                i_tmp = atoi(optarg);
                if (i_tmp < 1) {
                    printf("Invalid argument to -rb. Send buffer size must be > 0.\n");
                    exit(-1);
                }
                sendBufSize = i_tmp;
                break;

            case 3:
                noDelay = 1;
                break;

            case 'v':
                verbose = ET_DEBUG_INFO;
                break;

            case ':':
            case 'h':
            case '?':
            default:
                errflg++;
        }
    }
    
    if (optind < argc || errflg || strlen(host) < 1 || strlen(et_name) < 1) {
        fprintf(stderr,
                "usage: %s  %s\n%s\n%s\n\n",
                argv[0],
                "-f <ET name> -host <ET host> [-h] [-v] [-c <chunk size>] [-s <event size>]",
                "                     [-g <group>] [-p <ET server port>] [-i <interface address>]",
                "                     [-rb <buf size>] [-sb <buf size>] [-nd]");

        fprintf(stderr, "          -host ET system's host\n");
        fprintf(stderr, "          -f ET system's (memory-mapped file) name\n");
        fprintf(stderr, "          -h help\n");
        fprintf(stderr, "          -v verbose output\n");
        fprintf(stderr, "          -c number of events in one get/put array\n");
        fprintf(stderr, "          -s event size in bytes\n");
        fprintf(stderr, "          -g group from which to get new events (1,2,...)\n");
        fprintf(stderr, "          -p ET server port\n");
        fprintf(stderr, "          -i outgoing network interface IP address (dot-decimal)\n");
        fprintf(stderr, "          -rb TCP receive buffer size (bytes)\n");
        fprintf(stderr, "          -sb TCP send    buffer size (bytes)\n");
        fprintf(stderr, "          -nd use TCP_NODELAY option\n\n");
        fprintf(stderr, "          This blaster works by making a direct connection to the\n");
        fprintf(stderr, "          ET system's server port and blasting as much data as possible\n");
        fprintf(stderr, "          over the connecting TCP socket.\n\n");
        exit(2);
    }

    /* allocate some memory */
    pe = (et_event **) calloc(chunk, sizeof(et_event *));
    if (pe == NULL) {
        printf("%s: out of memory\n", argv[0]);
        exit(1);
    }
    
    fakeData = (void *) malloc(size);
    if (fakeData == NULL) {
        printf("%s: out of memory\n", argv[0]);
        exit(1);
    }
        

    /******************/
    /* open ET system */
    /******************/
    et_open_config_init(&openconfig);
    et_open_config_setcast(openconfig, ET_DIRECT);
    et_open_config_sethost(openconfig, host);
    et_open_config_setserverport(openconfig, serverPort);
    et_open_config_setmode(openconfig, ET_HOST_AS_REMOTE);
    /* Defaults are to use operating system default buffer sizes and turn off TCP_NODELAY */
    et_open_config_settcp(openconfig, recvBufSize, sendBufSize, noDelay);
    if (strlen(interface) > 6) {
        et_open_config_setinterface(openconfig, interface);
    }
    
    et_open_config_setwait(openconfig, ET_OPEN_WAIT);
    if (et_open(&id, et_name, openconfig) != ET_OK) {
        printf("%s: et_open problems\n", argv[0]);
        exit(1);
    }
    et_open_config_destroy(openconfig);
 
    /* set level of debug output (everything) */
    if (verbose) {
        et_system_setdebug(id, ET_DEBUG_INFO);
    }
  
    /* attach to grandcentral station */
    if (et_station_attach(id, ET_GRANDCENTRAL, &attach1) < 0) {
        printf("%s: error in et_station_attach\n", argv[0]);
        exit(1);
    }

    /* create thread to deal with client */
//    pthread_create(&tid, NULL, newEventsThread, (void *) pinfo);

  
    /* read time for future statistics calculations */
#if defined __APPLE__
    gettimeofday(&t1, NULL);
    time1 = 1000L*t1.tv_sec + t1.tv_usec/1000L; /* milliseconds */
#else
    clock_gettime(CLOCK_REALTIME, &t1);
    time1 = 1000L*t1.tv_sec + t1.tv_nsec/1000000L; /* milliseconds */
#endif


    while (1) {
      
        status = et_events_new_group(id, attach1, pe, ET_SLEEP | ET_NOALLOC,
                                     NULL, size, chunk, group, &numRead);

        if (status != ET_OK) {
            printf("%s: et_events_new_group error, status = %d\n", argv[0], status);
            goto error;
        }

        /* set data to existing buffer (with ET_NOALLOC), and set data length */
        if (1) {
            for (i=0; i < numRead; i++) {
                et_event_setlength(pe[i], size);
                et_event_setdatabuffer(id, pe[i], fakeData);
            }
        }

        /* put events back into the ET system */
        status = et_events_put(id, attach1, pe, numRead);
        if (status != ET_OK) {
            printf("%s: et_events_put error, status = %d\n", argv[0], status);
            goto error;
        }

        eventCount += numRead;
        byteCount  += numRead*(size + 52) + 20; /* 52 is event overhead, 20 is ET call overhead */
       
        /* statistics */
#if defined __APPLE__
        gettimeofday(&t2, NULL);
        time2 = 1000L*t2.tv_sec + t2.tv_usec/1000L; /* milliseconds */
#else
        clock_gettime(CLOCK_REALTIME, &t2);
        time2 = 1000L*t2.tv_sec + t2.tv_nsec/1000000L; /* milliseconds */
#endif
        time = time2 - time1;
        
        if (time > 5000) {
        
            eventRate = 1000.0 * ((double) eventCount) / time;
            byteRate  = 1000.0 * ((double) byteCount)  / time;
            
            totalEventCount += eventCount;
            totalByteCount  += byteCount;
            
            totalT += time;
            
            avgEventRate = 1000.0 * ((double) totalEventCount) / totalT;
            avgByteRate  = 1000.0 * ((double) totalByteCount)  / totalT;
            
            printf("evRate: %3.4g Hz,  %3.4g avg;  byteRate: %3.4g bytes/sec,  %3.4g avg\n",
                   argv[0], eventRate, avgEventRate, byteRate, avgByteRate);
            
            eventCount = 0;
            byteCount  = 0;
            
#if defined __APPLE__
            gettimeofday(&t1, NULL);
            time1 = 1000L*t1.tv_sec + t1.tv_usec/1000L;
#else
            clock_gettime(CLOCK_REALTIME, &t1);
            time1 = 1000L*t1.tv_sec + t1.tv_nsec/1000000L;
#endif
        }

    } /* while(1) */
    
  
    error:

    printf("%s: DONE\n", argv[0]);
    exit(0);
}
Пример #7
0
/* our version of 'et_start' */
int
ettStart()
{
  objClass object = localobject;
  ET_priv *etp = (ET_priv *) object->privated;

  size_t hostlen = ET_FILENAME_LENGTH - 1;
  char *ch;

  struct timespec btime = {1, 0}; /* 1 sec */

  int status, ntransferred = 0;
  MYSQL *dbsock;
  char tmp[1000], tmpp[1000];

  printf("ettStart reached\n");

  printf("\n0 etp->exit = %d\n\n",etp->exit);

  /************************************/
  /* default configuration parameters */
  /************************************/
  etp->nevents = 4000;      /* total number of events */
  etp->event_size = 500000; /* size of event in bytes */

  etp->serverPort = 11111;  /* server port number, unique for every ET system on the same machine */
                            /* will NOT use that value, will get free port and put it into database */

  etp->udpPort = 0;
  etp->deleteFile = 1;
  etp->ngroups = 1;    
  etp->noDelay = 0;
  etp->maxNumStations = 0;
  etp->sendBufSize = 0;
  etp->recvBufSize = 0;
  etp->et_verbose = ET_DEBUG_NONE;




  /***************************************************/
  /* extract all necessary information from database */

  /* connect to database */
  dbsock = dbConnect(mysql_host, expid);


  /* get 'from' info */
  sprintf(tmp,"SELECT inputs FROM %s WHERE name='%s'",configname,object->name);
  printf("MYSQL QUERY >%s<\n",tmp);
  if(dbGetStr(dbsock, tmp, tmpp)==ET_ERROR)
  {
    printf("coda_ett: ERROR in mysql query >%s<\n",tmp);
  }
  else
  {
    printf("inputs >%s<\n",tmpp);
  }

  ch = strchr(tmpp,':'); /* get pointer to the location of ':' */
  if(ch==NULL)
  {
    printf("wrong arguments in 'from' - exit\n");
    exit(0);
  }
  ch[0] = '\0'; /* replace ':' by the end of string */

  /* info from database looks like 'ET66:ctof1', so after parsing
     'tmpp' contains 'ET66' and '(ch+1)' points to 'ctof1'; we are
     not using 'ET66' names here, just 'ctof1' as hostname; 'et_from'
     will be set using session name */
  strcpy(etp->host_from,(ch+1));
  /*sprintf(etp->et_from,"/tmp/et_sys_%s",session);*/
  sprintf(etp->et_from,"/et/%s",session);
  printf("host_from >%s<, et_from >%s<\n",etp->host_from,etp->et_from);




  /* get 'to' info */
  sprintf(tmp,"SELECT outputs FROM %s WHERE name='%s'",configname,object->name);
  printf("MYSQL QUERY >%s<\n",tmp);
  if(dbGetStr(dbsock, tmp, tmpp)==ET_ERROR)
  {
    printf("cannot get 'outputs' from table>%s< for the name>%s<\n",configname,object->name);
    return(ET_ERROR);
  }
  else
  {
    printf("outputs >%s<\n",tmpp);
  }
  ch = strchr(tmpp,':'); /* get pointer to the location of ':' */
  if(ch==NULL)
  {
    printf("wrong arguments in 'to' - exit\n");
    exit(0);
  }
  ch[0] = '\0'; /* replace ':' by the end of string */
  strcpy(etp->host_to,(ch+1));
  /*sprintf(etp->et_to,"/tmp/et_sys_%s",session);*/
  sprintf(etp->et_to,"/et/%s",session);
  printf("host_to >%s<, et_to >%s<\n",etp->host_to,etp->et_to);


  /* disconnect from database */
  dbDisconnect(dbsock);


  /* station 'from' */
  strcpy(etp->station,"ETT");




  /* init ET configuration will be used for both ET systems */
  et_open_config_init(&etp->openconfig);


  /*****************/
  /* open 'from' ET */
  /*****************/

  et_open_config_sethost(etp->openconfig, etp->host_from);
  et_open_config_gethost(etp->openconfig, ch);
  printf("host_from >%s<\n",ch);
  /*et_open_config_setport(openconfig, 12345);*/


  /*sergey: increase tcp buffersize 
  {
	int rBufSize;
    int sBufSize;
    int noDelay;

	et_open_config_gettcp(openconfig, &rBufSize, &sBufSize, &noDelay);
    printf("default rBufSize=%d, sBufSize=%d, noDelay=%d\n", rBufSize, sBufSize, noDelay);

	rBufSize = 65000;
    sBufSize = 65000;
    noDelay = 0;
	et_open_config_settcp(openconfig, rBufSize, sBufSize, noDelay);

	et_open_config_gettcp(openconfig, &rBufSize, &sBufSize, &noDelay);
    printf("ett: set rBufSize=%d, sBufSize=%d, noDelay=%d\n", rBufSize, sBufSize, noDelay);
  }
*/

  if(et_open(&etp->id_from, etp->et_from, etp->openconfig) != ET_OK)
  {
    printf("et_open 'from' problems\n");
    exit(1);
  }


  /******************/
  /* open 'to' ET */
  /******************/

  /*!!!!!!!!!!!!!!!! ET_HOST_ANYWHERE works, to_node does not !!!!!!!!*/
  et_open_config_sethost(etp->openconfig, etp->host_to/*ET_HOST_ANYWHERE*/);
  et_open_config_gethost(etp->openconfig, ch);
  printf("host_to >%s<\n",ch);

  /* Always use 'direct' connection: you can connect to any subnet,
     but only one ET system allowed on remote machine */
  et_open_config_setcast(etp->openconfig, ET_DIRECT);






  /*sergey: increase tcp buffersize 
  {
	int rBufSize;
    int sBufSize;
    int noDelay;

	et_open_config_gettcp(openconfig, &rBufSize, &sBufSize, &noDelay);
    printf("default rBufSize=%d, sBufSize=%d, noDelay=%d\n", rBufSize, sBufSize, noDelay);

	rBufSize = 65000;
    sBufSize = 65000;
    noDelay = 0;
	et_open_config_settcp(openconfig, rBufSize, sBufSize, noDelay);

	et_open_config_gettcp(openconfig, &rBufSize, &sBufSize, &noDelay);
    printf("ett: set rBufSize=%d, sBufSize=%d, noDelay=%d\n", rBufSize, sBufSize, noDelay);
  }
*/


  /*
  {
    et_open_config *config = (et_open_config *) openconfig;
    printf("befor et_open: rBufSize=%d, sBufSize=%d, noDelay=%d\n",
      config->tcpSendBufSize,config->tcpRecvBufSize,config->tcpNoDelay);
  }
  */


  if(et_open(&etp->id_to, etp->et_to, etp->openconfig) != ET_OK)
  {
    printf("et_open 'to' problems\n");
    exit(1);
  }

  {
    et_id *idto = (et_id *) etp->id_to;
    printf("11111: idto->endian=0x%08x idto->systemendian=0x%08x\n",idto->endian,idto->systemendian);
  }

printf("11\n");fflush(stdout);
  /* destroy configuration */
  et_open_config_destroy(etp->openconfig);

  /* init station configuration */
  et_station_config_init(&etp->sconfig);
  et_station_config_setuser(etp->sconfig, ET_STATION_USER_MULTI);
  et_station_config_setrestore(etp->sconfig, ET_STATION_RESTORE_OUT);
  et_station_config_setprescale(etp->sconfig, 1);
  et_station_config_setcue(etp->sconfig, 150);
 
printf("12\n");fflush(stdout);

  /* ET system "all" mode */
  et_station_config_setselect(etp->sconfig, ET_STATION_SELECT_ALL);
  et_station_config_setblock(etp->sconfig, ET_STATION_BLOCKING);

  /* ET system "on req" mode 
  et_station_config_setselect(etp->sconfig, ET_STATION_SELECT_ALL);
  et_station_config_setblock(etp->sconfig, ET_STATION_NONBLOCKING);
  */
  /* ET system "condition" mode 
  et_station_config_setselect(etp->sconfig, ET_STATION_SELECT_MATCH);
  et_station_config_setblock(setp->config, ET_STATION_BLOCKING);
  et_station_config_setselectwords(etp->sconfig, selections);
  */
  /* new non-blocking "condition" mode 
  et_station_config_setselect(etp->sconfig, ET_STATION_SELECT_MATCH);
  et_station_config_setblock(etp->sconfig, ET_STATION_NONBLOCKING);
  et_station_config_setselectwords(etp->sconfig, selections);
  */
  /* user's condition, blocking  mode 
  et_station_config_setselect(etp->sconfig, ET_STATION_SELECT_USER);
  et_station_config_setblock(etp->sconfig, ET_STATION_BLOCKING);
  et_station_config_setselectwords(etp->sconfig, selections);
  if (et_station_config_setfunction(etp->sconfig, "et_carls_function") == ET_ERROR) {
	printf("%s: cannot set function\n", argv[0]);
	exit(1);
  }
  if (et_station_config_setlib(etp->sconfig, "/home/timmer/cvs/coda/source/et/src/libet_user.so") == ET_ERROR) {
    printf("%s: cannot set library\n", argv[0]);
	exit(1);
  }
  */
  /* user's condition, nonblocking mode 
  et_station_config_setselect(etp->sconfig, ET_STATION_SELECT_USER);
  et_station_config_setblock(etp->sconfig, ET_STATION_NONBLOCKING);
  et_station_config_setselectwords(etp->sconfig, selections);
  et_station_config_setfunction(etp->sconfig, "et_carls_function");
  et_station_config_setlib(etp->sconfig, "/home/timmer/cvs/coda/source/et/src/libet_user.so");
  */
  
  /* set debug level */
  et_system_setdebug(etp->id_from, ET_DEBUG_INFO);
  et_system_setdebug(etp->id_to,   ET_DEBUG_INFO);

  if ((status = et_station_create(etp->id_from, &etp->stat_from, etp->station, etp->sconfig)) < ET_OK)
  {
    if (status == ET_ERROR_EXISTS)
    {
      /* my_stat contains pointer to existing station */;
      printf("station already exists, will attach to it\n");

      /* get id and attach to existing station (must be created by 'et_start' */
      if((status = et_station_name_to_id(etp->id_from, &etp->stat_from, etp->station)) < ET_OK)
      {
        printf("error in station_name_to_id\n");
        exit(0);
      }
    }
    else
    {
      printf("error in station creation\n");
      exit(0);
    }
  }

  et_station_config_destroy(etp->sconfig);
printf("13\n");fflush(stdout);





  /* */
  if (et_station_attach(etp->id_from, etp->stat_from, &etp->att_from) < 0)
  {
    printf("error in station attach\n");
    exit(0);
  }
printf("14\n");fflush(stdout);

  if (et_station_attach(etp->id_to, ET_GRANDCENTRAL, &etp->att_to) < 0)
  {
    printf("error in station attach\n");
    exit(0);
  }
printf("15\n");fflush(stdout);

  et_bridge_config_init(&etp->bconfig);

  /*et_bridge_config_setfunc(etp->bconfig, et_bridge_CODAswap);*/


  /* set timeouts - does not do anything ???
  if (et_bridge_config_settimeoutfrom(etp->bconfig, btime) < 0)
  {
    printf("error et_bridge_config_settimeoutfrom\n");
    exit(0);
  }

  if (et_bridge_config_settimeoutto(etp->bconfig, btime) < 0)
  {
    printf("error et_bridge_config_settimeoutto\n");
    exit(0);
  }
  */

  printf("1 etp->exit = %d\n",etp->exit);
  printf("1 etp->exit = %d\n",etp->exit);
  printf("1 etp->exit = %d\n",etp->exit);

  /* infinite loop */
  status = ET_OK;
  while((status == ET_OK) && (etp->exit == 0))
  {
	printf("-> status=%d etp->exit=%d\n",status,etp->exit);
    status = et_events_bridge(etp->id_from, etp->id_to, etp->att_from, etp->att_to,
			      etp->bconfig, NUMEVENTS, &ntransferred);
  }

  printf("2 etp->exit = %d\n",etp->exit);
  printf("2 etp->exit = %d\n",etp->exit);
  printf("2 etp->exit = %d\n",etp->exit);

  /* cleanup */
  et_bridge_config_destroy(etp->bconfig);
  et_forcedclose(etp->id_from);
  et_forcedclose(etp->id_to);

  etp->exit = 0;

  return(ET_OK);
}
Пример #8
0
main(int argc,char **argv)
{
  int *jw;
  BOSIO *fd;
  int status, i, j, size, nevents_max, event_size, 
      freq, freq_tot=0, freq_avg, iterations=1, count;
  int con[ET_STATION_SELECT_INTS];
  et_statconfig   sconfig;
  et_openconfig   openconfig;
  et_event      **pe;
  et_att_id	      attach;
  et_sys_id       id;
  struct timespec timeout, t1, t2;
  double          time, avgsize, totsize;
  sigset_t        sigblock;
  pthread_t       tid;
  
  if (argc != 2) {
    printf("Usage: fpack2et <et_filename>\n");
    exit(1);
  }

  timeout.tv_sec  = 0;
  timeout.tv_nsec = 1;

  printf("fpack2et: will try to attach\n");
  et_open_config_init(&openconfig);
  if (et_open(&id, argv[1], openconfig) != ET_OK) {
    printf("fpack2et: et_attach problems\n");
    exit(1);
  }
  et_open_config_destroy(openconfig);
  
  et_system_setdebug(id, ET_DEBUG_INFO);
  /*
   * Now that we have access to an ET system, find out have many
   * events it has and what size they are. Then allocate an array
   * of pointers to use for reading, writing, and modifying these events.
   */
  
  if (et_system_getnumevents(id, &nevents_max) != ET_OK) {
    printf("et_client: ET has died");
    exit(1);
  }
  if (et_system_geteventsize(id, &event_size) != ET_OK) {
    printf("et_client: ET has died");
    exit(1);
  }

  printf("event_size=%d\n",event_size);
  if ( (pe = (et_event **) calloc(nevents_max, sizeof(et_event *))) == NULL) {
    printf("et_client: cannot allocate memory");
    exit(1);
  }

  if (et_station_attach(id, ET_GRANDCENTRAL, &attach) < 0) {
    printf("et_client: error in station attach\n");
    exit(1);
  }
  printf("fpack2et: attached to gc, att = %d, pid = %d\n", attach, getpid());


/* open FPACK file */

  if ( (status = bosOpen("./bigfile","r",&fd)) !=0)
  {
	printf("bosOpen status %d \n",status);
    fflush(stdout);
    goto error;
  }


  while (et_alive(id))
  {
#if defined(linux) || defined(Darwin)
    gettimeofday(&t1, NULL);
#else
    clock_gettime(CLOCK_REALTIME, &t1);
#endif
    avgsize = 0.;
    totsize = 0.;
    for (j=0; j < NUMLOOPS ; j++)
    {
      count = 0;
      for (i=0; i < CHUNK ; i++)
      {
        /*status = et_event_new(id, attach, &pe[i], ET_SLEEP, NULL, size);*/
        status = et_event_new(id, attach, &pe[i], ET_SLEEP, NULL, (event_size-100));
        if (status == ET_OK)
        {
          count++;
        }
        else if (status == ET_ERROR)
        {
          printf("fpack2et: et_event_new() returns ET_ERROR\n");
          break;
        }
        else if (status == ET_ERROR_TIMEOUT)
        {
          printf("fpack2et: got timeout\n");
          break;
        }
        else if (status == ET_ERROR_EMPTY)
        {
          printf("fpack2et: no events\n");
          break;
        }
        else if (status == ET_ERROR_BUSY)
        {
          printf("fpack2et: grandcentral is busy\n");
          break;
        }
        else if (status != ET_OK)
        {
          printf("fpack2et: request error\n");
          goto error;
        }

/************************************************/
/* write data, set priority, set control values */
/************************************************/

/* read one event from FPACK file */

        et_event_getdata(pe[i], (void **)&jw);
        if((status = etRead(fd,jw,event_size,&size,control) ) == EBIO_EOF)
        {
          /*goto endoffile;*/

          bosRewind(fd);
          status = etRead(fd,jw,event_size,&size,control);
        }

        avgsize += (double)size;
        totsize += (double)size;

        if ( status != 0)
        {
          printf("etRead error = %d\n",status);	fflush(stdout);
          goto error;
        }

		control[0] = 1; /* to make MON happy */
		
        et_event_setcontrol(pe[i], control, 4);
        et_event_setlength(pe[i], size);
		
        /*if(i==5) et_event_setpriority(pe[i], ET_HIGH);*/
		/*
status = et_event_put(id, attach, pe[i]);
		*/
      } /* for CHUNK */
    
      /* write data */
	  /*
goto a456;
*/

      status = et_events_put(id, attach, pe, count);
/*exit(0);*/

      if (status == ET_OK)
      {
        ;
      }
      else if (status == ET_ERROR_DEAD)
      {
        printf("fpack2et: et_events_put() returns ET_ERROR_DEAD\n");
        break;
      }
      else if (status != ET_OK)
      {
        printf("fpack2et: put error\n");
        goto error;
      }
a456:
;
    } /* for NUMLOOPS */


    /* statistics */
    avgsize = avgsize / ((double)(CHUNK*NUMLOOPS));
#if defined(linux) || defined(Darwin)
    gettimeofday(&t2, NULL);
#else
    clock_gettime(CLOCK_REALTIME, &t2);
#endif
    time = (double)(t2.tv_sec - t1.tv_sec) + 1.e-9*(t2.tv_nsec - t1.tv_nsec);
    freq = (CHUNK*NUMLOOPS)/time;
    if ((INT_MAX - freq_tot) < freq)
    {
      freq_tot   = 0;
	  iterations = 1;
    }
    freq_tot += freq;
    freq_avg = freq_tot/iterations;
    totsize = totsize/time/1024./1024.;
    iterations++;
    printf("%4d fpack2et: %7d Hz, %7d Hz Avg;  %7.1f bytes size, %6.1f MBytes/sec\n",
      (int)totsize,freq,freq_avg,avgsize,totsize);
    if (!et_alive(id))
    {
      et_wait_for_alive(id);
    }

  } /* while(alive) */
    
  
error:
  printf("fpack2et: ERROR\n");
  exit(0);


endoffile:

/* close FPACK file */
  bosClose(fd);
  exit(0);
}
Пример #9
0
/* ET Initialization */    
int
mon_et_initialize(void)
{
  et_statconfig   sconfig;
  et_openconfig   openconfig;
  int             status;
  struct timespec timeout;

  timeout.tv_sec  = 2;
  timeout.tv_nsec = 0;

  /* Normally, initialization is done only once. However, if the ET
   * system dies and is restarted, and we're running on a Linux or
   * Linux-like operating system, then we need to re-initalize in
   * order to reestablish the tcp connection for communication etc.
   * Thus, we must undo some of the previous initialization before
   * we do it again.
   */
  if(et_init > 0)
  {
    /* unmap shared mem, detach attachment, close socket, free et_sys */
    et_forcedclose(et_sys);
  }
  
  printf("mon_et_initialize: start ET stuff\n");

  if(et_open_config_init(&openconfig) != ET_OK)
  {
    printf("ERROR: mon ET init: cannot allocate mem to open ET system\n");
    return MON_ERROR;
  }
  et_open_config_setwait(openconfig, ET_OPEN_WAIT);
  et_open_config_settimeout(openconfig, timeout);
  if(et_open(&et_sys, et_name, openconfig) != ET_OK)
  {
    printf("ERROR: mon ET init: cannot open ET system\n");
    return MON_ERROR;
  }
  et_open_config_destroy(openconfig);

  /* set level of debug output */
  et_system_setdebug(et_sys, ET_DEBUG_ERROR);

  /* where am I relative to the ET system? */
  et_system_getlocality(et_sys, &et_locality);

  et_station_config_init(&sconfig);
  et_station_config_setselect(sconfig,  ET_STATION_SELECT_ALL);
  et_station_config_setblock(sconfig,   ET_STATION_BLOCKING);
  et_station_config_setuser(sconfig,    ET_STATION_USER_MULTI);
  et_station_config_setrestore(sconfig, ET_STATION_RESTORE_OUT);
  et_station_config_setprescale(sconfig,1);

  if((status = et_station_create(et_sys, &et_statid, "TAPE", sconfig)) < 0)
  {
    if (status == ET_ERROR_EXISTS) {
      printf("mon ET init: station exists, will attach\n");
    }
    else
    {
      et_close(et_sys);
      et_station_config_destroy(sconfig);
      printf("ERROR: mon ET init: cannot create ET station (status = %d)\n",
        status);
      return(MON_ERROR);
    }
  }
  et_station_config_destroy(sconfig);

  if (et_station_attach(et_sys, et_statid, &et_attach) != ET_OK) {
    et_close(et_sys);
    printf("ERROR: mon ET init: cannot attach to ET station\n");
    return MON_ERROR;
  }

  et_init++;
  et_reinit = 0;
  printf("mon ET init: ET fully initialized\n");
  return MON_OK;
}
Пример #10
0
main(int argc,char **argv)
{
    int        i, j, size, status, nevents_max, event_size;
    et_att_id  attach;
    et_sys_id  id;
    et_event   *pe;
    et_openconfig   openconfig;

    if (argc != 2) {
        printf("Usage: et_producer <et_filename>\n");
        exit(1);
    }

    /* set the desired size of our events in bytes */
    size = 10;

    /* opening the ET system is the first thing we must do */
    et_open_config_init(&openconfig);
    et_open_config_sethost(openconfig, ET_HOST_ANYWHERE);
    et_open_config_setcast(openconfig, ET_BROADCAST);

    if (et_open(&id, argv[1], openconfig) != ET_OK) {
        printf("et_producer: et_open problems\n");
        exit(1);
    }
    et_open_config_destroy(openconfig);

    /* set the level of debug output that we want (everything) */
    et_system_setdebug(id, ET_DEBUG_INFO);

    /* attach to GRANDCENTRAL station since we are producing events */
    if (et_station_attach(id, ET_GRANDCENTRAL, &attach) < 0) {
        printf("et_producer: error in station attach\n");
        exit(1);
    }

    while (et_alive(id)) {
        /* get new/unused event */
        status = et_event_new(id, attach, &pe, ET_SLEEP, NULL, size);
        if (status != ET_OK) {
            printf("et_producer: error in et_event_new\n");
            goto error;
        }

        /* put data into the event here */

        /* put event back into the ET system */
        status = et_event_put(id, attach, pe);
        if (status != ET_OK) {
            printf("et_producer: put error\n");
            goto error;
        }

        if (!et_alive(id)) {
            et_wait_for_alive(id);
        }
    } /* while(alive) */


error:
    printf("et_producer: ERROR\n");
    exit(0);
}