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 #if INCLUDE_TRACE 45 #include "trace/traceStream.hpp" 46 #include "utilities/ostream.hpp" 47 48 <xsl:apply-templates select="trace/events/struct" mode="trace"/> 49 <xsl:apply-templates select="trace/events/event" mode="trace"/> 50 51 #else // !INCLUDE_TRACE 52 53 class TraceEvent { 54 public: 55 TraceEvent() {} 56 void set_starttime(const Ticks& time) {} 57 void set_endtime(const Ticks& time) {} 58 bool should_commit() const { return false; } 59 static bool is_enabled() { return false; } 60 void commit() const {} 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& 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<Event', @id, '>')"/> 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(*tty); 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<Event', @id, '>(timing) {}', $newline)"/> 138 void writeEvent(void) { 139 ResourceMark rm; 140 if (UseLockedTracing) { 141 ttyLocker lock; 142 writeEventContent(); 143 } else { 144 writeEventContent(); 145 } 146 } 147 }; 148 149 </xsl:template> 150 151 <xsl:template match="value|transition_value|relation" mode="write-empty-setters"> 152 <xsl:param name="cls"/> 153 <xsl:variable name="type" select="@type"/> 154 <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/> 155 <xsl:value-of select="concat(' void set_', @field, '(', $wt, ' value) { }')"/> 156 <xsl:if test="position() != last()"> 157 <xsl:text> 158 </xsl:text> 159 </xsl:if> 160 </xsl:template> 161 162 <xsl:template match="structvalue" mode="write-empty-setters"> 163 <xsl:param name="cls"/> 164 <xsl:value-of select="concat(' void set_', @field, '(const TraceStruct', @type, '& value) { }')"/> 165 <xsl:if test="position() != last()"> 166 <xsl:text> 167 </xsl:text> 168 </xsl:if> 169 </xsl:template> 170 171 <xsl:template match="value[@type='TICKS']" mode="write-setters"> 172 #if INCLUDE_TRACE 173 <xsl:value-of select="concat(' void set_', @field, '(const Ticks& time) { _', @field, ' = time; }')"/> 174 #else 175 <xsl:value-of select="concat(' void set_', @field, '(const Ticks& ignore) {}')"/> 176 #endif 177 </xsl:template> 178 179 <xsl:template match="value[@type='TICKSPAN']" mode="write-setters"> 180 #if INCLUDE_TRACE 181 <xsl:value-of select="concat(' void set_', @field, '(const Tickspan& time) { _', @field, ' = time; }')"/> 182 #else 183 <xsl:value-of select="concat(' void set_', @field, '(const Tickspan& ignore) {}')"/> 184 #endif 185 </xsl:template> 186 187 188 <xsl:template match="value" mode="write-fields"> 189 <xsl:variable name="type" select="@type"/> 190 <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/> 191 <xsl:value-of select="concat(' ', $wt, ' _', @field, ';')"/> 192 <xsl:if test="position() != last()"> 193 <xsl:text> 194 </xsl:text> 195 </xsl:if> 196 </xsl:template> 197 198 <xsl:template match="structvalue" mode="write-fields"> 199 <xsl:value-of select="concat(' TraceStruct', @type, ' _', @field, ';')"/> 200 <xsl:text> 201 </xsl:text> 202 </xsl:template> 203 204 <xsl:template match="value|transition_value|relation" mode="write-setters"> 205 <xsl:param name="cls"/> 206 <xsl:variable name="type" select="@type"/> 207 <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/> 208 <xsl:value-of select="concat(' void set_', @field, '(', $wt, ' value) { this->_', @field, ' = value; }')"/> 209 <xsl:if test="position() != last()"> 210 <xsl:text> 211 </xsl:text> 212 </xsl:if> 213 </xsl:template> 214 215 <xsl:template match="structvalue" mode="write-setters"> 216 <xsl:param name="cls"/> 217 <xsl:value-of select="concat(' void set_', @field, '(const TraceStruct', @type, '& value) { this->_', @field, ' = value; }')"/> 218 <xsl:if test="position() != last()"> 219 <xsl:text> 220 </xsl:text> 221 </xsl:if> 222 </xsl:template> 223 224 <xsl:template match="value" mode="write-data"> 225 <xsl:variable name="type" select="@type"/> 226 <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@writetype"/> 227 <xsl:choose> 228 <xsl:when test="@type='TICKSPAN'"> 229 <xsl:value-of select="concat(' ts.print_val("', @label, '", _', @field, '.value());')"/> 230 </xsl:when> 231 <xsl:when test="@type='TICKS'"> 232 <xsl:value-of select="concat(' ts.print_val("', @label, '", _', @field, '.value());')"/> 233 </xsl:when> 234 <xsl:otherwise> 235 <xsl:value-of select="concat(' ts.print_val("', @label, '", _', @field, ');')"/> 236 </xsl:otherwise> 237 </xsl:choose> 238 <xsl:if test="position() != last()"> 239 <xsl:text> 240 ts.print(", "); 241 </xsl:text> 242 </xsl:if> 243 </xsl:template> 244 245 <xsl:template match="structvalue" mode="write-data"> 246 <xsl:value-of select="concat(' _', @field, '.writeStruct(ts);')"/> 247 <xsl:if test="position() != last()"> 248 <xsl:text> 249 ts.print(", "); 250 </xsl:text> 251 </xsl:if> 252 </xsl:template> 253 254 </xsl:stylesheet>