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