コード例 #1
0
ファイル: erl_msacc.c プロジェクト: hawk/otp
/*
 * Creates a structure looking like this
 * #{ type => scheduler, id => 1, counters => #{ State1 => Counter1 ... StateN => CounterN}}
 */
static
Eterm erts_msacc_gather_stats(ErtsMsAcc *msacc, ErtsHeapFactory *factory) {
    Uint sz = 0;
    Eterm *hp, cvs[ERTS_MSACC_STATE_COUNT];
    Eterm key, state_map;
    int i;
    flatmap_t *map; 

    hp = erts_produce_heap(factory, 4, 0);
    key = TUPLE3(hp,am_counters,am_id,am_type);

    for (i = 0; i < ERTS_MSACC_STATE_COUNT; i++) {
        cvs[i] = erts_bld_sint64(NULL, &sz,(Sint64)msacc->counters[i].pc);
#ifdef ERTS_MSACC_STATE_COUNTERS
        erts_bld_uint64(NULL,&sz,msacc->counters[i].sc);
        sz += 3;
#endif
    }

    hp = erts_produce_heap(factory, sz, 0);

    for (i = 0; i < ERTS_MSACC_STATE_COUNT; i++) {
        cvs[i] = erts_bld_sint64(&hp,NULL,(Sint64)msacc->counters[i].pc);
#ifdef ERTS_MSACC_STATE_COUNTERS
        Eterm counter__ = erts_bld_uint64(&hp,NULL,msacc->counters[i].sc);
        cvs[i] = TUPLE2(hp,cvs[i],counter__);
        hp += 3;
#endif
    }

    state_map = erts_map_from_ks_and_vs(factory, erts_msacc_state_atoms, cvs,
                                        ERTS_MSACC_STATE_COUNT);

    hp = erts_produce_heap(factory, MAP_HEADER_FLATMAP_SZ + 3, 0);
    map = (flatmap_t*)hp;
    hp += MAP_HEADER_FLATMAP_SZ;
    map->thing_word = MAP_HEADER_FLATMAP;
    map->size = 3;
    map->keys = key;
    hp[0] = state_map;
    hp[1] = msacc->id;
    hp[2] = am_atom_put(msacc->type,strlen(msacc->type));

    return make_flatmap(map);
}
コード例 #2
0
ファイル: erl_msacc.c プロジェクト: 3112517927/otp
/*
 * Creates a structure looking like this
 * #{ type => scheduler, id => 1, counters => #{ State1 => Counter1 ... StateN => CounterN}}
 */
static
Eterm erts_msacc_gather_stats(ErtsMsAcc *msacc, Eterm **hpp, Uint *szp) {
    int i;
    Eterm *hp;
    Eterm key, state_key, state_map;
    Eterm res = THE_NON_VALUE;
    flatmap_t *map;

    if (szp) {
      *szp += MAP_HEADER_FLATMAP_SZ + 1 + 2*(3);
      *szp += MAP_HEADER_FLATMAP_SZ + 1 + 2*(ERTS_MSACC_STATE_COUNT);
      for (i = 0; i < ERTS_MSACC_STATE_COUNT; i++) {
          (void)erts_bld_sint64(NULL,szp,(Sint64)msacc->perf_counters[i]);
#ifdef ERTS_MSACC_STATE_COUNTERS
          (void)erts_bld_uint64(NULL,szp,msacc->state_counters[i]);
          *szp += 3; /* tuple to put state+perf counter in */
#endif
      }
    }

    if (hpp) {
        Eterm counters[ERTS_MSACC_STATE_COUNT];
        hp = *hpp;
        for (i = 0; i < ERTS_MSACC_STATE_COUNT; i++) {
            Eterm counter = erts_bld_sint64(&hp,NULL,(Sint64)msacc->perf_counters[i]);
#ifdef ERTS_MSACC_STATE_COUNTERS
            Eterm counter__ = erts_bld_uint64(&hp,NULL,msacc->state_counters[i]);
            counters[i] = TUPLE2(hp,counter,counter__);
            hp += 3;
#else
            counters[i] = counter;
#endif
        }

      key = TUPLE3(hp,am_counters,am_id,am_type);
      hp += 4;

      state_key = make_tuple(hp);
      hp[0] = make_arityval(ERTS_MSACC_STATE_COUNT);
      
      for (i = 0; i < ERTS_MSACC_STATE_COUNT; i++)
        hp[1+i] = erts_msacc_state_atoms[i];
      hp += 1 + ERTS_MSACC_STATE_COUNT;

      map = (flatmap_t*)hp;
      hp += MAP_HEADER_FLATMAP_SZ;
      map->thing_word = MAP_HEADER_FLATMAP;
      map->size = ERTS_MSACC_STATE_COUNT;
      map->keys = state_key;
      for (i = 0; i < ERTS_MSACC_STATE_COUNT; i++)
            hp[i] = counters[i];
      hp += ERTS_MSACC_STATE_COUNT;
      state_map = make_flatmap(map);

      map = (flatmap_t*)hp;
      hp += MAP_HEADER_FLATMAP_SZ;
      map->thing_word = MAP_HEADER_FLATMAP;
      map->size = 3;
      map->keys = key;
      hp[0] = state_map;
      hp[1] = msacc->id;
      hp[2] = am_atom_put(msacc->type,strlen(msacc->type));
      hp += 3;

      *hpp = hp;
      res = make_flatmap(map);
    }

    return res;
}