Path: blob/master/runtime/include/rastrace_external.h
5986 views
/*******************************************************************************1* Copyright (c) 2014, 2019 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#ifndef RASTRACE_EXTERNAL_H23#define RASTRACE_EXTERNAL_H2425/* @ddr_namespace: default */26#include "ute_core.h"27#include "j9port.h"2829#ifdef __cplusplus30extern "C" {31#endif3233#define UT_THREAD_FROM_OMRVM_THREAD(thr) ((thr) ? &(thr)->_trace.uteThread : NULL)3435/*36* =============================================================================37* Language interface - embedded in UtGlobalData38*39* This interface supplies callback functions for language-specific behaviour.40* A callback may be NULL. We will NULL-check each function pointer before invoking it.41* =============================================================================42*/43typedef omr_error_t (*SetLanguageTraceOptionFunc)(const OMR_VM *omr_vm, const char *optName, const char* optValue, BOOLEAN atRuntime);44typedef void (*ReportCommandLineErrorFunc)(J9PortLibrary* portLibrary, const char* detailStr, va_list args);4546typedef struct OMRTraceLanguageInterface {47/**48* Attach the current thread to the language VM.49*50* The trace engine invokes this callback to attach internal threads to the VM.51* A sample implementation is omr_trc_defaultAttachCurrentThreadToLanguageVM().52* Attached threads will be detached using the DetachCurrentThreadFromLanguageVM() callback.53*54* @pre The current thread is completely unattached to the VM.55*56* @param[in] omrVM The OMR VM.57* @param[in] name The name of the current thread.58* @param[out] omrVMThread Location where a pointer to a new OMR VM thread should be stored. Must not be NULL.59*60* @return an OMR error code61*/62omr_error_t (*AttachCurrentThreadToLanguageVM)(OMR_VM *omrVM, const char *name, OMR_VMThread **omrVMThread);6364/**65* Detach the current thread from the language VM.66*67* The trace engine invokes this callback to detach internal threads to the VM.68* A sample implementation is omr_trc_defaultDetachThreadFromLanguageVM().69* The current thread should have been attached using the AttachCurrentThreadToLanguageVM() callback.70*71* @pre The current thread is attached to the VM.72*73* @param[in,out] omrVMThread The OMR VM thread.74* @return an OMR error code75*/76omr_error_t (*DetachCurrentThreadFromLanguageVM)(OMR_VMThread *omrVMThread);7778/**79* Pass unhandled trace options for implementer to handle.80*/81SetLanguageTraceOptionFunc SetLanguageTraceOption;8283/**84* Report errors with trace options to the implementer's error stream.85*/86ReportCommandLineErrorFunc ReportCommandLineError;87} OMRTraceLanguageInterface;8889/*90* =============================================================================91* Functions called by users of the trace library at initialisation/shutdown time.92* (Runtime functions are called vi UtInterface->UtServerInterface once initialized)93* =============================================================================94*/9596/**97* @brief Fill in the interfaces the runtime will use to access trace functions.98*99* Fill in the interfaces the runtime will use to access trace functions.100* This function fills in the function tables that an application can use to access101* the trace engine functions.102*103* UtServerInterface contains the functions the application can use to access and control104* the trace engine.105*106* UtModuleInterface contains the functions used by a module (library) to initialize107* it's trace setup and to take trace points. These functions are usually accessed via108* the macros generated from the TDF files.109*110* @param[in,out] utIntf Will be returned a pointer to a newly initialized UtInterface structure.111* @param[in,out] utServerIntf112* @param[in,out] utModuleIntf113*114* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.115*/116omr_error_t fillInUTInterfaces(UtInterface **utIntf, UtServerInterface *utServerIntf, UtModuleInterface *utModuleIntf);117118/**119* @brief Initialize the trace engine.120*121* Initialize the trace engine.122*123* The gbl pointer is intended to allow the trace global data structure124* to be linked to somewhere public so that it can be found by debugging125* tools, this allows them to do things like extract trace buffers from126* core files.127* It is not intended to give read/write access to the trace global data128* at runtime and is deliberately a void** for a structure that is not129* publicly defined.130*131* The opts field is used for the same purpose as the opts field in132* setOptions. See the documentation for that function for full details.133*134* The ignore field specifies options to ignore in the properties file.135*136* The function pointer types for the fields on OMRTraceLanguageInterface are137* documented with the function pointer definitions.138*139* @param[out] thr A UtThreadData pointer. *thr can point to NULL, initialize trace will initialize it.140* @param[in,out] gbl A pointer for the trace global data structure.141* @param[in] opts A NULL-terminated array of options to be passed to the trace engine.142* @param[in] vm The OMR_VM the trace engine will be running inside.143* @param[in] ignore Options to ignore in the properties file.144* @param[in] languageIntf A set of function pointers for accessing function in the OMR based runtime.145*146* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.147*/148omr_error_t initializeTrace(UtThreadData **thr, void **gbl,const char **opts, const OMR_VM *vm, const char **ignore, const OMRTraceLanguageInterface *languageIntf);149150/**151* @brief Inform the trace engine the application has reached a point that trace can start it's own threads.152*153* Inform the trace engine the application has reached a point that trace can start it's own threads.154* The trace engine may (depending on the options it has been passed) start it's own internal threads155* at this point.156*157* @param[in] thr UtThreadData for the current thread.158*159* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.160*/161omr_error_t startTraceWorkerThread(UtThreadData **thr);162163/**164* @brief Terminate the trace engine.165*166* Terminate the trace engine. This call will shut down the trace engine,167* waiting for all tracing threads to terminate and flush trace data to168* any subscribers.169*170* It will wait until all the threads not listed in daemonThreadNames have171* terminated or it's internal timeout has expired (1 second) before172* flushing the trace data to subscribers.173*174* @param[in] thr UtThreadData for the current thread.175* @param[in] daemonThreadNames A list of threads that should not be waited for before timing out.176*177* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.178*/179omr_error_t utTerminateTrace(UtThreadData **thr, char** daemonThreadNames);180181/**182* @brief Free the trace engines internal data structures.183*184* This must only be called after utTerminateTrace and will free any remaining185* memory held by the trace engine.186*187* After calling this no further calls may be made to the trace engine.188*189* @param[in] thr UtThreadData for the current thread.190*191*/192void freeTrace(UtThreadData **thr);193194/**195* @brief Notify trace that a new thread has started.196*197* Notify the trace engine that a new thread has started. Trace will198* allocate a new UtThreadData and store a pointer to it in the thr199* parameter.200*201* A thread *must not* attempt to take a trace point or invoke trace202* functions until this function has been called.203*204* Note that passing another threads UtThreadData when taking a205* trace point may work - but will lead to the event represented206* by that trace point appearing to have occurred on the other thread207* once the trace is formatted. This is extremely undesirable when208* using trace for problem determination.209*210* NOTE: Currently thrSynonym1 must be the omrthread_t for this thread and211* thrSynonym2 must be the OMR_VMThread.212*213* @param[out] thr The UtThreadData structure for this thread.214* @param[in] threadId The id of this thread. Must be unique. (The address of a per thread structure is recommended)215* @param[in] threadName A name for this thread. Will be displayed when trace data is formatted. May be NULL.216* @param[in] thrSynonym1 A synonym for this threads id to aid cross referencing in problem diagnosis.217* @param[in] thrSynonym2 A synonym for this threads id to aid cross referencing in problem diagnosis.218*219* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.220*/221omr_error_t threadStart(UtThreadData **thr, const void *threadId, const char *threadName, const void *thrSynonym1, const void *thrSynonym2);222223/**224* @brief Notify trace that a thread has stopped.225*226* Inform the trace engine that the thread represented by this227* UtThreadData has terminated and free it's allocated UtThreadData.228*229* @param[in,out] thr The UtThreadData structure for this thread.230*231* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.232*/233omr_error_t threadStop(UtThreadData **thr);234235/**236* @brief Set trace options237*238* Set trace options, options are supplied in an array of strings.239* For options that are key/value pairs (for example maximal=all)240* the key is passed in position n and the value in n+1:241* opts[n] = "maximal";242* opts[n+1] = "all";243* For simple flag options (for example nofatalassert) the flag is244* passed in opts[n] and opts[n+1] is null.245* opts[n] = "nofatalassert";246* opts[n+1] = NULL;247*248* The atRuntime flag is set to TRUE if trace startup is complete249* (startTraceWorkerThread has been called) and FALSE if it250* setOptions is called before that. Certain options may only be251* set during startup. If atRuntime is TRUE setOptions will not attempt252* to set those options.253*254* The SetOptions call available on UtServerInterface is identical but255* is only intended to be called once trace startup is complete and256* effectively is the same call with atRuntime set to TRUE.257*258* @param[in] thr The UtThreadData for the currently executing thread. Must not be NULL.259* @param[in] opts An array of options to be passed to the trace engine.260* @param[in] atRuntime A flag indicating whether trace startup is complete.261*262* @return The integer debug level the trace engine is using.263*/264omr_error_t setOptions(UtThreadData **thr, const char **opts, BOOLEAN atRuntime);265266/**267* @brief Set the information to be included in the trace file header.268*269* Set the information to be included in the trace file header. This is270* information which will be included in the header of all binary trace271* files generated by this application and formatted into the header272* information when that trace file is formatted.273*274* Typically serviceInfo is the unique version string for the application275* and startupInfo is the formatted command line.276*277* The strings are copied so may be freed.278*279* @param[in] serviceInfo The service level of the application.280* @param[in] startupInfo The startup information for the application.281*282* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.283*/284omr_error_t setTraceHeaderInfo(const char * serviceInfo, const char * startupInfo);285286/**287* @brief Obtain the debug level for the trace engine.288*289* Obtain the debug level for the trace engine. This is set by passing trace the290* option debug=N (where N is a positive integer).291*292* This function allows trace implementers to write statements of the form:293* if ( getDebugLevel > N ) {294* ReportCommandLineErrorFunc(....)295* }296* where ReportCommandLineErrorFunc is the same function (or the same underlying functionality)297* as passed to the trace engine in field OMRTraceLanguageInterface.ReportCommandLineError when trace298* was initialized. This allows trace implementers to integrate their own debugging messages299* with those from the trace engine without having to create a separate debugging mechanism.300*301* @return The integer debug level the trace engine is using.302*/303int32_t getDebugLevel(void);304305/**306* @brief Creates a trace point307*308* Creates a trace point to record a trace event for the specified thread (generally the309* currently running thread). The trace point is in the module described by modInfo and310* has it's trace id masked with it's activation information. (This is generated as part311* of the trace macros and should simply be passed through.)312*313* The spec parameter describes the arguments to the trace point (and is also generated)314* and those arguments (if any) are contained in the va_list.315*316* This function exists to allow users to override the default implementation of317* UtModuleInterface.Trace(void *env, UtModuleInfo *modInfo, uint32_t traceId, const char *spec, ...);318* and pass in the var args arguments (since the use of var args prevents simply calling319* the original UtModuleInterface.Trace function). This allows trace implementers to320* map from a per thread env parameter that is convenient for their application to a321* UtThreadData. All the other parameters should be left unchanged.322*323* @param[in] thr The UtThreadData for the currently executing thread. Must not be NULL.324* @param[in] modInfo A pointer to the UtModuleInfo for the module this trace point belongs to.325* @param[in] traceId The trace point id for this trace point.326* @param[in] spec The trace point format specification for this trace point327* @param[in] varArgs The va_list of parameters for this trace point.328*/329void doTracePoint(UtThreadData **thr, UtModuleInfo *modInfo, uint32_t traceId, const char *spec, va_list varArgs);330331/**332* @brief Walk the current trace configuration options.333*334* Returns each of the trace options that have been set and updates **cursor to335* track it's position. Passing *cursor = NULL begins a new walk.336*337* Cursor is updated during the walk and will be NULL when the end of the options338* is reached. The returned char* will also be NULL at the end of the walk.339*340* @param cursor A cursor to record the current walk position with.341*342* @return a pointer to an option string or NULL when there are no more options.343*/344const char* walkTraceConfig(void **cursor);345346/*347* =============================================================================348* Keywords for trace command line options.349* =============================================================================350*/351352#define UT_DEBUG_KEYWORD "DEBUG"353#define UT_FORMAT_KEYWORD "FORMAT"354#define UT_SUFFIX_KEYWORD "SUFFIX"355#define UT_LIBPATH_KEYWORD "LIBPATH"356#define UT_PROPERTIES_KEYWORD "PROPERTIES"357#define UT_BUFFERS_KEYWORD "BUFFERS"358#define UT_INIT_KEYWORD "INITIALIZATION"359#define UT_RESET_KEYWORD "RESETTABLE"360#define UT_MINIMAL_KEYWORD "MINIMAL"361#define UT_MAXIMAL_KEYWORD "MAXIMAL"362#define UT_COUNT_KEYWORD "COUNT"363#define UT_PRINT_KEYWORD "PRINT"364#define UT_IPRINT_KEYWORD "IPRINT"365#define UT_PLATFORM_KEYWORD "PLATFORM"366#define UT_EXTERNAL_KEYWORD "EXTERNAL"367#define UT_EXCEPTION_KEYWORD "EXCEPTION"368#define UT_EXCEPT_OUT_KEYWORD "EXCEPTION.OUTPUT"369#define UT_STATE_OUT_KEYWORD "STATE.OUTPUT"370#define UT_NONE_KEYWORD "NONE"371#define UT_OUTPUT_KEYWORD "OUTPUT"372#define UT_LEVEL_KEYWORD "LEVEL"373#define UT_TRIGGER_KEYWORD "TRIGGER"374#define UT_SUSPEND_KEYWORD "SUSPEND"375#define UT_RESUME_KEYWORD "RESUME"376#define UT_RESUME_COUNT_KEYWORD "RESUMECOUNT"377#define UT_SUSPEND_COUNT_KEYWORD "SUSPENDCOUNT"378#define UT_ALL "ALL"379#define UT_BACKTRACE "BACKTRACE"380#define UT_FATAL_ASSERT_KEYWORD "FATALASSERT"381#define UT_NO_FATAL_ASSERT_KEYWORD "NOFATALASSERT"382#define UT_SLEEPTIME_KEYWORD "SLEEPTIME"383384/*385* =============================================================================386* Types for trace trigger functionality.387* =============================================================================388*/389390/**391* When a trigger was fired - before or after a tracepoint392*/393typedef enum TriggerPhase {BEFORE_TRACEPOINT, AFTER_TRACEPOINT} TriggerPhase;394395typedef void (*TriggerActionFunc)(OMR_VMThread *thr); /* Function to call when performing a trigger action */396397typedef struct RasTriggerAction {398const char *name; /* String specified on the cmd-line to select this action */399TriggerPhase phase; /* When this trigger action should be fired */400TriggerActionFunc fn; /* Function to call when performing the action */401} RasTriggerAction;402403typedef omr_error_t (*ParseTriggerTypeFunc)(OMR_VMThread *thr, char *opt, BOOLEAN atRuntime); /* Function to parse the options of a trigger type */404405typedef struct RasTriggerType {406const char *name; /* String specified on the cmd-line to select this type */407ParseTriggerTypeFunc parse; /* Function to parse the options of this trigger type */408BOOLEAN runtimeModifiable; /* Whether this trigger type can be modified at runtime */409} RasTriggerType;410411/**412* @brief Add a type of trace trigger413*414* Add a type of trace trigger. This allows additional trace trigger types415* (the base types are "group" and "tpnid") to be added to the trace engine416*417* The application can define it's own logic for triggering these new types418* of triggers and they can call any of the available trigger actions.419*420* @param[in] thr The UtThreadData for the currently executing thread.421* @param[in] newType The new trigger type to add.422*423* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.424*/425omr_error_t addTriggerType(OMR_VMThread *thr, const struct RasTriggerType *newType);426427/**428* @brief Add a type of trace trigger action.429*430* Add a type of trace trigger. This allows additional trace trigger actions431* to be added to the trace engine These can be triggered by any trigger type.432*433* This allows the application to define additional actions or call backs that434* can occur when a trace point fires.435*436* @param[in] thr The UtThreadData for the currently executing thread.437* @param[in] newAction The new trigger action to add.438*439* @return OMR_ERROR_NONE if successful, an error code describing the failure otherwise.440*/441omr_error_t addTriggerAction(OMR_VMThread *thr, const struct RasTriggerAction *newAction);442443/**444* Convert the name of a trigger action into its entry in the rasTriggerActions array.445*446* @param thr447* @param name A trigger name string.448*449* @return Trigger action or NULL450*/451const struct RasTriggerAction *parseTriggerAction(OMR_VMThread *thr, const char *name, BOOLEAN atRuntime);452453#ifdef __cplusplus454}455#endif456457#endif /* !RASTRACE_EXTERNAL_H */458459460