Commit 572912a30ee440a84b3fad2627e1348f5a07f59a
1 parent
15823b63
Exists in
desenv
Registro de tempo em logs de debug
Showing
2 changed files
with
48 additions
and
14 deletions
Show diff stats
rn/ProcessarPendenciasRN.php
| @@ -101,7 +101,9 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa | @@ -101,7 +101,9 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa | ||
| 101 | //Processamento de pendências de recebimento dos metadados do processo | 101 | //Processamento de pendências de recebimento dos metadados do processo |
| 102 | $this->objGearmanWorker->addFunction("receberProcedimento", function ($job) { | 102 | $this->objGearmanWorker->addFunction("receberProcedimento", function ($job) { |
| 103 | try{ | 103 | try{ |
| 104 | - $this->gravarLogDebug("Processando recebimento de processo [receberProcedimento] com IDT " . $job->workload(), 0, true); | 104 | + $this->gravarLogDebug("Processando recebimento de protocolo [receberProcedimento] com IDT " . $job->workload(), 0, true); |
| 105 | + $numTempoInicialRecebimento = microtime(true); | ||
| 106 | + | ||
| 105 | $numIdentificacaoTramite = intval($job->workload()); | 107 | $numIdentificacaoTramite = intval($job->workload()); |
| 106 | $objPenTramiteProcessadoRN = new PenTramiteProcessadoRN(PenTramiteProcessadoRN::STR_TIPO_PROCESSO); | 108 | $objPenTramiteProcessadoRN = new PenTramiteProcessadoRN(PenTramiteProcessadoRN::STR_TIPO_PROCESSO); |
| 107 | 109 | ||
| @@ -109,6 +111,10 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa | @@ -109,6 +111,10 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa | ||
| 109 | $objReceberProcedimentoRN = new ReceberProcedimentoRN(); | 111 | $objReceberProcedimentoRN = new ReceberProcedimentoRN(); |
| 110 | $objReceberProcedimentoRN->receberProcedimento($numIdentificacaoTramite); | 112 | $objReceberProcedimentoRN->receberProcedimento($numIdentificacaoTramite); |
| 111 | } | 113 | } |
| 114 | + | ||
| 115 | + $numTempoTotalRecebimento = round(microtime(true) - $numTempoInicialRecebimento, 2); | ||
| 116 | + $this->gravarLogDebug("Finalizado o recebimento de protocolo com IDT " . $job->workload() . "(Tempo total: {$numTempoTotalRecebimento}s)", 0, true); | ||
| 117 | + | ||
| 112 | } | 118 | } |
| 113 | catch(Exception $e){ | 119 | catch(Exception $e){ |
| 114 | $this->gravarLogDebug(InfraException::inspecionar($e), 0, true); | 120 | $this->gravarLogDebug(InfraException::inspecionar($e), 0, true); |
rn/ReceberProcedimentoRN.php
| @@ -18,6 +18,8 @@ class ReceberProcedimentoRN extends InfraRN | @@ -18,6 +18,8 @@ class ReceberProcedimentoRN extends InfraRN | ||
| 18 | $this->objProcessoEletronicoRN = new ProcessoEletronicoRN(); | 18 | $this->objProcessoEletronicoRN = new ProcessoEletronicoRN(); |
| 19 | $this->objProcedimentoAndamentoRN = new ProcedimentoAndamentoRN(); | 19 | $this->objProcedimentoAndamentoRN = new ProcedimentoAndamentoRN(); |
| 20 | $this->objReceberComponenteDigitalRN = new ReceberComponenteDigitalRN(); | 20 | $this->objReceberComponenteDigitalRN = new ReceberComponenteDigitalRN(); |
| 21 | + | ||
| 22 | + $this->numTempoUltimoLog = null; | ||
| 21 | } | 23 | } |
| 22 | 24 | ||
| 23 | protected function inicializarObjInfraIBanco() | 25 | protected function inicializarObjInfraIBanco() |
| @@ -110,21 +112,34 @@ class ReceberProcedimentoRN extends InfraRN | @@ -110,21 +112,34 @@ class ReceberProcedimentoRN extends InfraRN | ||
| 110 | 112 | ||
| 111 | $numOrdemComponente = $key + 1; | 113 | $numOrdemComponente = $key + 1; |
| 112 | if(!is_null($componentePendente)){ | 114 | if(!is_null($componentePendente)){ |
| 113 | - //TODO: Necessário otimizar trecho abaixo para evitar download desnecessário de documentos | ||
| 114 | - //TODO: Download do componente digital é realizado, mesmo já existindo na base de dados, devido a comportamento obrigatório do Barramento para mudança de status | 115 | + //Download do componente digital é realizado, mesmo já existindo na base de dados, devido a comportamento obrigatório do Barramento para mudança de status |
| 115 | //Ajuste deverá ser feito em versões futuas | 116 | //Ajuste deverá ser feito em versões futuas |
| 116 | $arrayHash[] = $componentePendente; | 117 | $arrayHash[] = $componentePendente; |
| 117 | 118 | ||
| 118 | //Obter os dados do componente digital | 119 | //Obter os dados do componente digital |
| 119 | $this->gravarLogDebug("Baixando componente digital $numOrdemComponente", 6); | 120 | $this->gravarLogDebug("Baixando componente digital $numOrdemComponente", 6); |
| 121 | + $numTempoInicialDownload = microtime(true); | ||
| 120 | $objComponenteDigital = $this->objProcessoEletronicoRN->receberComponenteDigital($parNumIdentificacaoTramite, $componentePendente, $objTramite->protocolo); | 122 | $objComponenteDigital = $this->objProcessoEletronicoRN->receberComponenteDigital($parNumIdentificacaoTramite, $componentePendente, $objTramite->protocolo); |
| 123 | + $numTempoTotalDownload = round(microtime(true) - $numTempoInicialDownload, 2); | ||
| 124 | + $numTamanhoArquivoKB = round(strlen($objComponenteDigital->conteudoDoComponenteDigital) / 1024, 2); | ||
| 125 | + $numVelocidade = round($numTamanhoArquivoKB / $numTempoTotalDownload, 2); | ||
| 126 | + $this->gravarLogDebug("Tempo total de download de $numTamanhoArquivoKB kb: {$numTempoTotalDownload}s ({$numVelocidade} kb/s)", 7); | ||
| 127 | + | ||
| 128 | + $numTempoInicialArmazenamento = microtime(true); | ||
| 121 | $arrAnexosComponentes[$key][$componentePendente] = $this->objReceberComponenteDigitalRN->copiarComponenteDigitalPastaTemporaria($objComponenteDigital); | 129 | $arrAnexosComponentes[$key][$componentePendente] = $this->objReceberComponenteDigitalRN->copiarComponenteDigitalPastaTemporaria($objComponenteDigital); |
| 122 | $arrAnexosComponentes[$key]['recebido'] = false; | 130 | $arrAnexosComponentes[$key]['recebido'] = false; |
| 131 | + $numTempoTotalArmazenamento = round(microtime(true) - $numTempoInicialArmazenamento, 2); | ||
| 132 | + $numVelocidade = round($numTamanhoArquivoKB / $numTempoTotalArmazenamento, 2); | ||
| 133 | + $this->gravarLogDebug("Tempo total de armazenamento em disco: {$numTempoTotalArmazenamento}s ({$numVelocidade} kb/s)", 7); | ||
| 123 | 134 | ||
| 124 | //Valida a integridade do hash | 135 | //Valida a integridade do hash |
| 125 | - $this->gravarLogDebug("Validando integridade de componente digital $numOrdemComponente", 6); | 136 | + $this->gravarLogDebug("Validando integridade de componente digital $numOrdemComponente", 7); |
| 137 | + $numTempoInicialValidacao = microtime(true); | ||
| 126 | $this->objReceberComponenteDigitalRN->validarIntegridadeDoComponenteDigital($arrAnexosComponentes[$key][$componentePendente], | 138 | $this->objReceberComponenteDigitalRN->validarIntegridadeDoComponenteDigital($arrAnexosComponentes[$key][$componentePendente], |
| 127 | $componentePendente, $parNumIdentificacaoTramite, $numOrdemComponente); | 139 | $componentePendente, $parNumIdentificacaoTramite, $numOrdemComponente); |
| 140 | + $numTempoTotalValidacao = round(microtime(true) - $numTempoInicialValidacao, 2); | ||
| 141 | + $numVelocidade = round($numTamanhoArquivoKB / $numTempoTotalValidacao, 2); | ||
| 142 | + $this->gravarLogDebug("Tempo total de validação de integridade: {$numTempoTotalValidacao}s ({$numVelocidade} kb/s)", 7); | ||
| 128 | } | 143 | } |
| 129 | } | 144 | } |
| 130 | 145 | ||
| @@ -212,7 +227,7 @@ class ReceberProcedimentoRN extends InfraRN | @@ -212,7 +227,7 @@ class ReceberProcedimentoRN extends InfraRN | ||
| 212 | { | 227 | { |
| 213 | if(count($parArrHashComponentes) > 0){ | 228 | if(count($parArrHashComponentes) > 0){ |
| 214 | //Obter dados dos componetes digitais | 229 | //Obter dados dos componetes digitais |
| 215 | - $this->gravarLogDebug("Iniciando o recebimento dos componentes digitais pendentes", 4); | 230 | + $this->gravarLogDebug("Iniciando o armazenamento dos componentes digitais pendentes", 4); |
| 216 | $objComponenteDigitalDTO = new ComponenteDigitalDTO(); | 231 | $objComponenteDigitalDTO = new ComponenteDigitalDTO(); |
| 217 | $objComponenteDigitalDTO->setStrNumeroRegistro($parStrNumeroRegistro); | 232 | $objComponenteDigitalDTO->setStrNumeroRegistro($parStrNumeroRegistro); |
| 218 | $objComponenteDigitalDTO->setNumIdTramite($parNumIdentificacaoTramite); | 233 | $objComponenteDigitalDTO->setNumIdTramite($parNumIdentificacaoTramite); |
| @@ -246,7 +261,7 @@ class ReceberProcedimentoRN extends InfraRN | @@ -246,7 +261,7 @@ class ReceberProcedimentoRN extends InfraRN | ||
| 246 | if($this->documentosPendenteRegistro($dblIdProcedimento, $dblIdDocumento, $strHash)){ | 261 | if($this->documentosPendenteRegistro($dblIdProcedimento, $dblIdDocumento, $strHash)){ |
| 247 | $strNomeDocumento = array_key_exists($strHash, $arrStrNomeDocumento) ? $arrStrNomeDocumento[$strHash]['especieNome'] : '[Desconhecido]'; | 262 | $strNomeDocumento = array_key_exists($strHash, $arrStrNomeDocumento) ? $arrStrNomeDocumento[$strHash]['especieNome'] : '[Desconhecido]'; |
| 248 | $this->objReceberComponenteDigitalRN->receberComponenteDigital($objComponenteDigitalDTOEnviado); | 263 | $this->objReceberComponenteDigitalRN->receberComponenteDigital($objComponenteDigitalDTOEnviado); |
| 249 | - $strMensagemRecebimento = sprintf('Recebendo %s %s', $strNomeDocumento, $objComponenteDigitalDTOEnviado->getStrProtocoloDocumentoFormatado()); | 264 | + $strMensagemRecebimento = sprintf('Armazenando componente do documento %s %s', $strNomeDocumento, $objComponenteDigitalDTOEnviado->getStrProtocoloDocumentoFormatado()); |
| 250 | $this->objProcedimentoAndamentoRN->cadastrar(ProcedimentoAndamentoDTO::criarAndamento($strMensagemRecebimento, 'S')); | 265 | $this->objProcedimentoAndamentoRN->cadastrar(ProcedimentoAndamentoDTO::criarAndamento($strMensagemRecebimento, 'S')); |
| 251 | $this->gravarLogDebug($strMensagemRecebimento, 6); | 266 | $this->gravarLogDebug($strMensagemRecebimento, 6); |
| 252 | } | 267 | } |
| @@ -1846,14 +1861,6 @@ class ReceberProcedimentoRN extends InfraRN | @@ -1846,14 +1861,6 @@ class ReceberProcedimentoRN extends InfraRN | ||
| 1846 | return $objProcedimentoAndamentoDTO; | 1861 | return $objProcedimentoAndamentoDTO; |
| 1847 | } | 1862 | } |
| 1848 | 1863 | ||
| 1849 | - private function gravarLogDebug($strMensagem, $numIdentacao=0) | ||
| 1850 | - { | ||
| 1851 | - $strDataLog = date("d/m/Y H:i:s"); | ||
| 1852 | - $strLog = sprintf("[%s] [PROCESSAMENTO] %s %s", $strDataLog, str_repeat(" ", $numIdentacao * 4), $strMensagem); | ||
| 1853 | - InfraDebug::getInstance()->gravar($strLog); | ||
| 1854 | - } | ||
| 1855 | - | ||
| 1856 | - | ||
| 1857 | /** | 1864 | /** |
| 1858 | * Verifica se existe documentos com pendência de download de seus componentes digitais | 1865 | * Verifica se existe documentos com pendência de download de seus componentes digitais |
| 1859 | * @param [type] $parNumIdProcedimento Identificador do processo | 1866 | * @param [type] $parNumIdProcedimento Identificador do processo |
| @@ -1928,4 +1935,25 @@ class ReceberProcedimentoRN extends InfraRN | @@ -1928,4 +1935,25 @@ class ReceberProcedimentoRN extends InfraRN | ||
| 1928 | throw new InfraException($strMensagemPadrao . $strMensagemErro); | 1935 | throw new InfraException($strMensagemPadrao . $strMensagemErro); |
| 1929 | } | 1936 | } |
| 1930 | } | 1937 | } |
| 1938 | + | ||
| 1939 | + private function gravarLogDebug($strMensagem, $numIdentacao=0, $bolLogTempoProcessamento=true) | ||
| 1940 | + { | ||
| 1941 | + $strDataLog = date("d/m/Y H:i:s"); | ||
| 1942 | + $strLog = sprintf("[%s] [PROCESSAMENTO] %s %s", $strDataLog, str_repeat(" ", $numIdentacao * 4), $strMensagem); | ||
| 1943 | + | ||
| 1944 | + //Registro de tempo de processamento desde último log | ||
| 1945 | + if($bolLogTempoProcessamento){ | ||
| 1946 | + $numTempoFinal = microtime(true); | ||
| 1947 | + if(is_null($this->numTempoUltimoLog)){ | ||
| 1948 | + //Inicializa contador de tempo de processamento | ||
| 1949 | + $this->numTempoUltimoLog = $numTempoFinal; | ||
| 1950 | + } else { | ||
| 1951 | + $numTempoProcessamento = round($numTempoFinal - $this->numTempoUltimoLog, 2); | ||
| 1952 | + $strLog .= " [tempo: +{$numTempoProcessamento}s]"; | ||
| 1953 | + $this->numTempoUltimoLog = $numTempoFinal; | ||
| 1954 | + } | ||
| 1955 | + } | ||
| 1956 | + | ||
| 1957 | + InfraDebug::getInstance()->gravar($strLog); | ||
| 1958 | + } | ||
| 1931 | } | 1959 | } |