1    /*
     2     * Copyright (c) 2012, Texas Instruments Incorporated
     3     * All rights reserved.
     4     *
     5     * Redistribution and use in source and binary forms, with or without
     6     * modification, are permitted provided that the following conditions
     7     * are met:
     8     *
     9     * *  Redistributions of source code must retain the above copyright
    10     *    notice, this list of conditions and the following disclaimer.
    11     *
    12     * *  Redistributions in binary form must reproduce the above copyright
    13     *    notice, this list of conditions and the following disclaimer in the
    14     *    documentation and/or other materials provided with the distribution.
    15     *
    16     * *  Neither the name of Texas Instruments Incorporated nor the names of
    17     *    its contributors may be used to endorse or promote products derived
    18     *    from this software without specific prior written permission.
    19     *
    20     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    22     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    23     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    27     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    28     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    29     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    30     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31     * */
    32    
    33    /*
    34     * ======== UIAUserCtx.xdc ========
    35     */
    36    
    37    import xdc.runtime.Types;
    38    import xdc.runtime.Diags;
    39    import ti.uia.events.IUIACtx;
    40    
    41    /*!
    42     * UIA User Context Instrumentation
    43     *
    44     * The UIAUserCtx module provides context change events
    45     * and methods that allow tooling to identify user-defined
    46     * context switches and to enable context-aware filtering,
    47     * trace and analysis.
    48     *
    49     * It inherits IUIACtx, which defines a function pointer to
    50     * an isLoggingEnabled function which, if configured to point to
    51     * a function, will evaluate the function prior to logging the context
    52     * change event and will store the return value of the function in
    53     * ti_uia_runtime_CtxFilter_gIsLoggingEnabled, which is used to
    54     * determine whether or not to log events.
    55     *
    56     *  The generation of UIAUserCtx events is also controlled by a module's diagnostics
    57     *  mask, which is described in details in `{@link xdc.runtime.Diags}`.
    58     * `UIAUserCtx` events are generated only when the Diags.ANALYSIS bit is set
    59     *  in the module's diagnostics mask.
    60     *
    61     *  The following configuration script demonstrates how the application might
    62     *  control the logging of ANALYSIS events embedded in the `Mod` module at configuration
    63     *  time. In this case, the configuration script arranges for the `Log`
    64     *  statements within modules to always generate ANALYSIS events.
    65     *  Without these configuration statements, no ANALYSIS events would be generated
    66     *  by any modules.
    67     *
    68     * @a(Examples)
    69     * Example 1: This is part of the XDC configuration file for the application:
    70     *
    71     *  @p(code)
    72     *  var LogCtxChg = xdc.useModule('ti.uia.runtime.LogCtxChg');
    73     *  var Diags = xdc.useModule('xdc.runtime.Diags');
    74     *  var LoggerSys = xdc.useModule('xdc.runtime.LoggerSys');
    75     *  var Defaults = xdc.useModule('xdc.runtime.Defaults');
    76     *  var logger = LoggerSys.create();
    77     *
    78     *  Defaults.common$.diags_ANALYSIS = Diags.ALWAYS_ON;
    79     *  Defaults.common$.logger = logger;
    80     *  @p
    81     *
    82     *  @p(html)
    83     *  <hr />
    84     *  @p
    85     *
    86     *  Example 2: The following example configures a module to support logging
    87     *  of ANALYSIS events, but defers the actual activation and deactivation of the
    88     *  logging until runtime. See the `{@link Diags#setMask Diags_setMask()}`
    89     *  function for details on specifying the control string.
    90     *
    91     *  This is a part of the XDC configuration file for the application:
    92     *
    93     *  @p(code)
    94     *  var LogCtxChg = xdc.useModule('ti.uia.runtime.LogCtxChg');
    95     *  var Diags = xdc.useModule('xdc.runtime.Diags');
    96     *  var Mod = xdc.useModule('my.pkg.Mod');
    97     *
    98     *  Mod.common$.diags_ANALYSIS = Diags.RUNTIME_OFF;
    99     *  @p
   100     *
   101     *  This is a part of the C code for the application:
   102     *
   103     *  @p(code)
   104     *  // turn on logging of ANALYSIS events in the module
   105     *  Diags_setMask("my.pkg.Mod+Z");
   106     *
   107     *  // turn off logging of ANALYSIS events in the module
   108     *  Diags_setMask("my.pkg.Mod-Z");
   109     *  @p
   110     */
   111    
   112    @CustomHeader
   113    module UIAUserCtx inherits IUIACtx {
   114    
   115        /*!
   116         *  ======== ctxChg ========
   117         *  User-defined Context Change event
   118         *
   119         *  Used to log the start of new state in the user-defined context
   120         *
   121         *  Note that this event should not be referenced directly by user code - it is used
   122         *  internally by the LogCtxChg_user function, which logs the previous user context Id automatically.
   123         *
   124         *  @a(Example)
   125         *   The following C code shows how to log a Context Change
   126         *   event that identifies a new user-specified context ID
   127         *
   128         *  @p(code)
   129         *  #include <ti/uia/runtime/LogCtxChg.h>
   130         *  ...
   131         *  LogCtxChg_user("New user context=0x%x",newUserContextId);
   132         *  ...
   133         *
   134         *  @p
   135         *  This event prints the Log call site (%$F) and a format string (%$S)
   136         *  which is recursively formatted with any addition arguments.
   137         *  The following text is an example of what will be displayed for the event:
   138         *  @p(code)
   139         *  "User Ctx Change at Line 123 in appLoader.c [Prev. ctx = 0x1234] New user context=0x1235"
   140         *
   141         *  @param(fmt)   a constant string that describes the context change and provides a format specifier for newAppId
   142         *  @param(newUserContextId)   an integer which uniquely identifies the new user context
   143         */
   144        config xdc.runtime.Log.Event ctxChg = {
   145            mask: Diags.ANALYSIS,
   146            msg: "User Ctx Change at %$F [Prev. ctx = 0x%x] %$S"};
   147    
   148        /*!
   149         *  ======== metaEventUserCtxChg ========
   150         *  Metadata description of the User Context Change event
   151         *
   152         *  @_nodoc
   153         */
   154        metaonly config DvtTypes.MetaEventDescriptor metaEventUserCtxChg = {
   155            versionId: "2.0",
   156            analysisType: DvtTypes.DvtAnalysisType_CONTEXTCHANGE,
   157            displayText: "User Ctx Change",
   158            tooltipText: "User Context Change",
   159            numParameters: 5,
   160            paramInfo: [
   161            {   name: '__FILE__',
   162                dataDesc: DvtTypes.DvtDataDesc_FILENAMESTR,
   163                dataTypeName: 'String',
   164                units: 'none',
   165                isHidden: false
   166            },
   167            {   name: '__LINE__',
   168                dataDesc: DvtTypes.DvtDataDesc_LINENUM,
   169                dataTypeName: 'Int',
   170                units: 'none',
   171                isHidden: false
   172            },
   173            {   name: 'Prev. User Context',
   174                dataDesc: DvtTypes.DvtDataDesc_STATEID,
   175                dataTypeName: 'Int',
   176                units: 'none',
   177                isHidden: false
   178            },
   179            {   name: 'fmt',
   180                dataDesc: DvtTypes.DvtDataDesc_FMTSTR,
   181                dataTypeName: 'String',
   182                units: 'none',
   183                isHidden: false
   184            },
   185            {   name: 'New User Context',
   186                dataDesc: DvtTypes.DvtDataDesc_STATEID,
   187                dataTypeName: 'Int',
   188                units: 'none',
   189                isHidden: false
   190            }]
   191    
   192        };
   193        /*!
   194         * ======== getCtxId ========
   195         * Get the ID for the current user-defined context
   196         *
   197         *  @a(returns)
   198         *  returns the context ID logged by the last call to UIAUserCtx_logCtxChg.
   199         */
   200        @Macro Int getCtxId();
   201    
   202        /*!
   203         * ======== isLoggingEnabled ========
   204         * returns true if the new context matches the value to enable logging with.
   205         *
   206         *  Default implementation of the IUIACtx_IsLoggingEnabledFxn for user context.
   207         *  To enable context-aware filtering, assign UIAUserCtx_isLoggingEnabledFxn = &UIAUserCtx_isLoggingEnabled
   208         *  in the config script or programmatically, or assign your own implementation of this
   209         *  function.
   210         *  @param(newUserCtx) the new user context
   211         *  @a(returns) true if logging is enabled
   212         */
   213         @DirectCall
   214         Bool isLoggingEnabled(UInt newUserCtx);
   215    
   216        /*!
   217         * ======== setOldValue =========
   218         * sets ti_uia_events_UIAUserCtx_gLastValue to the new value and returns the old value before it was updated.
   219         *
   220         * @param(newValue) the new value to save in the global variable
   221         * @a(return)       the original value of the global variable before it was updated.
   222         */
   223         @DirectCall
   224         UInt setOldValue(UInt newValue);
   225    }