1 <?xml version="1.0" encoding="utf-8"?>
   2 <!--
   3  Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   4  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 
   6  This code is free software; you can redistribute it and/or modify it
   7  under the terms of the GNU General Public License version 2 only, as
   8  published by the Free Software Foundation.
   9 
  10  This code is distributed in the hope that it will be useful, but WITHOUT
  11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  version 2 for more details (a copy is included in the LICENSE file that
  14  accompanied this code).
  15 
  16  You should have received a copy of the GNU General Public License version
  17  2 along with this work; if not, write to the Free Software Foundation,
  18  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19 
  20  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  or visit www.oracle.com if you need additional information or have any
  22  questions.
  23 -->
  24 
  25 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  26 <xsl:import href="xsl_util.xsl"/>
  27 <xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
  28 
  29 <xsl:template match="/">
  30   <xsl:call-template name="file-header"/>
  31 
  32 #ifndef TRACEFILES_TRACEEVENTCLASSES_HPP
  33 #define TRACEFILES_TRACEEVENTCLASSES_HPP
  34 
  35 // On purpose outside the INCLUDE_TRACE
  36 // Some parts of traceEvent.hpp are used outside of
  37 // INCLUDE_TRACE
  38 
  39 #include "tracefiles/traceTypes.hpp"
  40 #include "utilities/macros.hpp"
  41 
  42 #if INCLUDE_TRACE
  43 #include "trace/traceEvent.hpp"
  44 #include "trace/traceStream.hpp"
  45 #include "utilities/ostream.hpp"
  46 
  47   <xsl:apply-templates select="trace/events/struct" mode="trace"/>
  48   <xsl:apply-templates select="trace/events/event" mode="trace"/>
  49 
  50 #else // !INCLUDE_TRACE
  51 
  52 class TraceEvent {
  53 public:
  54   TraceEvent() {}
  55   void set_starttime(const Ticks&amp; ignore) {}
  56   void set_endtime(const Ticks&amp; ignore) {}
  57   bool should_commit() const { return false; }
  58   static bool is_enabled() { return false; }
  59   void commit() {}
  60 };
  61 
  62   <xsl:apply-templates select="trace/events/struct" mode="empty"/>
  63   <xsl:apply-templates select="trace/events/event" mode="empty"/>
  64 
  65 #endif // INCLUDE_TRACE
  66 #endif // TRACEFILES_TRACEEVENTCLASSES_HPP
  67 </xsl:template>
  68 
  69 <xsl:template match="struct" mode="trace">
  70 struct TraceStruct<xsl:value-of select="@id"/>
  71 {
  72 private:
  73 <xsl:apply-templates select="value" mode="write-fields"/>
  74 public:
  75 <xsl:apply-templates select="value" mode="write-setters"/>
  76 
  77   void writeStruct(TraceStream&amp; ts) {
  78 <xsl:apply-templates select="value" mode="write-data"/>
  79   }
  80 };
  81 
  82 </xsl:template>
  83 
  84 <xsl:template match="struct" mode="empty">
  85 struct TraceStruct<xsl:value-of select="@id"/> 
  86 {
  87 public:
  88 <xsl:apply-templates select="value" mode="write-empty-setters"/>
  89 };
  90 </xsl:template>
  91 
  92 
  93 <xsl:template match="event" mode="empty">
  94   <xsl:value-of select="concat('class Event', @id, ' : public TraceEvent')"/>
  95 {
  96  public:
  97 <xsl:value-of select="concat('  Event', @id, '(bool ignore=true) {}')"/>
  98 <xsl:text>
  99 </xsl:text>
 100 
 101 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-empty-setters"/>
 102 };
 103 
 104 </xsl:template>
 105 
 106 
 107 <xsl:template match="event" mode="trace">
 108   <xsl:value-of select="concat('class Event', @id, ' : public TraceEvent&lt;Event', @id, '&gt;')"/>
 109 {
 110  public:
 111   static const bool hasThread = <xsl:value-of select="@has_thread"/>;
 112   static const bool hasStackTrace = <xsl:value-of select="@has_stacktrace"/>;
 113   static const bool isInstant = <xsl:value-of select="@is_instant"/>;
 114   static const bool isRequestable = <xsl:value-of select="@is_requestable"/>;
 115   static const TraceEventId eventId = <xsl:value-of select="concat('Trace', @id, 'Event')"/>;
 116 
 117  private:
 118 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-fields"/>
 119 
 120   void writeEventContent(void) {
 121     TraceStream ts;
 122     ts.print("<xsl:value-of select="@label"/>: [");
 123 <xsl:apply-templates select="value|structvalue" mode="write-data"/>
 124     ts.print("]\n");
 125   }
 126 
 127  public:
 128 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-setters"/>
 129 
 130   bool should_write(void) {
 131     return true;
 132   }
 133 <xsl:text>
 134 
 135 </xsl:text>
 136   <xsl:value-of select="concat('  Event', @id, '(EventStartTime timing=TIMED) : TraceEvent&lt;Event', @id, '&gt;(timing) {}', $newline)"/>
 137   void writeEvent(void) {
 138     if (UseLockedTracing) {
 139       ttyLocker lock;
 140       writeEventContent();
 141     } else {
 142       writeEventContent();
 143     }
 144   }
 145 
 146   using <xsl:value-of select="concat('TraceEvent&lt;Event', @id, '&gt;')"/>::commit; // else commit() is hidden by overloaded versions in this class
 147 
 148 <xsl:variable name="instant" select="@is_instant"/>
 149 <!-- non static method (only for non instant events)-->
 150 <xsl:if test="$instant='false'">
 151   <xsl:value-of select="concat('  Event', @id)"/>(
 152     <xsl:for-each select="value|structvalue|transition_value|relation">
 153     <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/>
 154     <xsl:if test="position() != last()">,
 155     </xsl:if></xsl:for-each>) : TraceEvent&lt;<xsl:value-of select="concat('Event', @id)"/>&gt;(TIMED) {
 156     if (should_commit()) {<xsl:for-each select="value|structvalue|transition_value|relation">
 157       set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>);</xsl:for-each>
 158     }
 159   }
 160 
 161   void commit(<xsl:for-each select="value|structvalue|transition_value|relation">
 162     <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/>
 163     <xsl:if test="position() != last()">,
 164               </xsl:if></xsl:for-each>) {
 165     if (should_commit()) {
 166       <xsl:for-each select="value|structvalue|transition_value|relation">set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>);
 167       </xsl:for-each>commit();
 168     }
 169   }</xsl:if>
 170 <!-- static method (for all events) -->
 171   static void commit(<xsl:if test="$instant='false'">const Ticks&amp; startTicks,
 172                      const Ticks&amp; endTicks<xsl:choose><xsl:when test="value|structvalue|transition_value|relation">,
 173                      </xsl:when></xsl:choose></xsl:if>
 174                      <xsl:for-each select="value|structvalue|transition_value|relation">
 175     <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/>
 176     <xsl:if test="position() != last()">,
 177                      </xsl:if></xsl:for-each>) {
 178     <xsl:value-of select="concat('Event', @id)"/> me(UNTIMED);
 179 
 180     if (me.should_commit()) {
 181       <xsl:if test="$instant='false'">me.set_starttime(startTicks);
 182       me.set_endtime(endTicks);
 183       </xsl:if>
 184       <xsl:for-each select="value|structvalue|transition_value|relation">me.set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>);
 185       </xsl:for-each>me.commit();
 186     }
 187   }
 188 };
 189 
 190 </xsl:template>
 191 
 192 <xsl:template match="value|transition_value|relation" mode="write-empty-setters">
 193   <xsl:param name="cls"/>
 194   <xsl:variable name="type" select="@type"/>
 195   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 196   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' value) { }')"/>
 197   <xsl:if test="position() != last()">
 198     <xsl:text>
 199 </xsl:text>
 200   </xsl:if>
 201 </xsl:template>
 202 
 203 <xsl:template match="structvalue" mode="write-empty-setters">
 204   <xsl:param name="cls"/>
 205   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { }')"/>
 206   <xsl:if test="position() != last()">
 207     <xsl:text>
 208 </xsl:text>
 209   </xsl:if>
 210 </xsl:template>
 211 
 212 <xsl:template match="value[@type='TICKS']" mode="write-setters">
 213 #if INCLUDE_TRACE
 214 <xsl:value-of select="concat('  void set_', @field, '(const Ticks&amp; time) { _', @field, ' = time; }')"/>
 215 #else
 216 <xsl:value-of select="concat('  void set_', @field, '(const Ticks&amp; ignore) {}')"/>
 217 #endif
 218 </xsl:template>
 219 
 220 <xsl:template match="value[@type='TICKSPAN']" mode="write-setters">
 221 #if INCLUDE_TRACE
 222   <xsl:value-of select="concat('  void set_', @field, '(const Tickspan&amp; time) { _', @field, ' = time; }')"/>
 223 #else
 224   <xsl:value-of select="concat('  void set_', @field, '(const Tickspan&amp; ignore) {}')"/>
 225 #endif
 226 </xsl:template>
 227 
 228 
 229 <xsl:template match="value" mode="write-fields">
 230   <xsl:variable name="type" select="@type"/>
 231   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 232   <xsl:value-of select="concat('  ', $wt, ' _', @field, ';')"/>
 233   <xsl:if test="position() != last()">
 234     <xsl:text> 
 235 </xsl:text>
 236   </xsl:if>
 237 </xsl:template>
 238 
 239 <xsl:template match="structvalue" mode="write-fields">
 240   <xsl:value-of select="concat('  TraceStruct', @type, ' _', @field, ';')"/>
 241   <xsl:text>
 242 </xsl:text>
 243 </xsl:template>
 244 
 245 <xsl:template match="value|transition_value|relation" mode="write-setters">
 246   <xsl:param name="cls"/>
 247   <xsl:variable name="type" select="@type"/>
 248   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 249   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' value) { this->_', @field, ' = value; }')"/>
 250   <xsl:if test="position() != last()">
 251     <xsl:text>
 252 </xsl:text>
 253   </xsl:if>
 254 </xsl:template>
 255 
 256 <xsl:template match="structvalue" mode="write-setters">
 257   <xsl:param name="cls"/>
 258   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { this->_', @field, ' = value; }')"/>
 259   <xsl:if test="position() != last()">
 260     <xsl:text>
 261 </xsl:text>
 262   </xsl:if>
 263 </xsl:template>
 264 
 265 <xsl:template match="value" mode="write-data">
 266   <xsl:variable name="type" select="@type"/>
 267   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@writetype"/>
 268   <xsl:choose>
 269     <xsl:when test="@type='TICKSPAN'">
 270       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, '.value());')"/>
 271     </xsl:when>
 272     <xsl:when test="@type='TICKS'">
 273       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, '.value());')"/>
 274     </xsl:when>
 275     <xsl:otherwise>
 276       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, ');')"/>
 277     </xsl:otherwise>
 278   </xsl:choose>
 279   <xsl:if test="position() != last()">
 280     <xsl:text>
 281     ts.print(", ");
 282 </xsl:text>
 283   </xsl:if>
 284 </xsl:template>
 285 
 286 <xsl:template match="structvalue" mode="write-data">
 287   <xsl:value-of select="concat('    _', @field, '.writeStruct(ts);')"/>
 288   <xsl:if test="position() != last()">
 289     <xsl:text>
 290     ts.print(", ");
 291 </xsl:text>
 292   </xsl:if>
 293 </xsl:template>
 294 
 295 
 296 <xsl:template match="value|transition_value|relation" mode="cpp-type">
 297   <xsl:variable name="type" select="@type"/>
 298   <xsl:value-of select="//primary_type[@symbol=$type]/@type"/>
 299 </xsl:template>
 300 <xsl:template match="structvalue" mode="cpp-type">
 301   <xsl:value-of select="concat('const TraceStruct', @type, '&amp;')"/>
 302 </xsl:template>
 303 
 304 </xsl:stylesheet>