Esempio n. 1
0
void selfn_monitor_time(const char *arg)
{
        if (!strcasecmp(arg, "inf") || !strcasecmp(arg, "infinite"))
                sel_timeout = -1; /**< infinite timeout */
        else
                sel_timeout = (int) strtouint64(arg);
}
Esempio n. 2
0
inline int
linux_table_scan(FILE *fp, struct linux_table *table)
{
    char *p;
    struct linux_table *t;
    char buf[1024];
    int ret = 0;

    while(fgets(buf, sizeof(buf), fp) != NULL) {
        for (t=table; t && t->field; t++) {
            if ((p = strstr(buf, t->field)) != NULL) {
                /* first digit after the matched field */
                for (p += t->field_len; *p; p++) {
                    if (isdigit((int)*p))
                        break;
                }
                if (isdigit((int)*p)) {
                    t->this = strtouint64(p, NULL, 10);
                    t->valid = LINUX_TABLE_VALID;
                    ret++;
                    break;
                }
            }
        }
    }
Esempio n. 3
0
void
token_set_counter ( Token *token, const gchar *str, GError **err )
{
  guint64 counter;
  GError *lerr;

  lerr = NULL;
  counter = strtouint64 ( str, &lerr );
  if ( lerr ){
    g_propagate_error ( err, lerr );
    return;
  }

  token->counter = counter;
}
Esempio n. 4
0
/**
 * @brief Verifies and translates definition of single
 *        allocation class of service
 *        from args into internal configuration.
 *
 * @param argc Number of arguments in input command
 * @param argv Input arguments for COS allocation
 */
static void
allocation_get_input(int argc, char *argv[])
{
	uint64_t mask = 0;

	if (argc < 2)
		sel_l3ca_cos_num = 0;
	else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-H")) {
		printf("Usage: %s [<COS#> <COS bitmask>]\n", argv[0]);
		printf("Example: %s 1 0xff\n\n", argv[0]);
		sel_l3ca_cos_num = 0;
	} else {
		sel_l3ca_cos_tab[0].class_id = (unsigned)atoi(argv[1]);
		mask = strtouint64(argv[2]);
		sel_l3ca_cos_tab[0].u.ways_mask = mask;
		sel_l3ca_cos_num = 1;
	}
}
Esempio n. 5
0
/**
 * @brief Verifies and translates definition of single allocation
 *        class of service from text string into internal configuration
 *        for specified sockets.
 *
 * @param str fragment of string passed to -e command line option
 * @param sockets array of sockets to set COS tables
 * @param sock_num number of sockets in array
 * @param type CAT type (L2/L3)
 */
static void
parse_allocation_cos(char *str, const uint64_t *sockets,
                     const unsigned sock_num, const enum sel_cat_type type)
{
        char *sp, *p = NULL;
        uint64_t mask = 0;
        unsigned i, class_id = 0;
        int update_scope = CAT_UPDATE_SCOPE_BOTH;

        sp = strdup(str);
        if (sp == NULL)
                sp = str;

        p = strchr(str, '=');
        if (p == NULL)
                parse_error(sp, "Invalid class of service definition");
        *p = '\0';

        parse_cos_mask_type(str, &update_scope, &class_id);
        mask = strtouint64(p+1);

        if (type == L2CA && update_scope != CAT_UPDATE_SCOPE_BOTH)
                parse_error(sp, "CDP not supported for L2 CAT!\n");
        free(sp);
        /**
         * Update all sockets COS table
         */
        if (sockets == NULL) {
                update_cat_cos_tab(&sel_cat_cos_all, class_id,
                                   mask, update_scope, type);
                return;
        }
        /**
         * Update COS tables
         */
        for (i = 0; i < sock_num; i++) {
                const unsigned s = (unsigned) sockets[i];
                /**
                 * Update specified socket COS table
                 */
                update_cat_cos_tab(&sel_cat_cos_tab[s], class_id,
                                   mask, update_scope, type);
        }
}
Esempio n. 6
0
/**
 * @brief Converts string describing CAT COS into ID and mask scope
 *
 * Current string format is: <ID>[CcDd]
 *
 * Some examples:
 *  1d  - class 1, data mask
 *  5C  - class 5, code mask
 *  0   - class 0, common mask for code & data
 *
 * @param [in] str string describing CAT COS. Function may modify
 *             the last character of the string in some conditions.
 * @param [out] scope indicates if string \a str refers to both COS masks
 *              or just one of them
 * @param [out] id class ID referred to in the string \a str
 */
static void
parse_cos_mask_type(char *str, int *scope, unsigned *id)
{
        size_t len = 0;

        ASSERT(str != NULL);
        ASSERT(scope != NULL);
        ASSERT(id != NULL);
        len = strlen(str);
        if (len > 1 && (str[len - 1] == 'c' || str[len - 1] == 'C')) {
                *scope = CAT_UPDATE_SCOPE_CODE;
                str[len - 1] = '\0';
        } else if (len > 1 && (str[len - 1] == 'd' || str[len - 1] == 'D')) {
                *scope = CAT_UPDATE_SCOPE_DATA;
                str[len - 1] = '\0';
        } else {
                *scope = CAT_UPDATE_SCOPE_BOTH;
        }
        *id = (unsigned) strtouint64(str);
}
Esempio n. 7
0
void selfn_monitor_interval(const char *arg)
{
        sel_mon_interval = (int) strtouint64(arg);
}
Esempio n. 8
0
/*
 * NAME
 *   strlisttonums
 *
 * DESCRIPTION
 *   Converts string of characters representing list of numbers into array of
 *   numbers. Allowed formats are:
 *     0,1,2,3
 *     0-10,20-18
 *     1,3,5-8,10,0x10-12
 *
 *   Numbers can be in decimal or hexadecimal format.
 *
 * PARAMETERS
 *   `s'         String representing list of unsigned numbers.
 *   `nums'      Array to put converted numeric values into.
 *   `max'       Maximum number of elements that nums can accommodate.
 *
 * RETURN VALUE
 *    Number of elements placed into nums.
 */
static size_t strlisttonums(char *s, uint64_t *nums, size_t max) {
  int ret;
  size_t index = 0;
  char *saveptr = NULL;

  if (s == NULL || nums == NULL || max == 0)
    return index;

  for (;;) {
    char *p = NULL;
    char *token = NULL;

    token = strtok_r(s, ",", &saveptr);
    if (token == NULL)
      break;

    s = NULL;

    while (isspace(*token))
      token++;
    if (*token == '\0')
      continue;

    p = strchr(token, '-');
    if (p != NULL) {
      uint64_t n, start, end;
      *p = '\0';
      ret = strtouint64(token, &start);
      if (ret < 0)
        return (0);
      ret = strtouint64(p + 1, &end);
      if (ret < 0)
        return (0);
      if (start > end) {
        return (0);
      }
      for (n = start; n <= end; n++) {
        if (!(isdup(nums, index, n))) {
          nums[index] = n;
          index++;
        }
        if (index >= max)
          return index;
      }
    } else {
      uint64_t val;

      ret = strtouint64(token, &val);
      if (ret < 0)
        return (0);

      if (!(isdup(nums, index, val))) {
        nums[index] = val;
        index++;
      }
      if (index >= max)
        return index;
    }
  }

  return index;
}
Esempio n. 9
0
unsigned
strlisttotab(char *s, uint64_t *tab, const unsigned max)
{
        unsigned index = 0;
        char *saveptr = NULL;

        if (s == NULL || tab == NULL || max == 0)
                return index;

        for (;;) {
                char *p = NULL;
                char *token = NULL;

                token = strtok_r(s, ",", &saveptr);
                if (token == NULL)
                        break;

                s = NULL;

                /* get rid of leading spaces & skip empty tokens */
                while (isspace(*token))
                        token++;
                if (*token == '\0')
                        continue;

                p = strchr(token, '-');
                if (p != NULL) {
                        /**
                         * range of numbers provided
                         * example: 1-5 or 12-9
                         */
                        uint64_t n, start, end;
                        *p = '\0';
                        start = strtouint64(token);
                        end = strtouint64(p+1);
                        if (start > end) {
                                /**
                                 * no big deal just swap start with end
                                 */
                                n = start;
                                start = end;
                                end = n;
                        }
                        for (n = start; n <= end; n++) {
                                if (!(isdup(tab, index, n))) {
                                        tab[index] = n;
                                        index++;
                                }
                                if (index >= max)
                                        return index;
                        }
                } else {
                        /**
                         * single number provided here
                         * remove duplicates if necessary
                         */
                        uint64_t val = strtouint64(token);

                        if (!(isdup(tab, index, val))) {
                                tab[index] = val;
                                index++;
                        }
                        if (index >= max)
                                return index;
                }
        }

        return index;
}
Esempio n. 10
0
int
gfs2_refresh_sbstats(const char *sysfs, const char *name, struct sbstats *sb)
{
    unsigned int id = 0;
    char buffer[4096];
    FILE *fp;

    /* Reset all counter for this fs */
    memset(sb, 0, sizeof(*sb));

    snprintf(buffer, sizeof(buffer), "%s/%s/sbstats", sysfs, name);
    buffer[sizeof(buffer)-1] = '\0';

    if ((fp = fopen(buffer, "r")) == NULL){
        /*
         * We set the values to UINT64_MAX to signify we have no
         * current values (no metric support or debugfs not mounted)
         *
         */
        memset(sb, -1, sizeof(*sb));
	return -oserror();
    }

    /*
     * Read through sbstats file one line at a time.  This is called on each
     * and every fetch request, so should be as quick as we can make it.
     *
     * Once we've skipped over the heading, the format is fixed so to make this
     * faster (we expect the kernel has a fixed set of types/stats) we go right
     * ahead and index directly into the stats structure for each line.  We do
     * check validity too - if there's a mismatch, we throw our toys.
     *
     * Also, we aggregate the per-CPU data for each statistic - we could go for
     * separate per-CPU metrics as well, but for now just keep it simple until
     * there's a real need for that extra complexity.
     *
     */
    while (fgets(buffer, sizeof(buffer), fp) != NULL) {
	char *typestr, *statstr, *end;
	char *p = buffer;

	if (strncmp(p, "type", 4) == 0)
	    continue;
	if (id > SBSTATS_COUNT)
	    break;

	typestr = p;
	for (typestr = p; !isspace((int)*p); p++) { }	/* skip lock type */
	for (; isspace((int)*p); p++) { *p = '\0'; }	/* eat whitespace */
	for (statstr = p; *p != ':'; p++) { }		/* skip stat type */
	*p = '\0';

	/* verify that the id we are up to matches what we see in the file */
	unsigned int type = id / NUM_LOCKSTATS;
	unsigned int stat = id % NUM_LOCKSTATS;
	if (strcmp(typestr, locktype[type]) != 0) {
	    __pmNotifyErr(LOG_ERR,
			"unexpected sbstat type \"%s\" (want %s at line %u)",
			typestr, locktype[type], id);
	    break;	/* eh? */
	}
	if (strcmp(statstr, stattype[stat]) != 0) {
	    __pmNotifyErr(LOG_ERR,
			"unexpected sbstat stat \"%s\" (want %s at line %u)",
			statstr, stattype[stat], id);
	    break;	/* wha? */
	}

	/* decode all of the (per-CPU) values until the end of line */
	for (p++; *p != '\0'; p++) {
	    __uint64_t value;

	    value = strtouint64(p, &end, 10);
	    if (end == p)
		break;
	    sb->values[id] += value;
	    p = end;
	}

	if (pmDebug & DBG_TRACE_APPL0)
	    __pmNotifyErr(LOG_INFO,
			"got expected sbstat type \"%s\", stat \"%s\" at line %u",
			typestr, statstr, id);

	/* now we can move on to the next metric (on the next line) */
	id++;
    }
    fclose(fp);
    return (id == SBSTATS_COUNT) ? 0 : -EINVAL;
}
Esempio n. 11
0
File: leaff.C Progetto: ondovb/canu
void
processArray(int argc, char **argv) {

  int arg = 1;
  while (arg < argc) {

    if       ((strcmp(argv[arg], "-f") == 0) ||
              (strcmp(argv[arg], "-F") == 0)) {
      delete fasta;
      fasta = new seqCache(argv[++arg]);

    } else if (strcmp(argv[arg], "-i") == 0) {

      failIfNoSource();

      ++arg;
      if ((argv[arg] == 0L) || (argv[arg][0] == '-'))
        fprintf(stderr, "ERROR: next arg to -i should be 'name', I got '%s'\n",
                (argv[arg] == 0L) ? "(nullpointer)" : argv[arg]), exit(1);

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        fprintf(stdout, "G\tseq\t%s:"F_U32"\t"F_U32"\t%s\n",
                argv[arg], s, fasta->getSequenceLength(s), ">unimplemented");

    } else if (strcmp(argv[arg], "-d") == 0) {
      failIfNoSource();
      printf(F_U32"\n", fasta->getNumberOfSequences());

    } else if (strcmp(argv[arg], "-L") == 0) {
      uint32 small = strtouint32(argv[++arg]);
      uint32 large = strtouint32(argv[++arg]);

      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        if ((small <= fasta->getSequenceLength(s)) && (fasta->getSequenceLength(s) < large))
          printSequence(s);

    } else if (strcmp(argv[arg], "-N") == 0) {
      double small = atof(argv[++arg]);
      double large = atof(argv[++arg]);

      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) {
        seqInCore *S   = fasta->getSequenceInCore(s);
        uint32     Ns  = 0;
        uint32     len = S->sequenceLength();
        char      *seq = S->sequence();

        for (uint32 i=begPos; i<len && i<endPos; i++)
          if ((seq[i] == 'n') || (seq[i] == 'N'))
            Ns++;

        double Np = 100.0 * Ns / len;

        if ((small <= Np) && (Np < large))
          printSequence(S);

        delete S;
      }

    } else if (strcmp(argv[arg], "-W") == 0) {
      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        printSequence(s);

    } else if (strcmp(argv[arg], "-G") == 0) {
      uint32 n = strtouint32(argv[++arg]);
      uint32 s = strtouint32(argv[++arg]);
      uint32 l = strtouint32(argv[++arg]);

      char      bases[4] = {'A', 'C', 'G', 'T'};
      char     *def      = new char [1024];
      char     *seq      = new char [l + 1];

      if (s == 0)
        s = 1;
      if (s > l)
        fprintf(stderr, "leaff: usage: -G num-seqs min-length max-length\n"), exit(1);

      for (uint32 i=0; i<n; i++) {
        uint32 j = s + ((l-s == 0) ? 0 : (MT.mtRandom32() % (l-s)));
        uint32 p = 0;

        while (p < j)
          seq[p++] = bases[MT.mtRandom32() & 0x3];
        seq[p] = 0;

        sprintf(def, "random%06"F_U32P, i);

        printSequence(def, seq, 0, j);
      }

      delete [] seq;
      delete [] def;

    } else if (strcmp(argv[arg], "-s") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Easy to fix, just read the first N sequences
      printSequence(argv[++arg]);

    } else if (strcmp(argv[arg], "-S") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Easy to fix, just read the first N sequences

      uint32 lowID  = fasta->getSequenceIID(argv[++arg]);
      uint32 highID = fasta->getSequenceIID(argv[++arg]);

      if (lowID > highID) {
        uint32 t = lowID;
        lowID    = highID;
        highID   = t;
      }

      for (uint32 s=lowID; (s <= highID) && (s <= fasta->getNumberOfSequences()); s++)
        printSequence(s);

    } else if (strcmp(argv[arg], "-r") == 0) {
      uint32 num = strtouint32(argv[++arg]);

      failIfNoSource();
      failIfNotRandomAccess();  //  Impossible to fix, or load whole thing into memory

      if (num >= fasta->getNumberOfSequences())
        num = fasta->getNumberOfSequences();

      uint32  *seqs = new uint32 [fasta->getNumberOfSequences()];

      for (uint32 i=0; i<fasta->getNumberOfSequences(); i++)
        seqs[i] = i;

      for (uint32 i=0; i<fasta->getNumberOfSequences(); i++) {
        uint32 j = MT.mtRandom32() % (fasta->getNumberOfSequences() - i) + i;
        uint32 t = seqs[j];
        seqs[j] = seqs[i];
        seqs[i] = t;
      }

      for (uint32 i=0; i<num; i++)
        printSequence(seqs[i]);

      delete [] seqs;

    } else if (strcmp(argv[arg], "-q") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Impossible to fix, or load whole thing into memory
      printIDsFromFile(argv[++arg]);

    } else if (strcmp(argv[arg], "-6") == 0) {
      withLineBreaks = 60;
      if ((argv[arg+1] != 0L) && (argv[arg+1][0] != '-'))
        withLineBreaks = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-w") == 0) {
      toUppercase = !toUppercase;
      for (int z=0; z<256; z++)
        translate[z] = (toUppercase) ? alphabet.toUpper(z) : (char)z;

    } else if (strcmp(argv[arg], "-R") == 0) {
      doReverse = !doReverse;

    } else if (strcmp(argv[arg], "-C") == 0) {
      doComplement = !doComplement;

    } else if (strcmp(argv[arg], "-H") == 0) {
      withDefLine    = !withDefLine;
      specialDefLine = 0L;

    } else if (strcmp(argv[arg], "-h") == 0) {
      withDefLine    = true;
      specialDefLine = argv[++arg];

    } else if (strcmp(argv[arg], "-e") == 0) {
      begPos = strtouint32(argv[++arg]);
      endPos = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-ends") == 0) {
      endExtract = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-A") == 0) {
      processFile(argv[++arg]);



    } else if (strcmp(argv[arg], "--findduplicates") == 0) {
      findDuplicates(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--mapduplicates") == 0) {
      mapDuplicates(argv[arg+1], argv[arg+2]);
      exit(0);

    } else if (strcmp(argv[arg], "--md5") == 0) {
      md5_s     md5;
      char      sum[33];

      fasta = new seqCache(argv[++arg]);

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) {
        seqInCore *S = fasta->getSequenceInCore(s);
        fprintf(stdout, "%s %s\n",
                md5_toascii(md5_string(&md5, S->sequence(), S->sequenceLength()), sum),
                S->header());
        delete S;
      }
      delete fasta;
      exit(0);

    } else if ((strcmp(argv[arg], "--partition") == 0) ||
               (strcmp(argv[arg], "--partitionmap") == 0)) {

      char *prefix = 0L;
      if (strcmp(argv[arg], "--partition") == 0)
        prefix = argv[++arg];

      //  does the next arg end with gbp, mbp, kbp or bp?  If so,
      //  partition by length, else partition into buckets.
      //
      int     al = strlen(argv[arg+1]);
      uint64  ps = strtouint64(argv[arg+1]);

      char a3 = (al<3) ? '0' : alphabet.toLower(argv[arg+1][al-3]);
      char a2 = (al<2) ? '0' : alphabet.toLower(argv[arg+1][al-2]);
      char a1 = (al<1) ? '0' : alphabet.toLower(argv[arg+1][al-1]);

      //  partition!

      if (!isdigit(a1) || !isdigit(a2) || !isdigit(a3)) {
        if        ((a3 == 'g') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000000000;
        } else if ((a3 == 'm') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000000;
        } else if ((a3 == 'k') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000;
        } else if (isdigit(a3) && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1;
        } else {
          fprintf(stderr, "Unknown partition size option '%s'\n", argv[arg+1]), exit(1);
        }

        if (ps == 0)
          fprintf(stderr, "Unknown or zero partition size '%s'\n", argv[arg+1]), exit(1);
        partitionBySize(prefix, ps, argv[arg+2]);
      } else {
        if (ps == 0)
          fprintf(stderr, "Unknown or zero partition size '%s'\n", argv[arg+1]), exit(1);
        partitionByBucket(prefix, ps, argv[arg+2]);
      }
      exit(0);

    } else if (strcmp(argv[arg], "--segment") == 0) {
      partitionBySegment(argv[arg+1], strtouint32(argv[arg+2]), argv[arg+3]);
      exit(0);

    } else if (strcmp(argv[arg], "--gccontent") == 0) {
      computeGCcontent(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--dumpblocks") == 0) {
      dumpBlocks(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--stats") == 0) {
      stats(argv[arg+1], (argv[arg+2] != 0L) ? strtouint64(argv[arg+2]) : 0);
      exit(0);

    } else if (strcmp(argv[arg], "--errors") == 0) {
      int    L = strtouint32(argv[++arg]);     //  Desired length
      int    l = 0;                            //  min of desired length, length of sequence
      int    N = strtouint32(argv[++arg]);     //  number of copies per sequence
      int    C = strtouint32(argv[++arg]);     //  number of mutations per copy
      double P = atof(argv[++arg]);            //  probability of mutation
      uint32 i = 0;

      fasta = new seqCache(argv[++arg]);

      seqInCore *S = fasta->getSequenceInCore(i++);
      while (S) {
        char   *seq = S->sequence();
        char   *hdr = S->header();
        int     len = S->sequenceLength();

        l = len;
        if ((L > 0) && (L < len))
          l = L;

        simseq(seq, hdr, len, N, l, C, P);

        delete S;
        S = fasta->getSequenceInCore(i++);
      }
      delete fasta;
      exit(0);

    } else if (strcmp(argv[arg], "--seqstore") == 0) {
      constructSeqStore(argv[++arg], fasta);
      exit(0);

    } else if (strcmp(argv[arg], "-help") == 0) {
      if      ((argv[arg+1]) && (strcmp(argv[arg+1], "analysis") == 0))
        helpAnalysis(argv[0]);
      else if ((argv[arg+1]) && (strcmp(argv[arg+1], "examples") == 0))
        helpExamples(argv[0]);
      else
        helpStandard(argv[0]);
      exit(0);

    } else {
      helpStandard(argv[0]);
      fprintf(stderr, "Unknown option '%s'\n", argv[arg]);
      exit(1);
    }

    arg++;
  }

  delete fasta;
  fasta = 0L;
}
Esempio n. 12
0
int
main(int argc, char **argv) {
  char     *outputName  = 0L;
  uint32    outputIndex = 0;
  uint32    inputsLen   = 0;
  char     *inputs[8192];
  uint64    memoryLimit = 1024 * 1024 * 1024;

  int arg=1;
  int err=0;
  while (arg < argc) {
    if        (strncmp(argv[arg], "-memory", 2) == 0) {
      memoryLimit = strtouint64(argv[++arg], 0L) * 1024 * 1024;

    } else if (strncmp(argv[arg], "-output", 2) == 0) {
      outputName = argv[++arg];

    } else {
      if (tapperResultFile::validResultFile(argv[arg]) == false) {
        fprintf(stderr, "Didn't find tapperResultFile '%s'\n", argv[arg]);
        err++;
      } else {
        inputs[inputsLen++] = argv[arg];
      }
    }

    arg++;
  }
  if ((err) || (inputsLen == 0) || (outputName == 0L)) {
    fprintf(stderr, "usage: %s [-memory X (MB)] -output prefix input ....\n", argv[0]);
    exit(1);
  }


  {
    uint32              aliMax = memoryLimit / sizeof(tapperAlignment);
    uint32              aliLen = 0;
    tapperAlignment    *ali    = new tapperAlignment [aliMax];

    fprintf(stderr, "Can fit "uint32FMT" alignments into "uint64FMT" bytes memory; "uint32FMT" bytes each.\n",
            aliMax, memoryLimit, (uint32)sizeof(tapperAlignment));

    speedCounter        S(" %10.0f results (%8.0f results/sec)\r", 1, 100000, true);

    for (uint32 inputsIdx=0; inputsIdx<inputsLen; inputsIdx++) {
      tapperResultFile   *inp = new tapperResultFile(inputs[inputsIdx], 'r');
      tapperResult       *res = new tapperResult;

      while (inp->read(res)) {

        //  Sort and dump if the next result has too many alignments.
        //
        if (aliMax < aliLen + (res->idx._numFrag +
                               res->idx._numFragSingleton +
                               res->idx._numFragTangled +
                               res->idx._numMated * 2)) {
          aliLen = sortAndDump(ali, aliLen, outputName, outputIndex);
        }

        aliLen = saveFrag(ali, aliLen, res, res->idx._numFrag,          res->frag);
        aliLen = saveFrag(ali, aliLen, res, res->idx._numFragSingleton, res->sing);
        aliLen = saveFrag(ali, aliLen, res, res->idx._numFragTangled,   res->tali);
        aliLen = saveMate(ali, aliLen, res);

        S.tick();
      }
      S.finish();

      delete inp;
      delete res;
    }

    aliLen = sortAndDump(ali, aliLen, outputName, outputIndex);

    delete [] ali;
  }

  //
  //  Now the merge.
  //

  {
    char                filename[FILENAME_MAX];

    tapperAlignment    *ali = new tapperAlignment   [outputIndex];
    recordFile        **inp = new recordFile      * [outputIndex];
    recordFile         *out = 0L;

    bool                stillMore = true;
    uint32              minidx = 0;

    tapperAlignmentPositionCompare lessthan;

    for (uint32 x=0; x<outputIndex; x++) {
      sprintf(filename, "%s."uint32FMTW(03)".tapperAlignment", outputName, x);
      inp[x] = new recordFile(filename, 0, sizeof(tapperAlignment), 'r');

      inp[x]->getRecord(ali + x);
    }

    sprintf(filename, "%s.tapperAlignment", outputName);
    out = new recordFile(filename, 0, sizeof(tapperAlignment), 'w');


    while (stillMore) {

      //  Compare all against the current default minidx, pick the
      //  smallest alignment currently loaded.
      for (uint32 x=0; x<outputIndex; x++)
        if ((x != minidx) && (inp[x] != 0L) && (lessthan(ali[x], ali[minidx])))
          minidx = x;

      //  Dump it.
      out->putRecord(ali + minidx);

      //  Read the next record.  If no next record, close the file,
      //  and pick a new default minidx
      if (inp[minidx]->getRecord(ali + minidx) == 0) {
        delete inp[minidx];
        inp[minidx] = 0L;

        stillMore = false;

        for (uint32 x=0; x<outputIndex; x++)
          if (inp[x] != 0L) {
            minidx    = x;
            stillMore = true;
          }
      }
    }

    delete    out;

    for (uint32 x=0; x<outputIndex; x++) {
      assert(inp[x] == 0L);

      sprintf(filename, "%s."uint32FMTW(03)".tapperAlignment", outputName, x);
      unlink(filename);
    }

    delete [] inp;
    delete [] ali;
  }

  exit(0);
}
Esempio n. 13
0
int
_pmi_stuff_value(pmi_context *current, pmi_handle *hp, const char *value)
{
    pmResult	*rp;
    int		i;
    pmID	pmid;
    pmValueSet	*vsp;
    pmValue	*vp;
    pmi_metric	*mp;
    char	*end;
    int		dsize;
    void	*data;
    __int64_t	ll;
    __uint64_t	ull;
    float	f;
    double	d;

    mp = &current->metric[hp->midx];

    if (current->result == NULL) {
	/* first time */
	current->result = (pmResult *)malloc(sizeof(pmResult));
	if (current->result == NULL) {
	    __pmNoMem("_pmi_stuff_value: result malloc:", sizeof(pmResult), PM_FATAL_ERR);
	}
	current->result->numpmid = 0;
	current->result->timestamp.tv_sec = 0;
	current->result->timestamp.tv_usec = 0;
    }
    rp = current->result;

    pmid = current->metric[hp->midx].pmid;
    for (i = 0; i < rp->numpmid; i++) {
	if (pmid == rp->vset[i]->pmid) {
	    if (mp->desc.indom == PM_INDOM_NULL)
		/* singular metric, cannot have more than one value */
		return PMI_ERR_DUPVALUE;
	    break;
	}
    }
    if (i == rp->numpmid) {
	rp->numpmid++;
	rp = current->result = (pmResult *)realloc(current->result, sizeof(pmResult) + (rp->numpmid - 1)*sizeof(pmValueSet *));
	if (current->result == NULL) {
	    __pmNoMem("_pmi_stuff_value: result realloc:", sizeof(pmResult) + (rp->numpmid - 1)*sizeof(pmValueSet *), PM_FATAL_ERR);
	}
	rp->vset[rp->numpmid-1] = (pmValueSet *)malloc(sizeof(pmValueSet));
	if (rp->vset[rp->numpmid-1] == NULL) {
	    __pmNoMem("_pmi_stuff_value: vset alloc:", sizeof(pmValueSet), PM_FATAL_ERR);
	}
	vsp = rp->vset[rp->numpmid-1];
	vsp->pmid = pmid;
	vsp->numval = 1;
    }
    else {
	int		j;
	for (j = 0; j < rp->vset[i]->numval; j++) {
	    if (rp->vset[i]->vlist[j].inst == hp->inst)
		/* each metric-instance can appear at most once per pmResult */
		return PMI_ERR_DUPVALUE;
	}
	rp->vset[i]->numval++;
	vsp = rp->vset[i] = (pmValueSet *)realloc(rp->vset[i], sizeof(pmValueSet) + (rp->vset[i]->numval-1)*sizeof(pmValue));
	if (rp->vset[i] == NULL) {
	    __pmNoMem("_pmi_stuff_value: vset realloc:", sizeof(pmValueSet) + (rp->vset[i]->numval-1)*sizeof(pmValue), PM_FATAL_ERR);
	}
    }
    vp = &vsp->vlist[vsp->numval-1];
    vp->inst = hp->inst;
    dsize = -1;
    switch (mp->desc.type) {
	case PM_TYPE_32:
	    if (vsp->numval == 1) vsp->valfmt = PM_VAL_INSITU;
	    vp->value.lval = (__int32_t)strtol(value, &end, 10);
	    if (*end != '\0') {
		vsp->numval = PM_ERR_CONV;
		return PM_ERR_CONV;
	    }
	    break;

	case PM_TYPE_U32:
	    if (vsp->numval == 1) vsp->valfmt = PM_VAL_INSITU;
	    vp->value.lval = (__uint32_t)strtoul(value, &end, 10);
	    if (*end != '\0') {
		vsp->numval = PM_ERR_CONV;
		return PM_ERR_CONV;
	    }
	    break;

	case PM_TYPE_64:
	    if (vsp->numval == 1) vsp->valfmt = PM_VAL_DPTR;
	    ll = strtoint64(value, &end, 10);
	    if (*end != '\0') {
		vsp->numval = PM_ERR_CONV;
		return PM_ERR_CONV;
	    }
	    dsize = sizeof(ll);
	    data = (void *)&ll;
	    break;

	case PM_TYPE_U64:
	    if (vsp->numval == 1) vsp->valfmt = PM_VAL_DPTR;
	    ull = strtouint64(value, &end, 10);
	    if (*end != '\0') {
		vsp->numval = PM_ERR_CONV;
		return PM_ERR_CONV;
	    }
	    dsize = sizeof(ull);
	    data = (void *)&ull;
	    break;

	case PM_TYPE_FLOAT:
	    if (vsp->numval == 1) vsp->valfmt = PM_VAL_DPTR;
	    f = strtof(value, &end);
	    if (*end != '\0') {
		vsp->numval = PM_ERR_CONV;
		return PM_ERR_CONV;
	    }
	    dsize = sizeof(f);
	    data = (void *)&f;
	    break;

	case PM_TYPE_DOUBLE:
	    if (vsp->numval == 1) vsp->valfmt = PM_VAL_DPTR;
	    d = strtod(value, &end);
	    if (*end != '\0') {
		vsp->numval = PM_ERR_CONV;
		return PM_ERR_CONV;
	    }
	    dsize = sizeof(d);
	    data = (void *)&d;
	    break;

	case PM_TYPE_STRING:
	    if (vsp->numval == 1) vsp->valfmt = PM_VAL_DPTR;
	    dsize = strlen(value)+1;
	    data = (void *)value;
	    break;

	default:
	    vsp->numval = PM_ERR_TYPE;
	    return PM_ERR_TYPE;
    }

    if (dsize != -1) {
	/* logic copied from stuffvalue.c in libpcp */
	int	need = dsize + PM_VAL_HDR_SIZE;

	vp->value.pval = (pmValueBlock *)malloc(need < sizeof(pmValueBlock) ? sizeof(pmValueBlock) : need);
	if (vp->value.pval == NULL) {
	    __pmNoMem("_pmi_stuff_value: pmValueBlock:", need < sizeof(pmValueBlock) ? sizeof(pmValueBlock) : need, PM_FATAL_ERR);
	}
	vp->value.pval->vlen = (int)need;
	vp->value.pval->vtype = mp->desc.type;
	memcpy((void *)vp->value.pval->vbuf, data, dsize);
    }

    return 0;
}
Esempio n. 14
0
/**
 * @brief Verifies and translates allocation association config string into
 *        internal configuration.
 *
 * @param str string passed to -a command line option
 */
static void
parse_allocation_assoc(char *str)
{
        uint64_t cores[PQOS_MAX_CORES];
        unsigned i = 0, n = 0, cos = 0;
        char *p = NULL;

        if (strncasecmp(str, "llc:", 4) != 0)
                parse_error(str, "Unrecognized allocation type");

        str += strlen("llc:");
        p = strchr(str, '=');
        if (p == NULL)
                parse_error(str,
                            "Invalid allocation class of service "
                            "association format");
        *p = '\0';

        cos = (unsigned) strtouint64(str);

        n = strlisttotab(p+1, cores, DIM(cores));
        if (n == 0)
                return;

        if (sel_cat_assoc_num <= 0) {
                for (i = 0; i < n; i++) {
                        if (i >= DIM(sel_cat_assoc_tab))
                                parse_error(str,
                                            "too many cores selected for "
                                            "allocation association");
                        sel_cat_assoc_tab[i].core = (unsigned) cores[i];
                        sel_cat_assoc_tab[i].class_id = cos;
                }
                sel_cat_assoc_num = (int) n;
                return;
        }

        for (i = 0; i < n; i++) {
                int j;

                for (j = 0; j < sel_cat_assoc_num; j++)
                        if (sel_cat_assoc_tab[j].core == (unsigned) cores[i])
                                break;

                if (j < sel_cat_assoc_num) {
                        /**
                         * this core is already on the list
                         * - update COS but warn about it
                         */
                        printf("warn: updating COS for core %u from %u to %u\n",
                               (unsigned) cores[i],
                               sel_cat_assoc_tab[j].class_id, cos);
                        sel_cat_assoc_tab[j].class_id = cos;
                } else {
                        /**
                         * New core is selected - extend the list
                         */
                        unsigned k = (unsigned) sel_cat_assoc_num;

                        if (k >= DIM(sel_cat_assoc_tab))
                                parse_error(str,
                                            "too many cores selected for "
                                            "allocation association");

                        sel_cat_assoc_tab[k].core = (unsigned) cores[i];
                        sel_cat_assoc_tab[k].class_id = cos;
                        sel_cat_assoc_num++;
                }
        }
}
Esempio n. 15
0
int
main(int argc, char **argv) {
  uint64  genomeSize         = 0;
  char   *atacFileName       = 0L;
  char   *prefix             = 0L;
  char   *trFile1  = 0L;
  char   *trFile2  = 0L;
  char    prefixFull[1024];
  bool    error              = false;

  int arg=1;
  while (arg < argc) {
    if (strcmp(argv[arg], "-g") == 0) {
      ++arg;
      if        (argv[arg][0] == 'A') {
        genomeSize = 0;
      } else if (argv[arg][0] == 'B') {
        genomeSize = 1;
      } else {
        genomeSize = strtouint64(argv[arg], 0L);
      }
    } else if (strcmp(argv[arg], "-a") == 0) {
      atacFileName = argv[++arg];
    } else if (strcmp(argv[arg], "-p") == 0) {
      prefix = argv[++arg];
    } else if (strcmp(argv[arg], "-ta") == 0) {
      trFile1 = argv[++arg];
    } else if (strcmp(argv[arg], "-tb") == 0) {
      trFile2 = argv[++arg];
    } else {
      error = true;
    }
    arg++;
  }

  if (!atacFileName || !prefix || error) {
    fprintf(stderr, "usage: %s -a <file.atac> -p <outprefix> [-ta trfile] [-tb trfile] [-g {A | B | g}]\n", argv[0]);
    fprintf(stderr, "  -a          read input from 'file.atac'\n");
    fprintf(stderr, "  -p          write stats to files prefixed with 'outprefix'\n");
    fprintf(stderr, "  -g          use a genome size of g for the Nx computation, defaults to\n");
    fprintf(stderr, "              the length of the A sequence.  Or use the actual length\n");
    fprintf(stderr, "              of sequence A or B.\n");
    fprintf(stderr, "  -ta         read tandem repeats for A from trfile\n");
    fprintf(stderr, "  -tb         read tandem repeats for B from trfile\n");
    exit(1);
  }
  
  atacFile           AF(atacFileName);
  atacMatchList     &matches = *AF.matches();
  atacMatchList     &runs    = *AF.runs();
  atacMatchList     &clumps  = *AF.clumps();

  //  We end up using sequences a lot here, so just bite it and load them in a cache.
  //
  seqCache  *A = new seqCache(AF.assemblyFileA(), 0, true);
  seqCache  *B = new seqCache(AF.assemblyFileB(), 0, true);

  A->loadAllSequences();
  B->loadAllSequences();

  fprintf(stdout, "\nSEQUENCE\n");
  totalLength(AF, A, B);

  if (trFile1 && trFile2) {
    atacFileStream     tr1(trFile1);
    atacFileStream     tr2(trFile2);
    tandemRepeatStats(tr1, tr2, AF, A, B);
  }

  //  XXX unmappedInRuns only works on runs, and if we have clumps in
  //  the input it fails.
  //
  if ((runs.numberOfMatches() > 0) && (clumps.numberOfMatches() == 0)) {
    fprintf(stdout, "\nMATCHES IN RUNS\n");
    unmappedInRuns(AF, A, B, prefix);
  }

  if (matches.numberOfMatches() > 0) {
    fprintf(stdout, "\nMATCHES\n");
    sprintf(prefixFull, "%s-matches", prefix);
    mappedLengths(AF, matches, A, B, prefixFull);
    NxOfMapped(AF, matches, genomeSize, prefixFull);
    MappedByChromosome(AF, matches, A, B, prefixFull);
  }

  if (runs.numberOfMatches() > 0) {
    fprintf(stdout, "\nRUNS\n");
    sprintf(prefixFull, "%s-runs", prefix);
    mappedLengths(AF, runs, A, B, prefixFull);
    NxOfMapped(AF, runs, genomeSize, prefixFull);
    MappedByChromosome(AF, runs, A, B, prefixFull);
  }

  if (clumps.numberOfMatches() > 0) {
    fprintf(stdout, "\nCLUMPS\n");
    sprintf(prefixFull, "%s-clumps", prefix);
    mappedLengths(AF, clumps, A, B, prefixFull);
    NxOfMapped(AF, clumps, genomeSize, prefixFull);
    MappedByChromosome(AF, clumps, A, B, prefixFull);
  }

  delete A;
  delete B;

  return(0);
}