1 <?xml version="1.0" encoding="utf-8"?>
   2 <!--
   3  Copyright (c) 2012, 2016, 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 "trace/traceEvent.hpp"
  41 #include "utilities/macros.hpp"
  42 #include "utilities/ticks.hpp"
  43 #if INCLUDE_TRACE
  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   void cancel() {}
  61 };
  62 
  63   <xsl:apply-templates select="trace/events/struct" mode="empty"/>
  64   <xsl:apply-templates select="trace/events/event" mode="empty"/>
  65 
  66 #endif // INCLUDE_TRACE
  67 #endif // TRACEFILES_TRACEEVENTCLASSES_HPP
  68 </xsl:template>
  69 
  70 <xsl:template match="struct" mode="trace">
  71 struct TraceStruct<xsl:value-of select="@id"/>
  72 {
  73 private:
  74 <xsl:apply-templates select="value" mode="write-fields"/>
  75 public:
  76 <xsl:apply-templates select="value" mode="write-setters"/>
  77 
  78   void writeStruct(TraceStream&amp; ts) {
  79 <xsl:apply-templates select="value" mode="write-data"/>
  80   }
  81 };
  82 
  83 </xsl:template>
  84 
  85 <xsl:template match="struct" mode="empty">
  86 struct TraceStruct<xsl:value-of select="@id"/> 
  87 {
  88 public:
  89 <xsl:apply-templates select="value" mode="write-empty-setters"/>
  90 };
  91 </xsl:template>
  92 
  93 
  94 <xsl:template match="event" mode="empty">
  95   <xsl:value-of select="concat('class Event', @id, ' : public TraceEvent')"/>
  96 {
  97  public:
  98 <xsl:value-of select="concat('  Event', @id, '(bool ignore=true) {}')"/>
  99 <xsl:text>
 100 </xsl:text>
 101 
 102 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-empty-setters"/>
 103 };
 104 
 105 </xsl:template>
 106 
 107 
 108 <xsl:template match="event" mode="trace">
 109   <xsl:value-of select="concat('class Event', @id, ' : public TraceEvent&lt;Event', @id, '&gt;')"/>
 110 {
 111  public:
 112   static const bool hasThread = <xsl:value-of select="@has_thread"/>;
 113   static const bool hasStackTrace = <xsl:value-of select="@has_stacktrace"/>;
 114   static const bool isInstant = <xsl:value-of select="@is_instant"/>;
 115   static const bool isRequestable = <xsl:value-of select="@is_requestable"/>;
 116   static const TraceEventId eventId = <xsl:value-of select="concat('Trace', @id, 'Event')"/>;
 117 
 118  private:
 119 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-fields"/>
 120 
 121   void writeEventContent(void) {
 122     TraceStream ts;
 123     ts.print("<xsl:value-of select="@label"/>: [");
 124 <xsl:apply-templates select="value|structvalue" mode="write-data"/>
 125     ts.print("]\n");
 126   }
 127 
 128  public:
 129 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-setters"/>
 130 
 131   bool should_write(void) {
 132     return true;
 133   }
 134 <xsl:text>
 135 
 136 </xsl:text>
 137   <xsl:value-of select="concat('  Event', @id, '(EventStartTime timing=TIMED) : TraceEvent&lt;Event', @id, '&gt;(timing) {}', $newline)"/>
 138   void writeEvent(void) {
 139     if (UseLockedTracing) {
 140       ttyLocker lock;
 141       writeEventContent();
 142     } else {
 143       writeEventContent();
 144     }
 145   }
 146 };
 147 
 148 </xsl:template>
 149 
 150 <xsl:template match="value|transition_value|relation" mode="write-empty-setters">
 151   <xsl:param name="cls"/>
 152   <xsl:variable name="type" select="@type"/>
 153   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 154   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' value) { }')"/>
 155   <xsl:if test="position() != last()">
 156     <xsl:text>
 157 </xsl:text>
 158   </xsl:if>
 159 </xsl:template>
 160 
 161 <xsl:template match="structvalue" mode="write-empty-setters">
 162   <xsl:param name="cls"/>
 163   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { }')"/>
 164   <xsl:if test="position() != last()">
 165     <xsl:text>
 166 </xsl:text>
 167   </xsl:if>
 168 </xsl:template>
 169 
 170 <xsl:template match="value[@type='TICKS']" mode="write-setters">
 171 #if INCLUDE_TRACE
 172 <xsl:value-of select="concat('  void set_', @field, '(const Ticks&amp; time) { _', @field, ' = time; }')"/>
 173 #else
 174 <xsl:value-of select="concat('  void set_', @field, '(const Ticks&amp; ignore) {}')"/>
 175 #endif
 176 </xsl:template>
 177 
 178 <xsl:template match="value[@type='TICKSPAN']" mode="write-setters">
 179 #if INCLUDE_TRACE
 180   <xsl:value-of select="concat('  void set_', @field, '(const Tickspan&amp; time) { _', @field, ' = time; }')"/>
 181 #else
 182   <xsl:value-of select="concat('  void set_', @field, '(const Tickspan&amp; ignore) {}')"/>
 183 #endif
 184 </xsl:template>
 185 
 186 
 187 <xsl:template match="value" mode="write-fields">
 188   <xsl:variable name="type" select="@type"/>
 189   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 190   <xsl:value-of select="concat('  ', $wt, ' _', @field, ';')"/>
 191   <xsl:if test="position() != last()">
 192     <xsl:text> 
 193 </xsl:text>
 194   </xsl:if>
 195 </xsl:template>
 196 
 197 <xsl:template match="structvalue" mode="write-fields">
 198   <xsl:value-of select="concat('  TraceStruct', @type, ' _', @field, ';')"/>
 199   <xsl:text>
 200 </xsl:text>
 201 </xsl:template>
 202 
 203 <xsl:template match="value|transition_value|relation" mode="write-setters">
 204   <xsl:param name="cls"/>
 205   <xsl:variable name="type" select="@type"/>
 206   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 207   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' value) { this->_', @field, ' = value; }')"/>
 208   <xsl:if test="position() != last()">
 209     <xsl:text>
 210 </xsl:text>
 211   </xsl:if>
 212 </xsl:template>
 213 
 214 <xsl:template match="structvalue" mode="write-setters">
 215   <xsl:param name="cls"/>
 216   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { this->_', @field, ' = value; }')"/>
 217   <xsl:if test="position() != last()">
 218     <xsl:text>
 219 </xsl:text>
 220   </xsl:if>
 221 </xsl:template>
 222 
 223 <xsl:template match="value" mode="write-data">
 224   <xsl:variable name="type" select="@type"/>
 225   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@writetype"/>
 226   <xsl:choose>
 227     <xsl:when test="@type='TICKSPAN'">
 228       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, '.value());')"/>
 229     </xsl:when>
 230     <xsl:when test="@type='TICKS'">
 231       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, '.value());')"/>
 232     </xsl:when>
 233     <xsl:otherwise>
 234       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, ');')"/>
 235     </xsl:otherwise>
 236   </xsl:choose>
 237   <xsl:if test="position() != last()">
 238     <xsl:text>
 239     ts.print(", ");
 240 </xsl:text>
 241   </xsl:if>
 242 </xsl:template>
 243 
 244 <xsl:template match="structvalue" mode="write-data">
 245   <xsl:value-of select="concat('    _', @field, '.writeStruct(ts);')"/>
 246   <xsl:if test="position() != last()">
 247     <xsl:text>
 248     ts.print(", ");
 249 </xsl:text>
 250   </xsl:if>
 251 </xsl:template>
 252 
 253 </xsl:stylesheet>