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