// write sampler data to AMF public void Write(MethodMap methodMap, bool combineSamples = true) { // get accumulated sampler data Address[] data = GetSamplerData(); // AMF serializable sample to write to Protocol.Sampler_sample sample = mSample; int lastCallStackIndex = 0; int lastCallStackCount = 0; // process all samples // this code is tricky because it tries to combine consecutive samples with the exact same callstack int sampleCount = 0; int index = 0; for (;;) { // get length of callstack int count = (int)data[index++]; if (count == 0) break; // get sample time int time = (int)data[index++]; // compare the last callstack with this one // if they are equal, the samples can be combined // else we have to start a new sample if (!combineSamples || (lastCallStackCount != count) || !ArrayEquals(data, index, lastCallStackIndex, count)) { // call stack is different... if (sample.numticks > 0) { // write last sample to log Session.WriteValueImmediate(sNameSamplerSample, sample); // reset sample for new callstack sample.numticks = 0; sample.ticktimes.length = 0; } // translate callstack to method ids var callstack = sample.callstack; callstack.length = 0; for (int i=0; i < count; i++) { bool topOfStack; uint methodId = methodMap.GetMethodId(data[index + i], out topOfStack, true ); // add method id callstack.push(methodId); // abort callstack if we are at a "top of stack" method if (topOfStack) { break; } } // save last callstack position lastCallStackIndex = index; lastCallStackCount = count; } // add tick to sample sample.numticks++; sample.time = time; sample.ticktimes.push((double)time); // advance to next sample index += count; sampleCount++; } if (sample.numticks > 0) { // write last sample to log Session.WriteValueImmediate(sNameSamplerSample, sample); // reset sample for new callstack sample.numticks = 0; sample.ticktimes.length = 0; } if (sampleCount > 0) { // TODO: Session.WriteValue(".sampler.medianInterval", 1000); Session.WriteValue(".sampler.averageInterval", 1000); Session.WriteValue(".sampler.maxInterval", 1000); } }
private static void BeginSession(Stream stream, bool autoCloseStream = true) { // get application name var assembly = System.Reflection.Assembly.GetEntryAssembly(); var appName = assembly.GetName().Name; var swfVersion = 21; var swfSize = 4 * 1024 * 1024; if (CategoryEnabledSampler || CategoryEnabledAllocTraces) { if (sSymbols == null) { // allocate symbol table for method map sSymbols = new SymbolTable(); } // create method map if we need it sMethodMap = new MethodMap(sSymbols); } // create AMF writer from stream sLog = new Log(stream, autoCloseStream); // write telemetry version WriteValue(".tlm.version", Session.Version); WriteValue(".tlm.meta", (double)0.0); WriteValue(".tlm.date", new _root.Date().getTime()); // write player info WriteValue(".player.version", "11,8,800,94"); // WriteValue(".player.airversion", "3.8.0.910"); WriteValue(".player.type", "PlayScript"); WriteValue(".player.debugger", flash.system.Capabilities.isDebugger); WriteValue(".player.global.date", new _root.Date().getTime()); WriteValue(".player.instance", 0); WriteValue(".player.scriptplayerversion", swfVersion); // write platform info WriteValue(".platform.cpucount", System.Environment.ProcessorCount); WriteValue(".platform.capabilities", flash.system.Capabilities.serverString); #if PLATFORM_MONOMAC WriteValue(".platform.gpu.kind", "opengl"); #else WriteValue(".platform.gpu.kind", "opengles2"); #endif #if PLATFORM_MONOMAC || PLATFORM_MONOTOUCH || PLATFORM_MONODROID // write gpu info WriteValue(".platform.gpu.vendor", GL.GetString(StringName.Vendor)); WriteValue(".platform.gpu.renderer", GL.GetString(StringName.Renderer)); WriteValue(".platform.gpu.version", GL.GetString(StringName.Version)); WriteValue(".platform.gpu.shadinglanguageversion", GL.GetString(StringName.ShadingLanguageVersion)); WriteValue(".platform.gpu.extensions", GL.GetString(StringName.Extensions)); #endif // write memory stats WriteValue(".mem.total", 8 * 1024); WriteValue(".mem.used", 4 * 1024); WriteValue(".mem.managed", 0); WriteValue(".mem.managed.used", 0); WriteValue(".mem.telemetry.overhead", 0); // write telemetry categories WriteCategoryEnabled("3D", CategoryEnabled3D); WriteCategoryEnabled("sampler", CategoryEnabledSampler); WriteCategoryEnabled("displayobjects", CategoryEnabledDisplayObjects); WriteCategoryEnabled("alloctraces", CategoryEnabledAllocTraces); WriteCategoryEnabled("allalloctraces", CategoryEnabledAllAllocTraces); WriteCategoryEnabled("customMetrics", CategoryEnabledCustomMetrics); WriteValue(".network.loadmovie", "app:/" + appName); WriteValue(".rend.display.mode", "auto"); // SWF startup timestamp WriteTime(".swf.start"); // write swf stats WriteSWFStats(appName, (int)flash.system.Capabilities.screenResolutionX, (int)flash.system.Capabilities.screenResolutionY, 60, swfVersion, swfSize); // write memory stats WriteMemoryStats(); // start categories if (CategoryEnabledAllocTraces) { WriteValue(".tlm.category.start", "alloctraces"); } if (CategoryEnabledCustomMetrics) { WriteValue(".tlm.category.start", "customMetrics"); } if (CategoryEnabledSampler) { WriteValue(".tlm.category.start", "sampler"); } // enable 'advanced telemetry' WriteValue(".tlm.detailedMetrics.start", true); Flush(); if (CategoryEnabledSampler) { // start sampler sSampler = new Sampler(sLog.StartTime, sLog.Divisor, SamplerRate, SamplerMaxCallStackDepth, SamplerStartDelay); } }
// write sampler data to AMF public void Write(MethodMap methodMap, bool combineSamples = true) { // get accumulated sampler data Address[] data = GetSamplerData(); // AMF serializable sample to write to Protocol.Sampler_sample sample = mSample; int lastCallStackIndex = 0; int lastCallStackCount = 0; // process all samples // this code is tricky because it tries to combine consecutive samples with the exact same callstack int sampleCount = 0; int index = 0; for (;;) { // get length of callstack int count = (int)data[index++]; if (count == 0) { break; } // get sample time int time = (int)data[index++]; // compare the last callstack with this one // if they are equal, the samples can be combined // else we have to start a new sample if (!combineSamples || (lastCallStackCount != count) || !ArrayEquals(data, index, lastCallStackIndex, count)) { // call stack is different... if (sample.numticks > 0) { // write last sample to log Session.WriteValueImmediate(sNameSamplerSample, sample); // reset sample for new callstack sample.numticks = 0; sample.ticktimes.length = 0; } // translate callstack to method ids var callstack = sample.callstack; callstack.length = 0; for (int i = 0; i < count; i++) { bool topOfStack; uint methodId = methodMap.GetMethodId(data[index + i], out topOfStack, true); // add method id callstack.push(methodId); // abort callstack if we are at a "top of stack" method if (topOfStack) { break; } } // save last callstack position lastCallStackIndex = index; lastCallStackCount = count; } // add tick to sample sample.numticks++; sample.time = time; sample.ticktimes.push((double)time); // advance to next sample index += count; sampleCount++; } if (sample.numticks > 0) { // write last sample to log Session.WriteValueImmediate(sNameSamplerSample, sample); // reset sample for new callstack sample.numticks = 0; sample.ticktimes.length = 0; } if (sampleCount > 0) { // TODO: Session.WriteValue(".sampler.medianInterval", 1000); Session.WriteValue(".sampler.averageInterval", 1000); Session.WriteValue(".sampler.maxInterval", 1000); } }
private static void BeginSession(Stream stream, bool autoCloseStream = true) { // get application name var assembly = System.Reflection.Assembly.GetEntryAssembly(); var appName = assembly.GetName().Name; var swfVersion = 21; var swfSize = 4 * 1024 * 1024; if (CategoryEnabledSampler || CategoryEnabledAllocTraces) { if (sSymbols == null) { // allocate symbol table for method map sSymbols = new SymbolTable(); } // create method map if we need it sMethodMap = new MethodMap(sSymbols); } // create AMF writer from stream sLog = new Log(stream, autoCloseStream); // write telemetry version WriteValue(".tlm.version", Session.Version); WriteValue(".tlm.meta", (double)0.0); WriteValue(".tlm.date", new _root.Date().getTime()); // write player info WriteValue(".player.version", "11,8,800,94"); // WriteValue(".player.airversion", "3.8.0.910"); WriteValue(".player.type", "PlayScript"); WriteValue(".player.debugger", flash.system.Capabilities.isDebugger); WriteValue(".player.global.date", new _root.Date().getTime()); WriteValue(".player.instance", 0); WriteValue(".player.scriptplayerversion", swfVersion); #if PLATFORM_MONOMAC // write platform info (this is faked) WriteValue(".platform.capabilities", "&M=Adobe%20Macintosh&R=1920x1200&COL=color&AR=1.0&OS=Mac%20OS%2010.7.4&ARCH=x86&L=en&PR32=t&PR64=t&LS=en;ja;fr;de;es;it;pt;pt-PT;nl;sv;nb;da;fi;ru;pl;zh-Hans;zh-Hant;ko;ar;cs;hu;tr"); WriteValue(".platform.cpucount", 4); // write gpu info (this is faked) WriteValue(".platform.gpu.kind", "opengl"); #else // write platform info (this is faked) WriteValue(".platform.capabilities", "&M=Adobe iOS&R=640x960&COL=color&AR=1&OS=iPhone OS 6.1 iPhone5,1&ARCH=ARM&L=en&IME=false&PR32=true&PR64=false&LS=en;fr;de;ja;nl;it;es;pt;pt-PT;da;fi;nb;sv;ko;zh-Hans;zh-Hant;ru;pl;tr;uk;ar;hr;cs;el;he;ro;sk;th;id;ms;en-GB;ca;hu;vi"); WriteValue(".platform.cpucount", 2); // write gpu info (this is faked) WriteValue(".platform.gpu.kind", "opengles2"); WriteValue(".platform.gpu.vendor", "Imagination Technologies"); WriteValue(".platform.gpu.renderer", "PowerVR SGX 535"); WriteValue(".platform.gpu.version", "OpenGL ES 2.0 IMGSGX535-63.24"); WriteValue(".platform.gpu.shadinglanguageversion", "OpenGL ES GLSL ES 1.0"); WriteValue(".platform.3d.driverinfo", "OpenGL Vendor=Imagination Technologies Version=OpenGL ES 2.0 IMGSGX535-63.24 Renderer=PowerVR SGX 535 GLSL=OpenGL ES GLSL ES 1.0"); #endif // write memory stats WriteValue(".mem.total", 8 * 1024); WriteValue(".mem.used", 4 * 1024); WriteValue(".mem.managed", 0); WriteValue(".mem.managed.used", 0); WriteValue(".mem.telemetry.overhead", 0); // write telemetry categories WriteCategoryEnabled("3D", CategoryEnabled3D); WriteCategoryEnabled("sampler", CategoryEnabledSampler); WriteCategoryEnabled("displayobjects", CategoryEnabledDisplayObjects); WriteCategoryEnabled("alloctraces", CategoryEnabledAllocTraces); WriteCategoryEnabled("allalloctraces", CategoryEnabledAllAllocTraces); WriteCategoryEnabled("customMetrics", CategoryEnabledCustomMetrics); WriteValue(".network.loadmovie", "app:/" + appName ); WriteValue(".rend.display.mode", "auto"); // SWF startup timestamp WriteTime(".swf.start"); // write swf stats WriteSWFStats(appName, 800, 600, 60, swfVersion, swfSize); // write memory stats WriteMemoryStats(); // start categories if (CategoryEnabledAllocTraces) { WriteValue(".tlm.category.start", "alloctraces"); } if (CategoryEnabledCustomMetrics) { WriteValue(".tlm.category.start", "customMetrics"); } if (CategoryEnabledSampler) { WriteValue(".tlm.category.start", "sampler"); } // enable 'advanced telemetry' WriteValue(".tlm.detailedMetrics.start", true); Flush(); if (CategoryEnabledSampler) { // start sampler sSampler = new Sampler(sLog.StartTime, sLog.Divisor, SamplerRate, SamplerMaxCallStackDepth, SamplerStartDelay); } }