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& ignore) {} 56 void set_endtime(const Ticks& 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& 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<Event', @id, '>')"/> 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<Event', @id, '>(timing) {}', $newline)"/> 137 void writeEvent(void) { 138 if (UseLockedTracing) { 139 ttyLocker lock; 140 writeEventContent(); 141 } else { 142 writeEventContent(); 143 } 144 } 145 146 using TraceEvent::commit; // else commit() is hidden by overloaded versions in this class 147 <xsl:variable name="instant" select="@is_instant"/> 148 <!-- non static method (only for non instant events)--> 149 <xsl:if test="$instant='false'"> 150 <xsl:value-of select="concat(' Event', @id)"/>( 151 <xsl:for-each select="value|structvalue|transition_value|relation"> 152 <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/> 153 <xsl:if test="position() != last()">, 154 </xsl:if></xsl:for-each>) : TraceEvent<<xsl:value-of select="concat('Event', @id)"/>>(TIMED) { 155 if (should_commit()) {<xsl:for-each select="value|structvalue|transition_value|relation"> 156 set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>);</xsl:for-each> 157 } 158 } 159 160 void commit(<xsl:for-each select="value|structvalue|transition_value|relation"> 161 <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/> 162 <xsl:if test="position() != last()">, 163 </xsl:if></xsl:for-each>) { 164 if (should_commit()) { 165 <xsl:for-each select="value|structvalue|transition_value|relation">set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>); 166 </xsl:for-each>commit(); 167 } 168 }</xsl:if> 169 <!-- static method (for all events) --> 170 static void commit(<xsl:if test="$instant='false'">const Ticks& startTicks, 171 const Ticks& endTicks<xsl:choose><xsl:when test="value|structvalue|transition_value|relation">, 172 </xsl:when></xsl:choose></xsl:if> 173 <xsl:for-each select="value|structvalue|transition_value|relation"> 174 <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/> 175 <xsl:if test="position() != last()">, 176 </xsl:if></xsl:for-each>) { 177 <xsl:value-of select="concat('Event', @id)"/> me(UNTIMED); 178 179 if (me.should_commit()) { 180 <xsl:if test="$instant='false'">me.set_starttime(startTicks); 181 me.set_endtime(endTicks); 182 </xsl:if> 183 <xsl:for-each select="value|structvalue|transition_value|relation">me.set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>); 184 </xsl:for-each>me.commit(); 185 } 186 } 187 }; 188 189 </xsl:template> 190 191 <xsl:template match="value|transition_value|relation" mode="write-empty-setters"> 192 <xsl:param name="cls"/> 193 <xsl:variable name="type" select="@type"/> 194 <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/> 195 <xsl:value-of select="concat(' void set_', @field, '(', $wt, ' value) { }')"/> 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-empty-setters"> 203 <xsl:param name="cls"/> 204 <xsl:value-of select="concat(' void set_', @field, '(const TraceStruct', @type, '& value) { }')"/> 205 <xsl:if test="position() != last()"> 206 <xsl:text> 207 </xsl:text> 208 </xsl:if> 209 </xsl:template> 210 211 <xsl:template match="value[@type='TICKS']" mode="write-setters"> 212 #if INCLUDE_TRACE 213 <xsl:value-of select="concat(' void set_', @field, '(const Ticks& time) { _', @field, ' = time; }')"/> 214 #else 215 <xsl:value-of select="concat(' void set_', @field, '(const Ticks& ignore) {}')"/> 216 #endif 217 </xsl:template> 218 219 <xsl:template match="value[@type='TICKSPAN']" mode="write-setters"> 220 #if INCLUDE_TRACE 221 <xsl:value-of select="concat(' void set_', @field, '(const Tickspan& time) { _', @field, ' = time; }')"/> 222 #else 223 <xsl:value-of select="concat(' void set_', @field, '(const Tickspan& ignore) {}')"/> 224 #endif 225 </xsl:template> 226 227 228 <xsl:template match="value" mode="write-fields"> 229 <xsl:variable name="type" select="@type"/> 230 <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/> 231 <xsl:value-of select="concat(' ', $wt, ' _', @field, ';')"/> 232 <xsl:if test="position() != last()"> 233 <xsl:text> 234 </xsl:text> 235 </xsl:if> 236 </xsl:template> 237 238 <xsl:template match="structvalue" mode="write-fields"> 239 <xsl:value-of select="concat(' TraceStruct', @type, ' _', @field, ';')"/> 240 <xsl:text> 241 </xsl:text> 242 </xsl:template> 243 244 <xsl:template match="value|transition_value|relation" mode="write-setters"> 245 <xsl:param name="cls"/> 246 <xsl:variable name="type" select="@type"/> 247 <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/> 248 <xsl:value-of select="concat(' void set_', @field, '(', $wt, ' value) { this->_', @field, ' = value; }')"/> 249 <xsl:if test="position() != last()"> 250 <xsl:text> 251 </xsl:text> 252 </xsl:if> 253 </xsl:template> 254 255 <xsl:template match="structvalue" mode="write-setters"> 256 <xsl:param name="cls"/> 257 <xsl:value-of select="concat(' void set_', @field, '(const TraceStruct', @type, '& value) { this->_', @field, ' = value; }')"/> 258 <xsl:if test="position() != last()"> 259 <xsl:text> 260 </xsl:text> 261 </xsl:if> 262 </xsl:template> 263 264 <xsl:template match="value" mode="write-data"> 265 <xsl:variable name="type" select="@type"/> 266 <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@writetype"/> 267 <xsl:choose> 268 <xsl:when test="@type='TICKSPAN'"> 269 <xsl:value-of select="concat(' ts.print_val("', @label, '", _', @field, '.value());')"/> 270 </xsl:when> 271 <xsl:when test="@type='TICKS'"> 272 <xsl:value-of select="concat(' ts.print_val("', @label, '", _', @field, '.value());')"/> 273 </xsl:when> 274 <xsl:otherwise> 275 <xsl:value-of select="concat(' ts.print_val("', @label, '", _', @field, ');')"/> 276 </xsl:otherwise> 277 </xsl:choose> 278 <xsl:if test="position() != last()"> 279 <xsl:text> 280 ts.print(", "); 281 </xsl:text> 282 </xsl:if> 283 </xsl:template> 284 285 <xsl:template match="structvalue" mode="write-data"> 286 <xsl:value-of select="concat(' _', @field, '.writeStruct(ts);')"/> 287 <xsl:if test="position() != last()"> 288 <xsl:text> 289 ts.print(", "); 290 </xsl:text> 291 </xsl:if> 292 </xsl:template> 293 294 295 <xsl:template match="value|transition_value|relation" mode="cpp-type"> 296 <xsl:variable name="type" select="@type"/> 297 <xsl:value-of select="//primary_type[@symbol=$type]/@type"/> 298 </xsl:template> 299 <xsl:template match="structvalue" mode="cpp-type"> 300 <xsl:value-of select="concat('const TraceStruct', @type, '&')"/> 301 </xsl:template> 302 303 </xsl:stylesheet>