1    /* 
     2     * Copyright (c) 2010, 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     *  ======== TraceUtil ========
    35     *  TraceUtil Configuration interface
    36     */
    37    @Template("./TraceUtil.xdt")
    38    
    39    metaonly module TraceUtil {
    40    
    41        /*!
    42         *  ======== PipeCmdAlias ========
    43         *  Alias' to use for the cmd pipe.
    44         */
    45        struct PipeCmdAlias {
    46            String alias;           /*! alias for a group of pipe commands */
    47            String cmds[];          /*! list of pipe commands for this alias */
    48        };
    49    
    50        /*!
    51         *  ======== Attrs ========
    52         *  Configuration attributes
    53         *
    54         *  This structure describes the initialization settings for the
    55         *  TraceUtil module; see TraceUtil.attrs.
    56         *
    57         *  @field(localTraceMask)  The trace mask to be used on the "local",
    58         *                          or application processor.
    59         *
    60         *  @field(localTraceFile)  The name of the file into which trace output
    61         *                          will be generated.  This can be a full path
    62         *                          (e.g. `/tmp/local.txt`), or a path relative
    63         *                          to the executing application.
    64         *
    65         *  @field(dsp0TraceMask)   The trace mask to be used on the "remote"
    66         *                          server.
    67         *
    68         *  @field(dsp0TraceFile)   The name of the file into which trace output
    69         *                          will be generated.  This can be a full path
    70         *                          (e.g. `/tmp/dsp0.txt`), or a path relative
    71         *                          to the executing application.
    72         *
    73         *  @field(dsp0BiosFile)    The name of the file into which DSP/BIOS log
    74         *                          output will be generated.  This can be a
    75         *                          full path (e.g. `/tmp/dspbios.dat`), or a
    76         *                          path relative to the executing application.
    77         *
    78         *  @field(traceFileFlags)  fopen flags used when opening the various
    79         *                          trace/log files.  See fopen() documentation
    80         *                          for details.  For example, to open the files
    81         *                          in "append" mode (i.e. add to existing file
    82         *                          content), use "a"; to open in "over-write"
    83         *                          mode, use "w".
    84         *
    85         *  @field(refreshPeriod)   The number of milliseconds to sleep before
    86         *                          reading the content off the remote servers.
    87         *                          This will vary based on the amount of trace
    88         *                          generated, and the size of the trace logs.
    89         *                          Failure to set this low enough will result
    90         *                          in data loss.
    91         */
    92        struct Attrs {
    93             String   localTraceMask;   /*! local tracing mask */
    94             String   localTraceFile;   /*! local tracing file */
    95             String   dsp0TraceMask;    /*! server's tracing mask */
    96             String   dsp0TraceFile;    /*! server's tracing file */
    97             String   dsp0BiosFile;     /*! server's BIOS tracing file */
    98             String   traceFileFlags;   /*! flags for fopen()ing trace files */
    99             Int      refreshPeriod;    /*! number of ms before two DSP data gets */
   100             String   cmdPipeFile;      /*! named pipe to read commands from */
   101             PipeCmdAlias cmdAliases[]; /*! any aliases for the pipe commands */
   102        };
   103    
   104        /* various pre-packaged tracing profiles (Configs) */
   105    
   106        /*!
   107         *  ======== NO_TRACING ========
   108         *  No tracing or logging of any kind
   109         */
   110        const Attrs NO_TRACING = {
   111            localTraceMask:    "*=",
   112            localTraceFile:    null,
   113            dsp0TraceMask:     "*=",
   114            dsp0TraceFile:     null,
   115            dsp0BiosFile:      null,
   116            traceFileFlags:    null,
   117            refreshPeriod:     0,
   118            cmdPipeFile:       "/tmp/cecmdpipe",
   119            cmdAliases: [ ],
   120        };
   121    
   122        /*!
   123         *  ======== DEFAULT_TRACING ========
   124         *  Tracing that prints warnings and errors on the standard output
   125         */
   126        const Attrs DEFAULT_TRACING = {
   127            localTraceMask:    "*=67",
   128            localTraceFile:    null,
   129            dsp0TraceMask:     "*=67",
   130            dsp0TraceFile:     null,
   131            dsp0BiosFile:      null,
   132            traceFileFlags:    null,
   133            refreshPeriod:     300,
   134            cmdPipeFile:       "/tmp/cecmdpipe",
   135            cmdAliases: [ ],
   136        };
   137    
   138        /*!
   139         *  ======== SOCRATES_TRACING ========
   140         *  Tracing appropriate for the SoC Analyzer data collection tool.
   141         *
   142         *  The default settings here place data files into the `/tmp` directory.
   143         *  `/tmp` typically provides faster write access than other file
   144         *  system files, so it is used to lower the overhead of tracing.
   145         *
   146         *  Using these default settings, the GPP and DSP generate approximately
   147         *  400 characters of trace in *each* the localTraceFile and
   148         *  dsp0TraceFile, for each round trip to/from the DSP.  This includes the
   149         *  typical `process()` and `control()` calls to each codec.
   150         *
   151         *  Using that figure, the user is encouraged to configure the
   152         *  refreshPeriod and System trace buffers appropriately, so as to reduce
   153         *  the likelyhood of data loss due to wrapping.
   154         *
   155         *  For example, consider an application which utilizes a 30
   156         *  frame-per-second video codec in parallel with a 50 frame-per-second
   157         *  audio codec.  Additionally, the audio codec requires calling `process()`
   158         *  *and* `control()` for each frame - the video only requires a single
   159         *  process() call.  This application alone will generate approximately
   160         *  ((50 * 2) + 30) * 400 = 52000 bytes of trace data each second.  If the
   161         *  default System trace buffer size is used (32768 bytes), the application
   162         *  needs to ensure the refresh period is less than 650 milliseconds
   163         *  *not including I/O overhead or potential for pre-emption*.
   164         */
   165        const Attrs SOCRATES_TRACING = {
   166            localTraceMask:    "*=67",
   167            localTraceFile:    "/tmp/cearmlog.txt",
   168            dsp0TraceMask:     "*=67",
   169            dsp0TraceFile:     "/tmp/cedsp0log.txt",
   170            dsp0BiosFile:      "/tmp/bioslog.dat",
   171    
   172            /* Open the file for writing.  Note, this over-writes existing files. */
   173            traceFileFlags:    "w",
   174    
   175            refreshPeriod:     0,
   176            cmdPipeFile:       "/tmp/cecmdpipe",
   177            cmdAliases: [
   178                {
   179                    alias: "socrates=on",
   180                    cmds:  [
   181                           "tracemask=*+5",
   182                           "dsp0tracemask=*+5,ti.bios+3",
   183                           "refreshperiod=200",
   184                    ],
   185                },
   186                {
   187                    alias: "socrates=off",
   188                    cmds:  [
   189                           "tracemask=*-5",
   190                           "refreshperiod=0",
   191                           "dsp0tracemask=*-5,ti.bios-3"
   192                    ],
   193                },
   194            ],
   195        };
   196    
   197        /*!
   198         *  ======== FULL_TRACING ========
   199         *  Enable all tracing.
   200         */
   201        const Attrs FULL_TRACING = {
   202            localTraceMask:    "*=01234567",
   203            localTraceFile:    "trace/cearmlog.txt",
   204            dsp0TraceMask:     "*=01234567,ti.bios=01324567",
   205            dsp0TraceFile:     "trace/cedsp0log.txt",
   206            dsp0BiosFile:      "trace/bioslog.dat",
   207            traceFileFlags:    "w",
   208            refreshPeriod:     100,
   209            cmdPipeFile:       "/tmp/cecmdpipe",
   210            cmdAliases: [ ],
   211        };
   212    
   213        /*!
   214         *  ======== attrs ========
   215         *  Tracing configuration; by default set to some very basic tracing
   216         */
   217        config Attrs attrs = DEFAULT_TRACING;
   218    }
   219    /*
   220     *  @(#) ti.sdo.ce.utils.trace; 1, 0, 1,307; 12-2-2010 21:28:05; /db/atree/library/trees/ce/ce-r11x/src/ xlibrary
   221    
   222     */
   223