Example #1
0
static int
debugLoop(int timeoutms) {
    fd_set read_set;
    struct timeval tv;
    int avail;
    int fd;

    if (interactive)
	debugPrompt();

retry:
    FD_ZERO(&read_set);
    FD_SET(0, &read_set);
    fd = 0;
    if (testState.connected) {
        FD_SET(testState.fc.fd, &read_set);
	fd = testState.fc.fd;
    }
    if (timeoutms >= 0) {
        tv.tv_sec = timeoutms / 1000;
        tv.tv_usec = (timeoutms % 1000) * 1000;
	avail = select(fd + 1, &read_set, NULL, NULL, &tv);
	if (avail == 0)
	    return(0);
    } else {
	avail = select(fd + 1, &read_set, NULL, NULL, NULL);
    }
    if (avail < 0) {
        if (errno == EINTR)
	    goto retry;
	fprintf(stderr, "debugLoop: select() failed \n");
	return (-1);
    }
    if (testState.connected) {
        if (FD_ISSET(testState.fc.fd, &read_set)) {
	    if (FAMPending(&(testState.fc)) > 0) {
		if (interactive)
		    printf("\n");
	        printEvents(0);
		if (interactive)
		    debugPrompt();
	    }
	}
    }
    if (timeoutms >= 0)
        return(0);
    if (!(FD_ISSET(0, &read_set)))
        goto retry;
    return(0);
}
Example #2
0
//----------------------------------------------------------------------------
// The main program function
//
void calcAndPrint(CalData& cd)
{
    // calc. start and end days
    //
    long jd_start = DateOps::dmyToDay( 1, cd.month, cd.year );
    long jd_end = ( cd.month < 12 ) ?
                  DateOps::dmyToDay( 1, cd.month + 1, cd.year ) :
                  DateOps::dmyToDay( 1, 1, cd.year + 1 );

    int end = int(jd_end - jd_start);

    // fill in data for month in question
    //
    TimePair sunRS[DAYS], moonRS[DAYS], astTwi[DAYS];
    double jd[DAYS];
    static const double hourFraction = 1./24.;

    double tzAdj = (double)cd.loc.timeZone() * hourFraction;
    long dstStart = DateOps::dstStart( cd.year );
    long dstEnd = DateOps::dstEnd( cd.year );

#if defined( PROGRESS_BAR )
    fprintf( stderr, "working" );
#endif

    for( int i=0; i<=end+1; i++ )
    {
        long day = jd_start + i;

        // automatically adjust for DST if enabled
        // This 'rough' method will be off by one on moon rise/set between
        //   midnight and 2:00 on "clock change" days. (sun & astTwi never
        //   occur at these times.)
        //
        double dstAdj =
            ( false == g_ignoreDst && day>=dstStart && day<dstEnd) ?
            hourFraction : 0.;

        jd[i] = (double)day - (tzAdj + dstAdj) - .5;

        // calculate rise/set times for the sun
        RiseSet::getTimes( sunRS[i], RiseSet::SUN, jd[i], cd.loc );

        // calculate rise/set times for Astronomical Twilight
        RiseSet::getTimes( astTwi[i], RiseSet::ASTRONOMICAL_TWI, jd[i], cd.loc );

        // calculate rise/set time for Luna )
        RiseSet::getTimes( moonRS[i], RiseSet::MOON, jd[i], cd.loc );

#if defined( PROGRESS_BAR )
        fputc( '.', stderr );
#endif
    }
    fputc( '\n', stderr );

    printHeading(cd);

    // print data for each day
    //
    char buf[256];
    for( int i=0; i<end; i++ ) {

        if (g_html) {
            if ( !(i&1) )
                fprintf( g_fp, "<TR CLASS=\"bar\">\n  <TD>" );
            else
                fprintf( g_fp, "<TR>\n  <TD>" );
        }

        // print day
        char* p = printDay( buf, jd_start, i, false );

        // print darkest hours
        p = printDarkness(p, i, astTwi, moonRS);

        // check for lunar & solar quarters and DST, print if found
        DST dstDay = DST_NONE;
        if ( dstStart == jd_start+i )
            dstDay = DST_START;
        else if ( dstEnd == jd_start+i )
            dstDay = DST_END;

        p = printEvents(p, i, jd, cd.loc, dstDay);

        // print rise/set times for Luna
        p = printTime( p, moonRS[i].TP_RISE );
        p = printTime( p, moonRS[i].TP_SET );

        // print set time for the sun
        p = printTime( p, sunRS[i].TP_SET );

        // print end of Astronomical Twilight */
        p = printTime( p, astTwi[i].TP_END );

        // next day
        p = printDay( p, jd_start, i+1, i == end-1 );
        if (!g_tabDelimited && !g_html)
            *p++ = ' ';

        // print start of Astronomical Twilight */
        p = printTime( p, astTwi[i+1].TP_START );

        // print rise time for the sun     (last column)
        p = printTime( p, sunRS[i+1].TP_RISE, false );

        if (g_html)
            strcpy( p, "</TD>\n</TR>\n" );
        else {
            *p++ = '\n';
            *p = 0;
        }

        fputs( buf, g_fp );
    }
    if (g_html)
        fputs( "</TABLE>\n</BODY>\n</HTML>\n", g_fp );
}
Example #3
0
static int
processCommand(char *line, int no)
{
    int ret, args;
    char *command = NULL;
    char *arg = NULL;
    char *arg2 = NULL;

    if (line == NULL)
        return (-1);
    if (line[0] == '#')
        return (0);

    args = scanCommand(line, &command, &arg, &arg2);
    if (args < 0)
        return (-1);
    if (args == 0)
        return (0);

    if (!strcmp(command, "connect")) {
        if (testState.connected) {
            fprintf(stderr, "connect line %d: already connected\n", no);
            return (-1);
        }
        if (arg != NULL) {
#ifdef HAVE_SETENV
            setenv("GAM_CLIENT_ID", arg, 1);
#elif HAVE_PUTENV
            char *client_id = malloc (strlen (arg) + sizeof "GAM_CLIENT_ID=");
              if (client_id)
              {
                strcpy (client_id, "GAM_CLIENT_ID=");
                strcat (client_id, arg);
                putenv (client_id);
              }
#endif /* HAVE_SETENV */
        }
        ret = FAMOpen(&(testState.fc));
        if (ret < 0) {
            fprintf(stderr, "connect line %d: failed to connect\n", no);
            return (-1);
        }
        testState.connected = 1;
        if (arg != NULL)
            printf("connected to %s\n", arg);
        else
            printf("connected\n");
    } else if (!strcmp(command, "kill")) {
        /*
         * okay, it's heavy but that's the simplest way since we do not have
         * the pid(s) of the servers running.
         */
        ret = system("killall gam_server");
        if (ret < 0) {
            fprintf(stderr, "kill line %d: failed to killall gam_server\n",
                    no);
            return (-1);
        }
        printf("killall gam_server\n");
    } else if (!strcmp(command, "disconnect")) {
        if (testState.connected == 0) {
            fprintf(stderr, "disconnect line %d: not connected\n", no);
            return (-1);
        }
        ret = FAMClose(&(testState.fc));
        if (ret < 0) {
            fprintf(stderr, "connect line %d: failed to disconnect\n", no);
            return (-1);
        }
        testState.connected = 0;
        printf("disconnected\n");
    } else if (!strcmp(command, "mondir")) {
        if (args >= 2) {
            if (arg[0] != '/')
                snprintf(filename, sizeof(filename), "%s/%s", pwd, arg);
            else
                snprintf(filename, sizeof(filename), "%s", arg);
        }
        if (args == 2) {
            ret = FAMMonitorDirectory(&(testState.fc), filename,
                                      &(testState.
                                        fr[testState.nb_requests]), NULL);
        } else if (args == 3) {
            int index;

            if (sscanf(arg2, "%d", &index) <= 0) {
                fprintf(stderr, "mondir line %d: invalid index value %s\n",
                        no, arg2);
                return (-1);
            }
            testState.fr[testState.nb_requests].reqnum = index;
            ret = FAMMonitorDirectory2(&(testState.fc), filename,
                                       &(testState.
                                         fr[testState.nb_requests]));
        } else {
            fprintf(stderr, "mondir line %d: invalid format\n", no);
            return (-1);
        }
        if (ret < 0) {
            fprintf(stderr, "mondir line %d: failed to monitor %s\n", no,
                    arg);
            return (-1);
        }
        printf("mondir %s %d\n", arg, testState.nb_requests);
        testState.nb_requests++;
    } else if (!strcmp(command, "monfile")) {
        if (args != 2) {
            fprintf(stderr, "monfile line %d: lacks name\n", no);
            return (-1);
        }
        if (arg[0] != '/')
            snprintf(filename, sizeof(filename), "%s/%s", pwd, arg);
        else
            snprintf(filename, sizeof(filename), "%s", arg);
        ret = FAMMonitorFile(&(testState.fc), filename,
                             &(testState.fr[testState.nb_requests]), NULL);
        if (ret < 0) {
            fprintf(stderr, "monfile line %d: failed to monitor %s\n", no,
                    arg);
            return (-1);
        }
        printf("monfile %s %d\n", arg, testState.nb_requests);
        testState.nb_requests++;
    } else if (!strcmp(command, "pending")) {
        if (args != 1) {
            fprintf(stderr, "pending line %d: extra argument %s\n", no,
                    arg);
            return (-1);
        }
        ret = FAMPending(&(testState.fc));
        if (ret < 0) {
            fprintf(stderr, "pending line %d: failed\n", no);
            return (-1);
        }
        printf("pending %d\n", ret);
    } else if (!strcmp(command, "mkdir")) {
        if (args != 2) {
            fprintf(stderr, "mkdir line %d: lacks name\n", no);
            return (-1);
        }
        ret = mkdir(arg, 0755);
        if (ret < 0) {
            fprintf(stderr, "mkdir line %d: failed to create %s\n", no,
                    arg);
            return (-1);
        }
        printf("mkdir %s\n", arg);
    } else if (!strcmp(command, "chmod")) {
        if (args != 3) {
            fprintf(stderr, "chmod line %d: lacks path and mode\n", no);
            return (-1);
        }
        ret = chmod(arg, strtol (arg2, NULL, 8));
        if (ret < 0) {
            fprintf(stderr, "chmod line %d: failed to chmod %s to %s\n", no,
                    arg, arg2);
            return (-1);
        }
        printf("chmod %s to %s\n", arg, arg2);
    } else if (!strcmp(command, "chown")) {
        if (args != 3) {
            fprintf(stderr, "chown line %d: lacks path and owner\n", no);
            return (-1);
        }
		struct stat sb;
		if (!lstat (arg, &sb)) {
			ret = (S_ISLNK (sb.st_mode)) ?
				lchown(arg, strtol(arg2, NULL, 10), -1) :
				chown(arg, strtol(arg2, NULL, 10), -1);
		} else
			ret=-1;
        if (ret < 0) {
            fprintf(stderr, "chown line %d: failed to chown %s to %s\n", no,
                    arg, arg2);
            return (-1);
        }
        printf("chown %s to %s\n", arg, arg2);
    } else if (!strcmp(command, "mkfile")) {
        if (args != 2) {
            fprintf(stderr, "mkfile line %d: lacks name\n", no);
            return (-1);
        }
        ret = open(arg, O_CREAT | O_WRONLY, 0666);
        if (ret < 0) {
            fprintf(stderr, "mkfile line %d: failed to open %s\n", no,
                    arg);
            return (-1);
        }
        close(ret);
        printf("mkfile %s\n", arg);
    } else if (!strcmp(command, "append")) {
        if (args != 2) {
            fprintf(stderr, "mkfile line %d: lacks name\n", no);
            return (-1);
        }
        ret = open(arg, O_RDWR | O_APPEND);
        if (ret < 0) {
            fprintf(stderr, "append line %d: failed to open %s\n", no,
                    arg);
            return (-1);
        }
        write(ret, "a", 1);
        close(ret);
        printf("append %s\n", arg);
    } else if (!strcmp(command, "rmdir")) {
        if (args != 2) {
            fprintf(stderr, "rmdir line %d: lacks name\n", no);
            return (-1);
        }
        ret = rmdir(arg);
        if (ret < 0) {
            fprintf(stderr, "rmdir line %d: failed to remove %s\n", no,
                    arg);
            return (-1);
        }
        printf("rmdir %s\n", arg);
    } else if (!strcmp(command, "rmfile")) {
        if (args != 2) {
            fprintf(stderr, "rmfile line %d: lacks name\n", no);
            return (-1);
        }
        ret = unlink(arg);
        if (ret < 0) {
            fprintf(stderr, "rmfile line %d: failed to unlink %s\n", no,
                    arg);
            return (-1);
        }
        printf("rmfile %s\n", arg);
	} else if (!strcmp(command, "move")) {
		if (args != 3)
		{
			fprintf(stderr, "move line %d: lacks something\n", no);
			return (-1);
		}
		ret = rename(arg, arg2);
		if (ret < 0) {
			fprintf(stderr, "move line %d: failed to move %s\n", no, arg);
			return (-1);
		}
		printf("move %s %s\n", arg, arg2);
	} else if (!strcmp(command, "link")) {
		if (args != 3) {
		fprintf(stderr, "link line %d: lacks target and name\n", no); return (-1);
		}
		ret = symlink(arg, arg2);
		if (ret < 0) {
			fprintf(stderr, "link line %d: failed to link to %s\n", no, arg);
			return (-1);
		}
		printf("link %s to %s\n", arg2, arg);
    } else if (!strcmp(command, "event")) {
        printEvent(no);
    } else if (!strcmp(command, "events")) {
        printEvents(no);
    } else if (!strcmp(command, "expect")) {
        int count;
        int delay = 0;
        int nb_events = testState.nb_events;

        if (args != 2) {
            fprintf(stderr, "expect line %d: lacks number\n", no);
            return (-1);
        }

        if (sscanf(arg, "%d", &count) <= 0) {
            fprintf(stderr, "expect line %d: invalid number value %s\n",
                    no, arg);
            return (-1);
        }
        /*
         * wait at most 3 secs before declaring failure
         */
        while ((delay < 30) && (testState.nb_events < nb_events + count)) {
            debugLoop(100);

/*	    printf("+"); fflush(stdout); */
            delay++;
        }
        if (testState.nb_events < nb_events + count) {
            printf("expect line %d: got %d of %d expected events\n",
                   no, testState.nb_events - nb_events, count);
            return (-1);
        }
    } else if (!strcmp(command, "sleep")) {
        int i;

        for (i = 0; (i < 30) && (FAMPending(&(testState.fc)) == 0); i++)
            usleep(50000);
    } else if (!strcmp(command, "wait")) {
        sleep(1);
    } else if (!strcmp(command, "cancel")) {
        if (args == 2) {
            int req_index = 0;

            if (sscanf(arg, "%d", &req_index) <= 0
                || req_index >= testState.nb_requests) {
                fprintf(stderr,
                        "cancel line %d: invalid req_index value %s\n", no,
                        arg);
                return (-1);
            }
            ret = FAMCancelMonitor(&(testState.fc),
                                   &(testState.fr[req_index]));

        } else {
            fprintf(stderr, "cancel line %d: invalid format\n", no);
            return (-1);
        }
        if (ret < 0) {
            fprintf(stderr,
                    "cancel line %d: failed to cancel req_index %s\n", no,
                    arg);
            return (-1);
        }
        printf("cancel %s %d\n", arg, testState.nb_requests);
    } else {
        fprintf(stderr, "Unable to parse line %d: %s\n", no, line);
        return (-1);
    }
    return (0);
}
Example #4
0
void kmp_stats_output_module::outputStats(const char* heading) 
{
    statistic allStats[TIMER_LAST];
    statistic allCounters[COUNTER_LAST];

    // stop all the explicit timers for all threads
    windupExplicitTimers();

    FILE * eventsOut;
    FILE * statsOut = outputFileName ? fopen (outputFileName, "a+") : stderr;

    if (eventPrintingEnabled()) {
        eventsOut = fopen(eventsFileName, "w+");
    }

    if (!statsOut)
        statsOut = stderr;

    fprintf(statsOut, "%s\n",heading);
    // Accumulate across threads.
    kmp_stats_list::iterator it;
    for (it = __kmp_stats_list.begin(); it != __kmp_stats_list.end(); it++) {
        int t = (*it)->getGtid();
        // Output per thread stats if requested.
        if (perThreadPrintingEnabled()) {
            fprintf (statsOut, "Thread %d\n", t);
            printStats(statsOut, (*it)->getTimers(), true);
            printCounters(statsOut, (*it)->getCounters());
            fprintf(statsOut,"\n");
        }
        // Output per thread events if requested.
        if (eventPrintingEnabled()) {
            kmp_stats_event_vector events = (*it)->getEventVector();
            printEvents(eventsOut, &events, t);
        }

        for (int s = 0; s<TIMER_LAST; s++) {
            // See if we should ignore this timer when aggregating
            if ((timeStat::masterOnly(timer_e(s)) && (t != 0)) || // Timer is only valid on the master and this thread is a worker
                (timeStat::workerOnly(timer_e(s)) && (t == 0)) || // Timer is only valid on a worker and this thread is the master
                timeStat::synthesized(timer_e(s))                 // It's a synthesized stat, so there's no raw data for it.
               )            
            {
                continue;
            }

            statistic * threadStat = (*it)->getTimer(timer_e(s));
            allStats[s] += *threadStat;
        }

        // Special handling for synthesized statistics.
        // These just have to be coded specially here for now. 
        // At present we only have a few: 
        // The total parallel work done in each thread.
        // The variance here makes it easy to see load imbalance over the whole program (though, of course,
        // it's possible to have a code with awful load balance in every parallel region but perfect load
        // balance oever the whole program.)
        // The time spent in barriers in each thread.
        allStats[TIMER_Total_work].addSample ((*it)->getTimer(TIMER_OMP_work)->getTotal());

        // Time in explicit barriers.
        allStats[TIMER_Total_barrier].addSample ((*it)->getTimer(TIMER_OMP_barrier)->getTotal());

        for (int c = 0; c<COUNTER_LAST; c++) {
            if (counter::masterOnly(counter_e(c)) && t != 0)
                continue;
            allCounters[c].addSample ((*it)->getCounter(counter_e(c))->getValue());
        }
    }

    if (eventPrintingEnabled()) {
        printPloticusFile();
        fclose(eventsOut);
    }

    fprintf (statsOut, "Aggregate for all threads\n");
    printStats (statsOut, &allStats[0], true);
    fprintf (statsOut, "\n");
    printStats (statsOut, &allCounters[0], false);

    if (statsOut != stderr)
        fclose(statsOut);

}
Example #5
0
void kmp_stats_output_module::outputStats(const char *heading) {
  // Stop all the explicit timers in all threads
  // Do this before declaring the local statistics because thay have
  // constructors so will take time to create.
  windupExplicitTimers();

  statistic allStats[TIMER_LAST];
  statistic totalStats[TIMER_LAST]; /* Synthesized, cross threads versions of
                                       normal timer stats */
  statistic allCounters[COUNTER_LAST];

  FILE *statsOut =
      !outputFileName.empty() ? fopen(outputFileName.c_str(), "a+") : stderr;
  if (!statsOut)
    statsOut = stderr;

  FILE *eventsOut;
  if (eventPrintingEnabled()) {
    eventsOut = fopen(eventsFileName, "w+");
  }

  printHeaderInfo(statsOut);
  fprintf(statsOut, "%s\n", heading);
  // Accumulate across threads.
  kmp_stats_list::iterator it;
  for (it = __kmp_stats_list->begin(); it != __kmp_stats_list->end(); it++) {
    int t = (*it)->getGtid();
    // Output per thread stats if requested.
    if (printPerThreadFlag) {
      fprintf(statsOut, "Thread %d\n", t);
      printTimerStats(statsOut, (*it)->getTimers(), 0);
      printCounters(statsOut, (*it)->getCounters());
      fprintf(statsOut, "\n");
    }
    // Output per thread events if requested.
    if (eventPrintingEnabled()) {
      kmp_stats_event_vector events = (*it)->getEventVector();
      printEvents(eventsOut, &events, t);
    }

    // Accumulate timers.
    for (timer_e s = timer_e(0); s < TIMER_LAST; s = timer_e(s + 1)) {
      // See if we should ignore this timer when aggregating
      if ((timeStat::masterOnly(s) && (t != 0)) || // Timer only valid on master
          // and this thread is worker
          (timeStat::workerOnly(s) && (t == 0)) // Timer only valid on worker
          // and this thread is the master
          ) {
        continue;
      }

      statistic *threadStat = (*it)->getTimer(s);
      allStats[s] += *threadStat;

      // Add Total stats for timers that are valid in more than one thread
      if (!timeStat::noTotal(s))
        totalStats[s].addSample(threadStat->getTotal());
    }

    // Accumulate counters.
    for (counter_e c = counter_e(0); c < COUNTER_LAST; c = counter_e(c + 1)) {
      if (counter::masterOnly(c) && t != 0)
        continue;
      allCounters[c].addSample((*it)->getCounter(c)->getValue());
    }
  }

  if (eventPrintingEnabled()) {
    printPloticusFile();
    fclose(eventsOut);
  }

  fprintf(statsOut, "Aggregate for all threads\n");
  printTimerStats(statsOut, &allStats[0], &totalStats[0]);
  fprintf(statsOut, "\n");
  printCounterStats(statsOut, &allCounters[0]);

  if (statsOut != stderr)
    fclose(statsOut);
}