performance-monitor-logger
Version:
## Instalação
2 lines • 33.9 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common/http"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("performance-monitor-logger",["exports","@angular/core","@angular/common/http","rxjs/operators"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["performance-monitor-logger"]={},e.ng.core,e.ng.common.http,e.rxjs.operators)}(this,(function(e,t,o,n){"use strict";var r=function(){function e(){}return e.prototype.ngOnInit=function(){},e}();r.decorators=[{type:t.Component,args:[{selector:"lib-performanceMonitorLogger",template:" <p>performance-monitor-logger works!</p> "}]}],r.ctorParameters=function(){return[]};var i=function(){};i.decorators=[{type:t.NgModule,args:[{declarations:[r],imports:[],exports:[r]}]}];var a=function(){};a.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new a},token:a,providedIn:"root"}),a.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],a.ctorParameters=function(){return[]};function c(e,t,o,n){return new(o||(o=Promise))((function(r,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,c)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var o,n,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=c(0),a.throw=c(1),a.return=c(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(s){return function(c){if(o)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(o=1,n&&(r=2&c[0]?n.return:c[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,c[1])).done)return r;switch(n=0,r&&(c=[2&c[0],r.value]),c[0]){case 0:case 1:r=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,n=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!r||c[1]>r[0]&&c[1]<r[3])){i.label=c[1];break}if(6===c[0]&&i.label<r[1]){i.label=r[1],r=c;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(c);break}r[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],n=0}finally{o=r=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}Object.create;function l(e){var t="function"==typeof Symbol&&Symbol.iterator,o=t&&e[t],n=0;if(o)return o.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function f(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var n,r,i=o.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}return a}function u(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(f(arguments[t]));return e}Object.create;"function"==typeof SuppressedError&&SuppressedError;var p=function(){function e(e){void 0===e&&(e="Service"),this.monitoramentoAtivo=!0,this.performanceTimers=new Map,this.performanceSummary=new Map,this.httpRequests=new Map,this.functionContextStack=[],this.eventContextStack=[],this.timerStack=[],this.lastTimerActivityAt=null,this.firstTimerInEventAt=null,this.currentEventBeginAt=null,this.instrumentedFns=new WeakMap,this.serviceName=e}return e.prototype.registerHttpRequest=function(e,t,o){var n,r;void 0===o&&(o=!1);var i="(desconhecido)";try{var a=null===(n=null==e?void 0:e.body)||void 0===n?void 0:n.name,c=this.extrairNomeDeSQL(null===(r=null==e?void 0:e.body)||void 0===r?void 0:r.sqlInstruction),s=(null==e?void 0:e.method)||"HTTP",l=null==e?void 0:e.url;if(a)i=a;else if(c)i=c;else if(l){var f=String(l).split("?")[0],u=f.split("/").filter(Boolean);i=s+" "+(u[u.length-1]||f)}else i=s}catch(e){}var p=this.eventContextStack.length?this.eventContextStack[this.eventContextStack.length-1]:void 0,m=p?p+" | "+i:i,d=this.httpRequests.get(m)||{tempoTotal:0,execucoes:0,errors:0};d.tempoTotal+=Number.isFinite(t)?t:0,d.execucoes+=1,o&&(d.errors+=1),this.httpRequests.set(m,d)},e.prototype.extrairNomeDeSQL=function(e){if(!e)return null;var t=e.match(/([A-Z0-9_]+\.[A-Z0-9_]+)/i);return t?t[1]:null},e.prototype.showWelcomeMessage=function(){console.log("%cSISTEMA DE MONITORAMENTO DE PERFORMANCE","color: #bbc7c8ff; font-size: 18px; font-weight: bold; text-shadow: 1px 1px #000; background-color: #43248bff; border-radius: 5px; padding: 10px 20px;")},e.prototype.startTimer=function(e){if(this.monitoramentoAtivo){if(0===this.performanceTimers.size&&0===this.performanceSummary.size){"═".repeat(56);console.log("%cINÍCIO DO MONITORAMENTO DE PERFORMANCE","color: #bbc7c8ff; font-size: 18px; font-weight: bold; text-shadow: 1px 1px #000; background-color: #43248bff; border-radius: 5px; padding: 10px 20px;")}this.performanceTimers.set(e,Date.now()),this.functionContextStack.push(e);var t,o,n=this.eventContextStack.length?this.eventContextStack[0]:void 0,r=String(e).split(".");r.length>=2?(t=r[0],o=r[r.length-1]):(t=void 0,o=e);var i=t?t+" | "+o:o,a=Date.now();n&&null===this.firstTimerInEventAt&&(this.firstTimerInEventAt=a),this.lastTimerActivityAt=a,this.timerStack.push({name:e,start:a,childElapsed:0,event:n,fullName:i}),console.log("║ [INÍCIO] "+i+" - "+(new Date).toLocaleTimeString())}},e.prototype.endTimer=function(e,t,o){var n,r,i,a,c,s;if(this.monitoramentoAtivo){var l=Date.now(),f=this.timerStack.length?this.timerStack[this.timerStack.length-1]:void 0;if(f&&f.name===e)this.timerStack.pop();else{for(var u=-1,p=this.timerStack.length-1;p>=0;p--)if(this.timerStack[p].name===e){u=p;break}if(-1===u)return void console.warn("⚠️ Timer não encontrado para: "+e);f=this.timerStack[u],this.timerStack.splice(u,1)}this.lastTimerActivityAt=l;var m=l-f.start,d=Math.max(0,m-f.childElapsed),h=this.timerStack[this.timerStack.length-1];h&&(h.childElapsed+=m),this.performanceTimers.delete(e),this.functionContextStack[this.functionContextStack.length-1]===e&&this.functionContextStack.pop();var g=this.getPerformanceStatus(d,o,null!==(n=f.fullName)&&void 0!==n?n:f.event?f.event+" | "+e:e),v=g.emoji,y=g.status,b=g.color,x=t?(null!==(r=f.fullName)&&void 0!==r?r:f.event?f.event+" | "+e:e)+" - "+t:""+(null!==(i=f.fullName)&&void 0!==i?i:f.event?f.event+" | "+e:e),T=("["+y+"]").padEnd(5),S=x.padEnd(10),E=d.toString().padStart(5);console.log("║ %c"+v+" "+T+" "+S+" - "+E+"ms ",b),o&&(o.ok||o.lento||o.critico)&&console.log("⚙️ Thresholds customizados: OK<"+(null!==(a=o.ok)&&void 0!==a?a:500)+"ms, LENTO<"+(null!==(c=o.lento)&&void 0!==c?c:2e3)+"ms"),this.updatePerformanceSummary(null!==(s=f.fullName)&&void 0!==s?s:f.event?f.event+" | "+e:e,d,o)}},e.prototype.getPerformanceStatus=function(e,t,o){var n,r,i,a,c;if(t&&(t.ok||t.lento||t.critico))a=null!==(n=t.ok)&&void 0!==n?n:500,c=null!==(r=t.lento)&&void 0!==r?r:2e3,null!==(i=t.critico)&&void 0!==i?i:Number.MAX_SAFE_INTEGER;else if(o){var s=this.performanceSummary.get(o),l=s?s.count+1:1,f=this.calculateDynamicThresholds(l);a=f.ok,c=f.lento,f.critico}else a=500,c=2e3,Number.MAX_SAFE_INTEGER;return e<a?{emoji:"🟢",status:"OK",color:"color: green; font-weight: bold;"}:e<c?{emoji:"🟡",status:"LENTO",color:"color: orange; font-weight: bold;"}:{emoji:"🔴",status:"CRÍTICO",color:"color: red; font-weight: bold;"}},e.prototype.updatePerformanceSummary=function(e,t,o){var n=this.performanceSummary.get(e);n?(n.count++,n.totalTime+=t,n.minTime=Math.min(n.minTime,t),n.maxTime=Math.max(n.maxTime,t),o&&(o.ok||o.lento||o.critico)&&(n.customThresholds=o)):this.performanceSummary.set(e,{count:1,totalTime:t,minTime:t,maxTime:t,customThresholds:o})},e.prototype.showPerformanceSummary=function(e){var t=this;if(void 0===e&&(e=!1),console.log("%c RELATÓRIO DE PERFORMANCE","color: #bbc7c8ff; font-size: 18px; font-weight: bold; text-shadow: 1px 1px #000; background-color: #43248bff; border-radius: 5px; padding: 10px 20px;"),0!==this.performanceSummary.size){var o=Array.from(this.performanceSummary.entries()).sort((function(e,t){return t[1].maxTime-e[1].maxTime})),n=Object.fromEntries(o.map((function(e){var o=f(e,2),n=o[0],r=o[1],i=Math.round(r.totalTime/r.count),a=t.getPerformanceStatus(i,r.customThresholds,n),c=a.emoji,s=a.status;return[n,{"Execuções":r.count,"Média(ms)":(i+"ms ("+s+") "+c).trim(),"Mínimo(ms)":r.minTime,"Máximo(ms)":r.maxTime,"Total(ms)":r.totalTime}]})));console.table(n)}else console.log("%c Nenhuma operação monitorada ainda.","color: gray; font-style: italic;")},e.prototype.showHttpRequestsReport=function(){if(console.log("%cRELATÓRIO DETALHADO DE REQUISIÇÕES HTTP","color: #bbc7c8ff; font-size: 18px; font-weight: bold; text-shadow: 1px 1px #000; background-color: #43248bff; border-radius: 5px; padding: 10px 20px;"),0!==this.httpRequests.size){var e=Object.fromEntries(Array.from(this.httpRequests.entries()).sort((function(e,t){return t[1].tempoTotal-e[1].tempoTotal})).map((function(e){var t=f(e,2),o=t[0],n=t[1];return[o,{"Execuções":n.execucoes,"Média":Math.round(n.tempoTotal/n.execucoes)+"ms","Tempo Total":Math.round(n.tempoTotal)+"ms",Erros:n.errors}]})));console.table(e)}else console.log("Nenhuma requisição HTTP registrada.")},e.prototype.generateDetailedAnalysis=function(){var e=this;if(console.log("%cANÁLISE DETALHADA DE PERFORMANCE","color: #bbc7c8ff; font-size: 18px; font-weight: bold; text-shadow: 1px 1px #000; background-color: #43248bff; border-radius: 5px; padding: 10px 20px;"),console.log(""),0!==this.performanceSummary.size){var t=this.categorizeOperations(),o=t.criticalOperations,n=t.slowOperations,r=t.fastOperations,i=function(e,t,o,n,r){var i="border-left: 4px solid "+e+"; padding: 2px 0 2px 10px; margin: 2px 0 2px 0; font-size: 14px; color: #fff; background: none; font-weight: normal;";console.log(("%c"+t+" "+o+" - "+n+"ms (média) "+r).trim(),i)};o.length>0&&(console.log("%c🔴 CRÍTICAS ( > 2000ms)","color: #fff; font-size: 14px; font-weight: bold; margin-top: 10px;"),o.forEach((function(t){var o=f(t,2),n=o[0],r=o[1],a=Math.round(r.totalTime/r.count),c=e.getPerformanceStatus(a,r.customThresholds,n).emoji;i("#c53030",c,n,a,"| otimizar urgente")}))),n.length>0&&(console.log("%c🟡 LENTAS (500ms - 2000ms)","color: #fff; font-size: 14px; font-weight: bold; margin-top: 10px;"),n.forEach((function(t){var o=f(t,2),n=o[0],r=o[1],a=Math.round(r.totalTime/r.count),c=e.getPerformanceStatus(a,r.customThresholds,n).emoji;i("#b7791f",c,n,a,"| pode ser melhorada")}))),r.length>0&&(console.log("%c🟢 RÁPIDAS ( < 500ms)","color: #fff; font-size: 14px; font-weight: bold; margin-top: 10px;"),r.forEach((function(t){var o=f(t,2),n=o[0],r=o[1],a=Math.round(r.totalTime/r.count),c=e.getPerformanceStatus(a,r.customThresholds,n).emoji;i("#38a169",c,n,a,"| excelente")}))),console.log("%cRecomendações:","color: #fff; font-size: 13px; font-weight: bold; margin-top: 14px; padding: 2px 0 2px 0;"),o.length>0&&(console.log("%c• Priorize a otimização das operações críticas.","color: #fff; font-size: 13px; font-weight: normal;"),console.log("%c• Considere implementar cache ou otimizar consultas SQL para essas operações.","color: #fff; font-size: 13px; font-weight: normal;")),n.length>0&&console.log("%c• Operações lentas podem se beneficiar de índices no banco de dados.","color: #fff; font-size: 13px; font-weight: normal;"),0===o.length&&0===n.length&&console.log("%c• Todas as operações estão com performance excelente!","color: #fff; font-size: 13px; font-weight: normal;");var a=this.performanceSummary.size,c=r.length,s=a>0?Math.round(c/a*100):100,l=s>=80?"#38a169":s>=60?"#f6e05e":"#c53030",u=s>=80?"Excelente! A maioria das operações está performando bem.":s>=60?"Médio. Há espaço para melhorias de performance.":"Crítico. Muitas operações precisam de otimização urgente.";console.log("%cScore de performance: "+s+"%","color: #fff; background: "+l+"; font-size: 14px; font-weight: bold; margin-top: 10px; padding: 2px 8px; border-radius: 3px;"),console.log("%c"+u,"color: #fff; font-size: 13px; font-weight: normal; margin-bottom: 8px;"),console.log("")}else console.log("%cNenhuma operação registrada para análise.","color: #bbb; font-style: italic; font-size: 14px; padding: 4px 0 4px 10px;")},e.prototype.categorizeOperations=function(){return{criticalOperations:Array.from(this.performanceSummary.entries()).filter((function(e){var t=f(e,2),o=(t[0],t[1]);return o.totalTime/o.count>2e3})),slowOperations:Array.from(this.performanceSummary.entries()).filter((function(e){var t=f(e,2),o=(t[0],t[1]),n=o.totalTime/o.count;return n>=500&&n<=2e3})),fastOperations:Array.from(this.performanceSummary.entries()).filter((function(e){var t=f(e,2),o=(t[0],t[1]);return o.totalTime/o.count<500}))}},e.prototype.showRecommendations=function(e,t){console.log("RECOMENDAÇÕES:"),e.length>0&&(console.log(" Priorize a otimização das operações críticas."),console.log(" Considere implementar cache ou otimizar consultas SQL para essas operações.")),t.length>0&&console.log(" Operações lentas podem se beneficiar de índices no banco de dados."),0===e.length&&0===t.length&&console.log(" Todas as operações estão com performance excelente!")},e.prototype.showPerformanceScore=function(e){var t=this.performanceSummary.size,o=Math.round(e/t*100);console.log("SCORE DE PERFORMANCE: "+o+"%"),o>=80?console.log("Excelente! A maioria das operações está performando bem."):o>=60?console.log("Médio. Há espaço para melhorias de performance."):console.log("Crítico. Muitas operações precisam de otimização urgente.")},e.prototype.getPerformanceReport=function(){this.showPerformanceSummary()},e.prototype.beginEventContext=function(e){e&&(0===this.eventContextStack.length&&(this.currentEventBeginAt=Date.now(),this.firstTimerInEventAt=null,this.lastTimerActivityAt=null),this.eventContextStack.push(e))},e.prototype.endEventContext=function(){this.eventContextStack.length>0&&this.eventContextStack.pop()},e.prototype.runInEventContext=function(e,t){return c(this,void 0,void 0,(function(){var o;return s(this,(function(n){switch(n.label){case 0:this.beginEventContext(e),n.label=1;case 1:return n.trys.push([1,,3,4]),o=t(),[4,Promise.resolve(o)];case 2:return[2,n.sent()];case 3:return this.endEventContext(),[7];case 4:return[2]}}))}))},e.prototype.resetPerformanceData=function(){this.performanceTimers.clear(),this.performanceSummary.clear(),this.httpRequests.clear(),console.log("%c🧹 [CLEANUP] Dados de performance limpos","color: #fff; background: #43248bff; font-size: 13px; font-weight: bold; border-radius: 4px; padding: 4px 12px; margin: 6px 0;")},e.prototype.setInactivityDelay=function(e){console.log("⏰ Relatório por inatividade está desabilitado.")},e.prototype.disableInactivityReport=function(){console.log("🔇 Relatório por inatividade já está desabilitado")},e.prototype.setAutoReportThreshold=function(e){console.log("⚙️ Threshold para relatório automático está desabilitado.")},e.prototype.disableAutoReport=function(){console.log("🔇 Relatório automático desabilitado")},e.prototype.getStatistics=function(){var e=this.categorizeOperations(),t=e.criticalOperations,o=e.slowOperations,n=e.fastOperations,r=this.performanceSummary.size,i=0,a=0;this.performanceSummary.forEach((function(e){i+=e.totalTime,a+=e.count}));var c=a>0?Math.round(i/a):0,s=r>0?Math.round(n.length/r*100):100;return{totalOperations:r,averageTime:c,fastOperations:n.length,slowOperations:o.length,criticalOperations:t.length,performanceScore:s}},e.prototype.getOperationStats=function(e){var t=this.performanceSummary.get(e);if(!t)return null;var o=this.httpRequests.get(e)?[e]:[];return Object.assign(Object.assign({},t),{httpCalls:o})},e.prototype.getMonitoredOperations=function(){return Array.from(this.performanceSummary.keys())},e.prototype.hasActiveTimers=function(){return this.timerStack.length>0},e.prototype.clearActiveTimers=function(){this.performanceTimers.clear(),this.timerStack=[],this.functionContextStack=[],console.log("%c🗑️ [CLEANUP] Timers ativos limpos","color: #fff; background: #23272f; font-size: 13px; font-weight: bold; border-radius: 4px; padding: 4px 12px; margin: 6px 0;")},e.prototype.instrumentObject=function(e,t){var o=this;if(e&&"object"==typeof e){var n=Object.assign({preserveToString:!0},t),r=function(e,t,r){try{var i=e[t];if("function"!=typeof i)return;var a=i;if(a.__pm_instrumented)return;if(f=t,u=n.include,p=n.exclude,m=function(e){return"string"==typeof e?f.includes(e):e.test(f)},d=!u||u.some(m),h=!p||!p.some(m),!d||!h)return;var c=t,s=n.nameTransform?n.nameTransform(c,r):c,l=o.createWrapper(a,s,n.preserveToString);Object.defineProperty(e,t,{value:l,writable:!0,configurable:!0})}catch(e){}var f,u,p,m,d,h};Object.getOwnPropertyNames(e).forEach((function(t){return r(e,t,[t])}));var i=Object.getPrototypeOf(e);i&&i!==Object.prototype&&Object.getOwnPropertyNames(i).filter((function(e){return"constructor"!==e})).forEach((function(t){return r(e,t,[t])}))}},e.prototype.instrumentNamespace=function(e,t){var o=this;if(e&&"object"==typeof e){var n=Object.assign({preserveToString:!0,maxDepth:2},t),r=function(e){var t=n.include,o=n.exclude,r=function(t){return"string"==typeof t?e.includes(t):t.test(e)},i=!t||t.some(r),a=!o||!o.some(r);return i&&a},i=new WeakSet,a=function(e,t,c){var s,f;if(e&&"object"==typeof e&&!(i.has(e)||(i.add(e),t>(n.maxDepth||2)))){var p=[];try{p.push.apply(p,u(Object.getOwnPropertyNames(e)))}catch(e){}try{for(var m=l(p),d=m.next();!d.done;d=m.next()){var h=d.value,g=void 0;try{g=e[h]}catch(e){continue}if("function"==typeof g){var v=g;if(v.__pm_instrumented)continue;if(!r(h))continue;var y=h,b=n.nameTransform?n.nameTransform(y,c.concat(h)):y,x=o.createWrapper(v,b,n.preserveToString);try{Object.defineProperty(e,h,{value:x,writable:!0,configurable:!0})}catch(e){}}else"object"==typeof g&&g&&a(g,t+1,c.concat(h))}}catch(e){s={error:e}}finally{try{d&&!d.done&&(f=m.return)&&f.call(m)}finally{if(s)throw s.error}}}};a(e,0,[])}},e.prototype.hookSetService=function(e,t,o){var n;if(e&&"object"==typeof e){var r=e.setService;if("function"==typeof r)if(!r.__pm_setservice_hooked){var i=Object.assign({preserveToString:!0,exclude:["constructor"]},o),a=t||((null===(n=null==e?void 0:e.constructor)||void 0===n?void 0:n.name)?String(e.constructor.name):"service"),c=i.nameTransform?function(e,t){return i.nameTransform(e,[a].concat(t||[]))}:function(e){return a+"."+e},s=r,l=this,f=function(t){for(var o=[],n=1;n<arguments.length;n++)o[n-1]=arguments[n];try{var r=this||e;if(r&&"object"==typeof r){var a=r.__pm_pack_instrumented;if(!a){l.instrumentObject(r,Object.assign(Object.assign({},i),{nameTransform:c}));try{Object.defineProperty(r,"__pm_pack_instrumented",{value:!0,configurable:!0,enumerable:!1,writable:!1})}catch(e){}}}}catch(e){}return s.apply(this,u([t],o))};f.__pm_setservice_hooked=!0;try{Object.defineProperty(e,"setService",{value:f,writable:!0,configurable:!0})}catch(e){}try{var p=e;p.__pm_pack_instrumented||(this.instrumentObject(p,Object.assign(Object.assign({},i),{nameTransform:c})),Object.defineProperty(p,"__pm_pack_instrumented",{value:!0,configurable:!0,enumerable:!1,writable:!1}))}catch(e){}}}},e.prototype.hookSetServiceBulk=function(e,t){var o,n;if(e&&"object"==typeof e){var r=function(e,o){if(!(!o||"function"!=typeof o.setService))i.hookSetService(o,e,t);else if(o&&"object"==typeof o){var n=Object.assign({},t),r=n.nameTransform?function(t,o){return n.nameTransform(t,[String(e)].concat(o||[]))}:function(t){return String(e)+"."+t};i.instrumentObject(o,Object.assign(Object.assign({},n),{nameTransform:r,exclude:u(["constructor"],n.exclude||[])}))}},i=this;try{for(var a=l(Object.entries(e)),c=a.next();!c.done;c=a.next()){var s=f(c.value,2);r(s[0],s[1])}}catch(e){o={error:e}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}}},e.prototype.hookSetServiceNamespace=function(e,t){var o=this;if(e&&"object"==typeof e){var n=Object.assign({preserveToString:!0,exclude:["constructor"],maxWalkDepth:2},t),r=function(e){var t=n.includeObjects,o=n.excludeObjects,r=function(t){return"string"==typeof t?e.includes(t):t.test(e)},i=!t||t.some(r),a=!o||!o.some(r);return i&&a},i=new WeakSet,a=function(e,t,c){var s,f;if(e&&"object"==typeof e&&!(i.has(e)||(i.add(e),t>(n.maxWalkDepth||2)))){var p=[];try{p.push.apply(p,u(Object.getOwnPropertyNames(e)))}catch(e){}try{for(var m=l(p),d=m.next();!d.done;d=m.next()){var h=d.value,g=void 0;try{g=e[h]}catch(e){continue}var v=c.concat(h),y=v.join(".");if(g&&"object"==typeof g){if("function"==typeof g.setService&&r(y)){var b=n.labelFromPath||function(e){return e.join(".")};o.hookSetService(g,b(v),n)}a(g,t+1,v)}}}catch(e){s={error:e}}finally{try{d&&!d.done&&(f=m.return)&&f.call(m)}finally{if(s)throw s.error}}}};a(e,0,[])}},e.prototype.createWrapper=function(e,t,o){var n=this.instrumentedFns.get(e);if(n)return n;var r=this,i=function(){for(var o=[],n=0;n<arguments.length;n++)o[n]=arguments[n];var i=t;try{var a=String(t).split("."),c=a[a.length-1],s=a.length>1?a[0]:void 0;if(!s||s.toLowerCase()===c.toLowerCase()){var l=r.guessFileLabelFromStack();l&&(i=l+"."+c)}}catch(e){}r.startTimer(i);try{var f=e.apply(this,o);return f&&"function"==typeof f.then?f.finally((function(){r.endTimer(i)})):(r.endTimer(i),f)}catch(e){throw r.endTimer(i,"erro"),e}};if(e.__pm_instrumented=!0,i.__pm_instrumented=!0,o)try{Object.defineProperty(i,"toString",{value:function(){return e.toString()},writable:!1,configurable:!0})}catch(e){}try{Object.defineProperty(i,"name",{value:e.name||t,configurable:!0})}catch(e){}return this.instrumentedFns.set(e,i),i},e.prototype.guessFileLabelFromStack=function(){var e,t;try{var o=new Error,n=String(o.stack||"").split("\n"),r=[];try{for(var i=l(n),a=i.next();!a.done;a=i.next()){var c=a.value.match(/[\\\/]([A-Za-z0-9_-]+)\.(?:ts|js)(?::\d+:\d+|\?|$)/);if(c&&c[1]){var s=c[1];if(/^pack/i.test(s))return s;r.push(s)}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}return r[0]}catch(e){return}},e.prototype.exportData=function(){var e={timestamp:(new Date).toISOString(),serviceName:this.serviceName,statistics:this.getStatistics(),operations:Array.from(this.performanceSummary.entries()).map((function(e){var t=f(e,2),o=t[0],n=t[1];return Object.assign(Object.assign({name:o},n),{averageTime:Math.round(n.totalTime/n.count)})}))};return JSON.stringify(e,null,2)},e.prototype.calculateDynamicThresholds=function(e){return 1===e?{ok:1e3,lento:2e3,critico:2e3}:e<=5?{ok:500,lento:1e3,critico:1e3}:e<=10?{ok:100,lento:250,critico:250}:{ok:20,lento:60,critico:60}},e.prototype.injectMonitorButton=function(){var e=this;if(!document.getElementById("btn-monitorar-performance")){var t="#23272f",o="#f3f4f6",n="0 2px 12px #0002",r="1px solid #353a40",i=document.createElement("div");i.id="performance-monitor-container",Object.assign(i.style,{position:"fixed",bottom:"5px",left:"50px",zIndex:"9999",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-end",transition:"transform 0.5s cubic-bezier(.4,2,.6,1)",gap:"10px"});var a=function(e,i){var a=document.createElement("button");return a.id=e,a.innerText=i,Object.assign(a.style,{width:"210px",height:"44px",background:t,color:o,borderRadius:"8px",border:r,padding:"10px 5px",fontSize:"13px",fontWeight:"600",cursor:"pointer",boxShadow:n,letterSpacing:"0.01em",textAlign:"center",transition:"background 0.2s, color 0.2s, transform 0.5s cubic-bezier(.4,2,.6,1)"}),a.onmouseenter=function(){a.style.background="#353a40",a.style.color="#fff"},a.onmouseleave=function(){a.style.background=t,a.style.color=o},a},c=a("btn-monitorar-performance","Parar monitoramento"),s=a("btn-finalizar-monitoramento","Finalizar monitoramento"),l=a("btn-req-detalhadas-performance","Requisições detalhadas"),f=a("btn-analise-detalhada-performance","Análise detalhada"),u=a("btn-relatorio-evento-performance","Relatório separado");l.style.display="none",f.style.display="none",s.style.display="none",u.style.display="none";var p=document.createElement("button");p.id="btn-toggle-performance",p.innerHTML='\n <img\n src="https://cdn-icons-png.flaticon.com/512/565/565655.png"\n alt="esconder"\n style="width:15px; height:15px; vertical-align:middle; filter: invert(1);"\n />\n ',Object.assign(p.style,{width:"38px",height:"38px",background:"#23272f",color:"#f3f4f6",borderRadius:"50%",border:r,fontSize:"20px",fontWeight:"bold",cursor:"pointer",boxShadow:n,position:"fixed",left:"5px",bottom:"5px",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"10000"}),p.onmouseenter=function(){p.style.background="#353a40",p.style.color="#fff"},p.onmouseleave=function(){p.style.background="#23272f",p.style.color="#f3f4f6"};var m=!1;p.onclick=function(){(m=!m)?(i.style.display="none",p.innerHTML='\n <img\n src="https://cdn-icons-png.flaticon.com/512/159/159604.png"\n alt="mostrar"\n style="width:15px; height:15px; vertical-align:middle; filter: invert(1);"\n />\n '):(i.style.display="flex",p.innerHTML='\n <img\n src="https://cdn-icons-png.flaticon.com/512/565/565655.png"\n alt="esconder"\n style="width:15px; height:15px; vertical-align:middle; filter: invert(1);"\n />\n ')};var d="monitorando",h=function(t){switch(d=t){case"inativo":c.innerText="Iniciar monitoramento",e.monitoramentoAtivo=!1,s.style.display="none",l.style.display="none",f.style.display="none",u.style.display="none";break;case"monitorando":c.innerText="Parar monitoramento",e.monitoramentoAtivo=!0,s.style.display="none",l.style.display="none",f.style.display="none",u.style.display="none";break;case"relatorio":c.innerText="Gerar relatório",e.monitoramentoAtivo=!1,s.style.display="none",l.style.display="block",f.style.display="block",u.style.display="block";break;case"relatorio_gerado":c.innerText="Gerar relatório",e.monitoramentoAtivo=!1,s.style.display="block",l.style.display="block",f.style.display="block",u.style.display="block"}};c.onclick=function(){"inativo"===d?(e.resetPerformanceData(),e.showWelcomeMessage(),h("monitorando")):"monitorando"===d?h("relatorio"):"relatorio"!==d&&"relatorio_gerado"!==d||(e.showPerformanceSummary(!1),h("relatorio_gerado"))},s.onclick=function(){e.resetPerformanceData(),h("inativo")},this.showWelcomeMessage(),i.appendChild(c),i.appendChild(l),i.appendChild(u),i.appendChild(f),i.appendChild(s),document.body.appendChild(i),document.body.appendChild(p),l.onclick=function(){e.showHttpRequestsReport()},f.onclick=function(){e.generateDetailedAnalysis()},u.onclick=function(){e.showEventReport(!0)};try{var g=window;if(!g.__pm_auto_ui_listeners_added){g.__pm_auto_ui_listeners_added=!0;var v=null,y=null;["click","submit","change","keydown"].forEach((function(t){document.addEventListener(t,(function(o){var n=o.target;!function(t){v&&(clearTimeout(v),v=null),y&&(clearInterval(y),y=null),e.beginEventContext(t),e.eventContextStack.length>1||(y=setInterval((function(){var t,o,n=Date.now(),r=e.hasActiveTimers(),i=null!==(t=e.currentEventBeginAt)&&void 0!==t?t:n,a=null!==e.firstTimerInEventAt,c=n-i>2e3,s=null!==(o=e.lastTimerActivityAt)&&void 0!==o?o:i;(a&&!r&&n-s>600||!a&&c||n-i>6e4)&&(e.endEventContext(),clearInterval(y),y=null)}),250),v=setTimeout((function(){y&&(clearInterval(y),y=null),e.endEventContext(),v=null}),6e4))}("UserInput:"+t+" "+function(e,t){try{var o="undefined"!=typeof KeyboardEvent&&t instanceof KeyboardEvent&&t.key?"["+t.key+"]":"";if(!e||"object"!=typeof e)return"ui"+o;var n=(e.tagName||e.nodeName||"").toString().toLowerCase()||"element",r=e.id?"#"+e.id:"",i=("string"==typeof e.className?e.className:e.classList&&"object"==typeof e.classList&&"function"==typeof e.classList.toString?e.classList.toString():"").split(" ").filter((function(e){return e&&!e.startsWith("ng-")&&!e.startsWith("cdk-")})).slice(0,2).join("."),a=i?"."+i:"",c="button"!==n&&"a"!==n||"string"!=typeof e.innerText?"":e.innerText.trim().slice(0,30);return""+n+r+a+o+(c?':"'+c+'"':"")}catch(e){return"ui"}}(n,o))}),!0)})),this.beginEventContext("AppInit"),setTimeout((function(){return e.endEventContext()}),3e3)}}catch(e){console.warn("[PerformanceMonitor] Falha ao ativar captura automática de UI:",e)}}},e.prototype.showEventReport=function(e){var t=this;if(void 0===e&&(e=!0),console.log("%cRELATÓRIO POR EVENTO","color: #bbc7c8ff; font-size: 18px; font-weight: bold; text-shadow: 1px 1px #000; background-color: #43248bff; border-radius: 5px; padding: 10px 20px;"),0!==this.performanceSummary.size){var o=new Map;this.performanceSummary.forEach((function(e,t){var n=t.split(" | "),r=n.length>1?n[0]:"SemEvento",i=n.length>1?n.slice(1).join(" | "):t;o.has(r)||o.set(r,{totalTime:0,totalExec:0,operations:[]});var a=o.get(r);a.totalTime+=e.totalTime,a.totalExec+=e.count,a.operations.push({name:i,stats:e})}));var n=0,r=0;Array.from(o.entries()).sort((function(e,t){return t[1].totalTime-e[1].totalTime})).forEach((function(o){var i=f(o,2),a=i[0],c=i[1];n+=c.totalTime,r+=c.totalExec,console.log("%cEVENTO: "+a+" | Tempo: "+Math.round(c.totalTime)+"ms | Execuções: "+c.totalExec,"color: #fff; background: #28647b; font-size: 13px; font-weight: bold; border-radius: 4px; padding: 3px 8px;");var s=Object.fromEntries(c.operations.sort((function(e,t){return t.stats.totalTime-e.stats.totalTime})).map((function(e){var o=e.name,n=e.stats,r=Math.round(n.totalTime/n.count),i=t.getPerformanceStatus(r,n.customThresholds,o),a=i.emoji,c=i.status;return[o,{"Execuções":n.count,"Média(ms)":(r+"ms ("+c+") "+a).trim(),"Mínimo(ms)":n.minTime,"Máximo(ms)":n.maxTime,"Total(ms)":Math.round(n.totalTime)}]})));if(console.table(s),e){var l={};t.httpRequests.forEach((function(e,t){var o=t.split(" | "),n=o.length>1?o[0]:"SemEvento",r=o.length>1?o.slice(1).join(" | "):t;n===a&&(l[r]={"Execuções":e.execucoes,"Média":Math.round(e.tempoTotal/Math.max(e.execucoes,1))+"ms","Tempo Total":Math.round(e.tempoTotal)+"ms",Erros:e.errors})})),Object.keys(l).length>0&&(console.log("%cHTTP ("+a+")","color: #fff; background: #28336b; font-size: 12px; font-weight: bold; border-radius: 4px; padding: 2px 8px;"),console.table(l))}})),console.log("%cTOTAL GERAL: "+Math.round(n)+"ms | Execuções: "+r,"color: #fff; background: #43248bff; font-size: 14px; font-weight: bold; border-radius: 4px; padding: 4px 12px; margin-top: 8px;")}else console.log("Nenhuma operação monitorada ainda.")},e}();function m(e){return void 0===e&&(e="Service"),new p(e)}var d=m("GLOBAL");var h=function(){function e(){}return e.prototype.intercept=function(e,t){var r;if(!e.url.startsWith("./assets")){var i=sessionStorage.getItem("idTela");i||(i="SEL041",sessionStorage.setItem("idTela",i));var a=null!==(r=sessionStorage.getItem("cdUsuario"))&&void 0!==r?r:"",c=e.clone({headers:e.headers.set("tela_id",i).set("tela","SEL041").set("user",a)}),s=performance.now();return t.handle(c).pipe(n.tap({next:function(e){var t,n;if(e instanceof o.HttpResponse){var r=performance.now()-s,i=(null===(t=c.body)||void 0===t?void 0:t.operationType)||"UNKNOWN",a=(null===(n=c.body)||void 0===n?void 0:n.name)||"";console.log("%c🟢 [HTTP] "+i+" "+("SELECT_FULL"===i?"":a)+" - "+r.toFixed(1)+"ms","color: #7048cfff; font-weight: bold;"),d.registerHttpRequest(c,r,!1)}},error:function(e){var t,o,n=performance.now()-s,r=(null===(t=c.body)||void 0===t?void 0:t.operationType)||"UNKNOWN",i=(null===(o=c.body)||void 0===o?void 0:o.name)||"";console.groupCollapsed("%c🔴 [HTTP] "+r+" "+i+" - "+n.toFixed(1)+"ms","color: #7048cfff; font-weight: bold;"),console.error(e),console.groupEnd(),d.registerHttpRequest(c,n,!0)}}))}return t.handle(e)},e}();h.decorators=[{type:t.Injectable}],e.GlobalPerformanceLogger=d,e.PerformanceMonitor=function(e){return function(t,o,n){var r,i;if(o||n){if(n){var a,c,s,f,u=n.value;if("object"!=typeof e||null===e||"exclude"in e||"prefix"in e)"function"==typeof e?(a=e.name||o,c=e):a="string"==typeof e?e:o;else a=(p=e).name||o,c=p.method,s={ok:p.ok,lento:p.lento,critico:p.critico},f=p.event;return n.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var o=this.performanceLogger,n=o||d;if(n){f&&n.beginEventContext(f),n.startTimer(a);var r=void 0;try{r=(c||u).apply(this,e)}catch(e){throw n.endTimer(a,void 0,s),f&&n.endEventContext(),e}return r&&"function"==typeof r.then?r.then((function(e){return n.endTimer(a,void 0,s),f&&n.endEventContext(),e})).catch((function(e){throw n.endTimer(a,void 0,s),f&&n.endEventContext(),e})):(n.endTimer(a,void 0,s),f&&n.endEventContext(),r)}return(c||u).apply(this,e)},n}}else{var p,m=t,h="object"==typeof(p=e)&&(null==p?void 0:p.exclude)||[],g="object"==typeof p&&(null==p?void 0:p.prefix)||"",v=function(e){if("constructor"===e||h.includes(e))return"continue";var t=Object.getOwnPropertyDescriptor(m.prototype,e);if(t&&"function"==typeof t.value){var o=t.value,n=g?g+"."+e:e;t.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r,i=this.performanceLogger,a=i||d;if(!a)return o.apply(this,e);a.startTimer(n);try{r=o.apply(this,e)}catch(e){throw a.endTimer(n),e}return r&&"function"==typeof r.then?r.then((function(e){return a.endTimer(n),e})).catch((function(e){throw a.endTimer(n),e})):(a.endTimer(n),r)},Object.defineProperty(m.prototype,e,t)}};try{for(var y=l(Object.getOwnPropertyNames(m.prototype)),b=y.next();!b.done;b=y.next()){v(b.value)}}catch(e){r={error:e}}finally{try{b&&!b.done&&(i=y.return)&&i.call(y)}finally{if(r)throw r.error}}}}},e.PerformanceMonitorComponent=r,e.PerformanceMonitorInterceptor=h,e.PerformanceMonitorModule=i,e.PerformanceMonitorService=a,e.ɵa=p,e.ɵb=m,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=performance-monitor-logger.umd.min.js.map