Ejemplo n.º 1
0
static
EventSet* eventset_from_mask(UInt mask)
{
    EventSet* es;
    Int i, count, offset;

    if (mask >= MAX_EVENTSET_COUNT) return 0;

    initialize_event_sets();
    if (eventSetTable[mask]) return eventSetTable[mask];

    es = (EventSet*) CLG_MALLOC("cl.events.eventset.1", sizeof(EventSet));
    es->mask = mask;

    offset = 0;
    count = 0;
    for(i=0;i<MAX_EVENTGROUP_COUNT;i++) {
	es->offset[i] = offset;
	if ( ((mask & (1u<<i))==0) || (eventGroup[i]==0))
	    continue;

	offset += eventGroup[i]->size;
	count++;
    }
    es->size = offset;
    es->count = count;

    eventSetTable[mask] = es;
    return es;
}
Ejemplo n.º 2
0
ULong* CLG_(get_costarray)(Int size)
{
  ULong* ptr;

  if (!cost_chunk_current ||
      (cost_chunk_current->size - cost_chunk_current->used < size)) {
    CostChunk* cc  = (CostChunk*) CLG_MALLOC(sizeof(CostChunk) +
					      COSTCHUNK_SIZE * sizeof(ULong));
    cc->size = COSTCHUNK_SIZE;
    cc->used = 0;
    cc->next = 0;

    if (cost_chunk_current)
      cost_chunk_current->next = cc;
    cost_chunk_current = cc;

    if (!cost_chunk_base) cost_chunk_base = cc;

    CLG_(costarray_chunks)++;
  }
  
  ptr = &(cost_chunk_current->data[cost_chunk_current->used]);
  cost_chunk_current->used += size;

  CLG_(costarray_entries) += size;

  return ptr;
}
Ejemplo n.º 3
0
void CLG_(init_bb_hash)()
{
   Int i;

   bbs.size    = 8437;
   bbs.entries = 0;
   bbs.table = (BB**) CLG_MALLOC(bbs.size * sizeof(BB*));

   for (i = 0; i < bbs.size; i++) bbs.table[i] = NULL;
}
Ejemplo n.º 4
0
void CLG_(init_bbcc_hash)(bbcc_hash* bbccs)
{
   Int i;

   CLG_ASSERT(bbccs != 0);

   bbccs->size    = N_BBCC_INITIAL_ENTRIES;
   bbccs->entries = 0;
   bbccs->table = (BBCC**) CLG_MALLOC(bbccs->size * sizeof(BBCC*));

   for (i = 0; i < bbccs->size; i++) bbccs->table[i] = NULL;
}
Ejemplo n.º 5
0
/* double size of hash table 1 (addr->BBCC) */
static void resize_bbcc_hash(void)
{
    Int i, new_size, conflicts1 = 0, conflicts2 = 0;
    BBCC** new_table;
    UInt new_idx;
    BBCC *curr_BBCC, *next_BBCC;

    new_size = 2*current_bbccs.size+3;
    new_table = (BBCC**) CLG_MALLOC("cl.bbcc.rbh.1",
                                    new_size * sizeof(BBCC*));
 
    if (!new_table) return;
 
    for (i = 0; i < new_size; i++)
      new_table[i] = NULL;
 
    for (i = 0; i < current_bbccs.size; i++) {
	if (current_bbccs.table[i] == NULL) continue;
 
	curr_BBCC = current_bbccs.table[i];
	while (NULL != curr_BBCC) {
	    next_BBCC = curr_BBCC->next;

	    new_idx = bbcc_hash_idx(curr_BBCC->bb,
				    curr_BBCC->cxt,
				    new_size);

	    curr_BBCC->next = new_table[new_idx];
	    new_table[new_idx] = curr_BBCC;
	    if (curr_BBCC->next) {
		conflicts1++;
		if (curr_BBCC->next->next)
		    conflicts2++;
	    }

	    curr_BBCC = next_BBCC;
	}
    }

    VG_(free)(current_bbccs.table);


    CLG_DEBUG(0,"Resize BBCC Hash: %d => %d (entries %d, conflicts %d/%d)\n",
	     current_bbccs.size, new_size,
	     current_bbccs.entries, conflicts1, conflicts2);

    current_bbccs.size = new_size;
    current_bbccs.table = new_table;
    CLG_(stat).bbcc_hash_resizes++;
}
Ejemplo n.º 6
0
static
EventGroup* new_event_group(int id, int n)
{
    EventGroup* eg;

    initialize_event_sets();

    CLG_ASSERT(id>=0 && id<MAX_EVENTGROUP_COUNT);
    CLG_ASSERT(eventGroup[id]==0);

    eg = (EventGroup*) CLG_MALLOC("cl.events.group.1",
				  sizeof(EventGroup) + n * sizeof(Char*));
    eg->size = n;
    eventGroup[id] = eg;
    return eg;
}
Ejemplo n.º 7
0
/* Allocate space for an event mapping */
EventMapping* CLG_(get_eventmapping)(EventSet* es)
{
    EventMapping* em;

    CLG_ASSERT(es != 0);

    em = (EventMapping*) CLG_MALLOC("cl.events.geMapping.1",
				    sizeof(EventMapping) +
				    sizeof(struct EventMappingEntry) *
				    es->size);
    em->capacity = es->size;
    em->size = 0;
    em->es = es;

    return em;
}
Ejemplo n.º 8
0
/* double size of bb table  */
static
void resize_bb_table(void)
{
    Int i, new_size, conflicts1 = 0, conflicts2 = 0;
    BB **new_table, *curr, *next;
    UInt new_idx;

    new_size  = 2* bbs.size +3;
    new_table = (BB**) CLG_MALLOC(new_size * sizeof(BB*));
 
    if (!new_table) return;
 
    for (i = 0; i < new_size; i++)
      new_table[i] = NULL;
 
    for (i = 0; i < bbs.size; i++) {
	if (bbs.table[i] == NULL) continue;
 
	curr = bbs.table[i];
	while (NULL != curr) {
	    next = curr->next;

	    new_idx = bb_hash_idx(curr->obj, curr->offset, new_size);

	    curr->next = new_table[new_idx];
	    new_table[new_idx] = curr;
	    if (curr->next) {
		conflicts1++;
		if (curr->next->next)
		    conflicts2++;
	    }

	    curr = next;
	}
    }

    VG_(free)(bbs.table);


    CLG_DEBUG(0, "Resize BB Hash: %d => %d (entries %d, conflicts %d/%d)\n",
	     bbs.size, new_size,
	     bbs.entries, conflicts1, conflicts2);

    bbs.size  = new_size;
    bbs.table = new_table;
    CLG_(stat).bb_hash_resizes++;
}
Ejemplo n.º 9
0
/**
 * Setup for interactive control of a callgrind run
 */
static void setup_control(void)
{
  Int fd, size;
  SysRes res;
  Char* dir;

  CLG_ASSERT(thisPID != 0);

  fd = -1;
  dir = CLG_(get_out_directory)();
  out_file = CLG_(get_out_file)();

  /* name of command file */
  size = VG_(strlen)(dir) + VG_(strlen)(DEFAULT_COMMANDNAME) +10;
  command_file = (char*) CLG_MALLOC(size);
  CLG_ASSERT(command_file != 0);
  VG_(sprintf)(command_file, "%s/%s.%d",
	       dir, DEFAULT_COMMANDNAME, thisPID);

  /* This is for compatibility with the "Force Now" Button of current
   * KCachegrind releases, as it doesn't use ".pid" to distinguish
   * different callgrind instances from same base directory.
   */
  command_file2 = (char*) CLG_MALLOC(size);
  CLG_ASSERT(command_file2 != 0);
  VG_(sprintf)(command_file2, "%s/%s",
	       dir, DEFAULT_COMMANDNAME);

  size = VG_(strlen)(dir) + VG_(strlen)(DEFAULT_RESULTNAME) +10;
  result_file = (char*) CLG_MALLOC(size);
  CLG_ASSERT(result_file != 0);
  VG_(sprintf)(result_file, "%s/%s.%d",
	       dir, DEFAULT_RESULTNAME, thisPID);

  /* If we get a command from a command file without .pid, use
   * a result file without .pid suffix
   */
  result_file2 = (char*) CLG_MALLOC(size);
  CLG_ASSERT(result_file2 != 0);
  VG_(sprintf)(result_file2, "%s/%s",
               dir, DEFAULT_RESULTNAME);

  info_file = (char*) CLG_MALLOC(VG_(strlen)(DEFAULT_INFONAME) + 10);
  CLG_ASSERT(info_file != 0);
  VG_(sprintf)(info_file, "%s.%d", DEFAULT_INFONAME, thisPID);

  CLG_DEBUG(1, "Setup for interactive control (PID: %d):\n", thisPID);
  CLG_DEBUG(1, "  output file:    '%s'\n", out_file);
  CLG_DEBUG(1, "  command file:   '%s'\n", command_file);
  CLG_DEBUG(1, "  result file:    '%s'\n", result_file);
  CLG_DEBUG(1, "  info file:      '%s'\n", info_file);

  /* create info file to indicate that we are running */ 
  res = VG_(open)(info_file, VKI_O_WRONLY|VKI_O_TRUNC, 0);
  if (res.isError) { 
    res = VG_(open)(info_file, VKI_O_CREAT|VKI_O_WRONLY,
		   VKI_S_IRUSR|VKI_S_IWUSR);
    if (res.isError) {
      VG_(message)(Vg_DebugMsg, 
		   "warning: can't write info file '%s'", info_file);
      info_file = 0;
      fd = -1;
    }
  }
  if (!res.isError)
      fd = (Int) res.res;
  if (fd>=0) {
    Char buf[512];
    Int i;

    WRITE_STR3(fd,
	       "# This file is generated by Callgrind-" VERSION ".\n"
	       "# It is used to enable controlling the supervision of\n"
	       "#  '", VG_(args_the_exename), "'\n"
	       "# by external tools.\n\n");
    
    VG_(sprintf)(buf, "version: " COMMAND_VERSION "\n");
    VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
    
    WRITE_STR3(fd, "base: ", dir, "\n");
    WRITE_STR3(fd, "dumps: ", out_file, "\n");
    WRITE_STR3(fd, "control: ", command_file, "\n");
    WRITE_STR3(fd, "result: ", result_file, "\n");

    WRITE_STR2(fd, "cmd: ", VG_(args_the_exename));    
    for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
        HChar* arg = * (HChar**)VG_(indexXA)( VG_(args_for_client), i );
	if (!arg) continue;
	WRITE_STR2(fd, " ", arg);
    }
    VG_(write)(fd, "\n", 1);
    VG_(close)(fd);
  }
}