<commit_before>/*****************************************************************************\
 *                        ANALYSIS PERFORMANCE TOOLS                         *
 *                                  MPItrace                                 *
 *              Instrumentation package for parallel applications            *
 *****************************************************************************
 *     ___     This library is free software; you can redistribute it and/or *
 *    /  __         modify it under the terms of the GNU LGPL as published   *
 *   /  /  _____    by the Free Software Foundation; either version 2.1      *
 *  /  /  /     \   of the License, or (at your option) any later version.   *
 * (  (  ( B S C )                                                           *
 *  \  \  \_____/   This library is distributed in hope that it will be      *
 *   \  \__         useful but WITHOUT ANY WARRANTY; without even the        *
 *    \___          implied warranty of MERCHANTABILITY or FITNESS FOR A     *
 *                  PARTICULAR PURPOSE. See the GNU LGPL for more details.   *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public License  *
 * along with this library; if not, write to the Free Software Foundation,   *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA          *
 * The GNU LEsser General Public License is contained in the file COPYING.   *
 *                                 ---------                                 *
 *   Barcelona Supercomputing Center - Centro Nacional de Supercomputacion   *
\*****************************************************************************/

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *\
 | @file: $HeadURL$
 | @last_commit: $Date$
 | @version:     $Revision$
\* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
#include "common.h"

static char UNUSED rcsid[] = "$Id$";

#include "calltrace.h"
#include "record.h"
#include "trace_macros.h"
#include "wrapper.h"

/* -- El usuario ha desactivado el traceo de MPI callers? -------- */
int Trace_Caller_Enabled[COUNT_CALLER_TYPES] = { 1, 1 };

/* -- Que MPI callers se tracean? -------------------------------- */
int * Trace_Caller[COUNT_CALLER_TYPES] = { NULL, NULL }; 

/* -- Profundidad maxima que necesitamos de la pila de llamadas -- */
int Caller_Deepness[COUNT_CALLER_TYPES] = { 0, 0 };

/* -- Cuantos MPI callers traceamos? ----------------------------- */
int Caller_Count[COUNT_CALLER_TYPES] = { 0, 0 }; 


#if defined(OS_LINUX) || defined(OS_FREEBSD)
 #if defined(ARCH_IA64)
  /* En arquitecturas IA64 las rutinas de backtrace estan en la libunwind */
  extern int backtrace (void *, int);
 #else
  /* En arquitecturas IA32, se encuentran en la GLIBC y declaradas en <execinfo.h> */
  #ifdef HAVE_EXECINFO_H
  # include <execinfo.h>
  #endif
 #endif
#endif

/* LINUX IA32/PPC o BGL*/
#if (defined(OS_LINUX) && !defined(ARCH_IA64)) || defined(OS_FREEBSD) || defined(IS_BG_MACHINE)

void trace_callers (iotimer_t time, int offset, int type) {
   void * callstack[MAX_STACK_DEEPNESS];
   int i, size;
#ifdef MPICALLER_DEBUG
   char **strings; 
#endif

#if defined(OS_FREEBSD)
	callstack[0] = (void*) trace_callers;
	size = backtrace (&callstack[1], Caller_Deepness[type]+offset-1);
	size++;
#else
	size = backtrace (callstack, Caller_Deepness[type]+offset);
#endif

#ifdef MPICALLER_DEBUG
  /*
   * Para printar aqui el nombre de la funcion, compilar la aplicacion con -rdynamic
   */
   strings = backtrace_symbols (callstack, size);

   printf ("%zd llamadas en la pila.\n", size);
   for (i = 0; i < size; i++) {
      printf ("%s\n", strings[i]);
   }
#endif

	for (i=0; (i<Caller_Deepness[type] && (i+offset-1)<size); i++)
	{
		if (type == CALLER_MPI)
		{
			if (Trace_Caller[CALLER_MPI][i])
			{
				TRACE_EVENT(time, MPI_CALLER_EVENT_TYPE(i+1), (UINT64) callstack[i+offset-1]);
			}
		}
#if defined(SAMPLING_SUPPORT)
		else if (type == CALLER_SAMPLING)
		{
			if (Trace_Caller[CALLER_SAMPLING][i])
			{
				SAMPLE_EVENT_NOHWC(time, SAMPLING_EV+i+1, (UINT64) callstack[i+offset-1]);
			}
		}
#endif
	}	  
}

UINT64 get_caller (int offset)
{
	void * callstack[MAX_STACK_DEEPNESS];
	int size;
#if defined(DEBUG)
	int i;
#endif

#if defined(OS_FREEBSD)
	callstack[0] = (void*) get_caller;
	size = backtrace (&callstack[1], offset-1);
	size++;
#else
	size = backtrace (callstack, offset);
#endif

#if defined(DEBUG)
	for (i = 0; i < size; i++)
		fprintf (stderr, "DEBUG: depth %d address %p %c\n", i, callstack[i],(offset-1 == i)?'*':' ');
#endif

	return (UINT64) ((offset-1 >= size)?0:callstack[offset-1]);
}

#endif /* LINUX IA32 */

/* LINUX IA64 */
#if defined(OS_LINUX) && defined(ARCH_IA64)<commit_msg>Callpath is accessed through the unwind symbols in x86/64.<commit_after>/*****************************************************************************\
 *                        ANALYSIS PERFORMANCE TOOLS                         *
 *                                  MPItrace                                 *
 *              Instrumentation package for parallel applications            *
 *****************************************************************************
 *     ___     This library is free software; you can redistribute it and/or *
 *    /  __         modify it under the terms of the GNU LGPL as published   *
 *   /  /  _____    by the Free Software Foundation; either version 2.1      *
 *  /  /  /     \   of the License, or (at your option) any later version.   *
 * (  (  ( B S C )                                                           *
 *  \  \  \_____/   This library is distributed in hope that it will be      *
 *   \  \__         useful but WITHOUT ANY WARRANTY; without even the        *
 *    \___          implied warranty of MERCHANTABILITY or FITNESS FOR A     *
 *                  PARTICULAR PURPOSE. See the GNU LGPL for more details.   *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public License  *
 * along with this library; if not, write to the Free Software Foundation,   *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA          *
 * The GNU LEsser General Public License is contained in the file COPYING.   *
 *                                 ---------                                 *
 *   Barcelona Supercomputing Center - Centro Nacional de Supercomputacion   *
\*****************************************************************************/

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *\
 | @file: $HeadURL$
 | @last_commit: $Date$
 | @version:     $Revision$
\* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
#include "common.h"

static char UNUSED rcsid[] = "$Id$";

#include "calltrace.h"
#include "record.h"
#include "trace_macros.h"
#include "wrapper.h"

/* -- El usuario ha desactivado el traceo de MPI callers? -------- */
int Trace_Caller_Enabled[COUNT_CALLER_TYPES] = { 1, 1 };

/* -- Que MPI callers se tracean? -------------------------------- */
int * Trace_Caller[COUNT_CALLER_TYPES] = { NULL, NULL }; 

/* -- Profundidad maxima que necesitamos de la pila de llamadas -- */
int Caller_Deepness[COUNT_CALLER_TYPES] = { 0, 0 };

/* -- Cuantos MPI callers traceamos? ----------------------------- */
int Caller_Count[COUNT_CALLER_TYPES] = { 0, 0 }; 


#if defined(OS_LINUX) || defined(OS_FREEBSD)
 #if !defined(ARCH_IA64) && !defined(ARCH_IA32_x64)
  /* En arquitecturas IA32, se encuentran en la GLIBC y declaradas en <execinfo.h> */
  #ifdef HAVE_EXECINFO_H
  # include <execinfo.h>
  #endif
 #endif
#endif

/* LINUX IA32/PPC o BGL*/
#if (defined(OS_LINUX) && !defined(ARCH_IA64) && !defined(ARCH_IA32_x64)) || defined(OS_FREEBSD) || defined(IS_BG_MACHINE)

void trace_callers (iotimer_t time, int offset, int type) {
   void * callstack[MAX_STACK_DEEPNESS];
   int i, size;
#ifdef MPICALLER_DEBUG
   char **strings; 
#endif

#if defined(OS_FREEBSD)
	callstack[0] = (void*) trace_callers;
	size = backtrace (&callstack[1], Caller_Deepness[type]+offset-1);
	size++;
#else
	size = backtrace (callstack, Caller_Deepness[type]+offset);
#endif

#ifdef MPICALLER_DEBUG
  /*
   * Para printar aqui el nombre de la funcion, compilar la aplicacion con -rdynamic
   */
   strings = backtrace_symbols (callstack, size);

   printf ("%zd llamadas en la pila.\n", size);
   for (i = 0; i < size; i++) {
      printf ("%s\n", strings[i]);
   }
#endif

	for (i=0; (i<Caller_Deepness[type] && (i+offset-1)<size); i++)
	{
		if (type == CALLER_MPI)
		{
			if (Trace_Caller[CALLER_MPI][i])
			{
				TRACE_EVENT(time, MPI_CALLER_EVENT_TYPE(i+1), (UINT64) callstack[i+offset-1]);
			}
		}
#if defined(SAMPLING_SUPPORT)
		else if (type == CALLER_SAMPLING)
		{
			if (Trace_Caller[CALLER_SAMPLING][i])
			{
				SAMPLE_EVENT_NOHWC(time, SAMPLING_EV+i+1, (UINT64) callstack[i+offset-1]);
			}
		}
#endif
	}	  
}

UINT64 get_caller (int offset)
{
	void * callstack[MAX_STACK_DEEPNESS];
	int size;
#if defined(DEBUG)
	int i;
#endif

#if defined(OS_FREEBSD)
	callstack[0] = (void*) get_caller;
	size = backtrace (&callstack[1], offset-1);
	size++;
#else
	size = backtrace (callstack, offset);
#endif

#if defined(DEBUG)
	for (i = 0; i < size; i++)
		fprintf (stderr, "DEBUG: depth %d address %p %c\n", i, callstack[i],(offset-1 == i)?'*':' ');
#endif

	return (UINT64) ((offset-1 >= size)?0:callstack[offset-1]);
}

#endif /* LINUX IA32 */

/* LINUX IA64 */
#if defined(OS_LINUX) && (defined(ARCH_IA64) || defined(ARCH_IA32_x64))
{'fraction_non_alphanumeric': 0.2067079463364293, 'fraction_numerical': 0.014035087719298246, 'mean_word_length': 2.4219632768361583, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5593931', 'n_tokens_mistral': 3325, 'n_tokens_neox': 3061, 'n_words': 819}