예제 #1
0
Boolean_T stat_olympic(Stat_T *ptr)
{
      if (ptr->count < 3)
            return Error_;
      stat_delete(ptr->min1, ptr);
      stat_delete(ptr->max1, ptr);
      return Success_;
}
예제 #2
0
// update or insert stat values
int
NdbIndexStat::stat_update(const Uint32* key1, Uint32 keylen1, const Uint32* key2, Uint32 keylen2, const float pct[2])
{
    const Uint32* const key[2] = { key1, key2 };
    const Uint32 keylen[2] = { keylen1, keylen2 };
    Uint32 idir;
    for (idir = 0; idir <= 1; idir++) {
        Area& a = m_area[idir];
        Uint32 k;
        bool match;
        stat_search(a, key[idir], keylen[idir], &k, &match);
        Uint16 seq = m_seq++;
        if (match) {
            // update old entry
            NdbIndexStat::Pointer& p = a.get_pointer(k);
            NdbIndexStat::Entry& e = a.get_entry(k);
            e.m_pct = pct[idir];
            p.m_seq = seq;
        } else {
            Uint32 entrylen = NdbIndexStat::EntrySize + keylen[idir];
            Uint32 need = NdbIndexStat::PointerSize + entrylen;
            while (need > a.m_free) {
                Uint32 j = stat_oldest(a);
                if (j < k)
                    k--;
                stat_delete(a, j);
            }
            // insert pointer
            Uint32 i;
            for (i = a.m_entries; i > k; i--) {
                NdbIndexStat::Pointer& p1 = a.get_pointer(i);
                NdbIndexStat::Pointer& p2 = a.get_pointer(i - 1);
                p1 = p2;
            }
            NdbIndexStat::Pointer& p = a.get_pointer(k);
            // insert entry
            Uint32 firstpos = a.get_firstpos();
            p.m_pos = firstpos - entrylen;
            NdbIndexStat::Entry& e = a.get_entry(k);
            e.m_pct = pct[idir];
            e.m_keylen = keylen[idir];
            Uint32* entrykey = (Uint32*)&e + EntrySize;
            for (i = 0; i < keylen[idir]; i++) {
                entrykey[i] = key[idir][i];
            }
            p.m_seq = seq;
            // total
            a.m_free -= PointerSize + entrylen;
            a.m_entries++;
        }
    }
    stat_verify();
    return 0;
}
예제 #3
0
파일: stats.c 프로젝트: kirtgoh/emics
void
main(void)
{
  struct stat_sdb_t *sdb;
  struct stat_stat_t *stat, *stat1, *stat2, *stat3, *stat4, *stat5;
  int an_int;
  unsigned int a_uint;
  float a_float;
  double a_double;
  static char *my_imap[8] = {
    "foo", "bar", "uxxe", "blah", "gaga", "dada", "mama", "googoo"
  };

  /* make stats database */
  sdb = stat_new();

  /* register stat variables */
  stat_reg_int(sdb, "stat.an_int", "An integer stat variable.",
	       &an_int, 1, NULL);
  stat_reg_uint(sdb, "stat.a_uint", "An unsigned integer stat variable.",
		&a_uint, 2, "%u (unsigned)");
  stat_reg_float(sdb, "stat.a_float", "A float stat variable.",
		 &a_float, 3, NULL);
  stat_reg_double(sdb, "stat.a_double", "A double stat variable.",
		  &a_double, 4, NULL);
  stat_reg_formula(sdb, "stat.a_formula", "A double stat formula.",
		   "stat.a_float / stat.a_uint", NULL);
  stat_reg_formula(sdb, "stat.a_formula1", "A double stat formula #1.",
		   "2 * (stat.a_formula / (1.5 * stat.an_int))", NULL);
  stat_reg_formula(sdb, "stat.a_bad_formula", "A double stat formula w/error.",
		   "stat.a_float / (stat.a_uint - 2)", NULL);
  stat = stat_reg_dist(sdb, "stat.a_dist", "An array distribution.",
		       0, 8, 1, PF_ALL, NULL, NULL, NULL);
  stat1 = stat_reg_dist(sdb, "stat.a_dist1", "An array distribution #1.",
			0, 8, 4, PF_ALL, NULL, NULL, NULL);
  stat2 = stat_reg_dist(sdb, "stat.a_dist2", "An array distribution #2.",
			0, 8, 1, (PF_PDF|PF_CDF), NULL, NULL, NULL);
  stat3 = stat_reg_dist(sdb, "stat.a_dist3", "An array distribution #3.",
			0, 8, 1, PF_ALL, NULL, my_imap, NULL);
  stat4 = stat_reg_sdist(sdb, "stat.a_sdist", "A sparse array distribution.",
			 0, PF_ALL, NULL, NULL);
  stat5 = stat_reg_sdist(sdb, "stat.a_sdist1",
			 "A sparse array distribution #1.",
			 0, PF_ALL, "0x%08lx        %10lu %6.2f %6.2f",
			 NULL);

  /* print initial stats */
  fprintf(stdout, "** Initial stats...\n");
  stat_print_stats(sdb, stdout);

  /* adjust stats */
  an_int++;
  a_uint++;
  a_float *= 2;
  a_double *= 4;

  stat_add_sample(stat, 8);
  stat_add_sample(stat, 8);
  stat_add_sample(stat, 1);
  stat_add_sample(stat, 3);
  stat_add_sample(stat, 4);
  stat_add_sample(stat, 4);
  stat_add_sample(stat, 7);

  stat_add_sample(stat1, 32);
  stat_add_sample(stat1, 32);
  stat_add_sample(stat1, 1);
  stat_add_sample(stat1, 12);
  stat_add_sample(stat1, 17);
  stat_add_sample(stat1, 18);
  stat_add_sample(stat1, 30);

  stat_add_sample(stat2, 8);
  stat_add_sample(stat2, 8);
  stat_add_sample(stat2, 1);
  stat_add_sample(stat2, 3);
  stat_add_sample(stat2, 4);
  stat_add_sample(stat2, 4);
  stat_add_sample(stat2, 7);

  stat_add_sample(stat3, 8);
  stat_add_sample(stat3, 8);
  stat_add_sample(stat3, 1);
  stat_add_sample(stat3, 3);
  stat_add_sample(stat3, 4);
  stat_add_sample(stat3, 4);
  stat_add_sample(stat3, 7);

  stat_add_sample(stat4, 800);
  stat_add_sample(stat4, 800);
  stat_add_sample(stat4, 1123);
  stat_add_sample(stat4, 3332);
  stat_add_sample(stat4, 4000);
  stat_add_samples(stat4, 4001, 18);
  stat_add_sample(stat4, 7);

  stat_add_sample(stat5, 800);
  stat_add_sample(stat5, 800);
  stat_add_sample(stat5, 1123);
  stat_add_sample(stat5, 3332);
  stat_add_sample(stat5, 4000);
  stat_add_samples(stat5, 4001, 18);
  stat_add_sample(stat5, 7);

  /* print final stats */
  fprintf(stdout, "** Final stats...\n");
  stat_print_stats(sdb, stdout);

  /* all done */
  stat_delete(sdb);
  exit(0);
}