1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 #include "trace.hxx" 27 #include <tools/debug.hxx> 28 29 #if defined(DBG_UTIL) 30 31 //============================================================================== 32 33 //------------------------------------------------------------------------------ 34 ::vos::OMutex Tracer::s_aMapSafety; 35 ::std::map< ::vos::OThread::TThreadIdentifier, sal_Int32, ::std::less< ::vos::OThread::TThreadIdentifier > > 36 Tracer::s_aThreadIndents; 37 38 //------------------------------------------------------------------------------ 39 Tracer::Tracer(const char* _pBlockDescription) 40 :m_sBlockDescription(_pBlockDescription) 41 { 42 ::vos::OGuard aGuard(s_aMapSafety); 43 sal_Int32 nIndent = s_aThreadIndents[ ::vos::OThread::getCurrentIdentifier() ]++; 44 45 ByteString sIndent; 46 while (nIndent--) 47 sIndent += '\t'; 48 49 ByteString sThread( ByteString::CreateFromInt32( (sal_Int32)::vos::OThread::getCurrentIdentifier() ) ); 50 sThread += '\t'; 51 52 ByteString sMessage(sThread); 53 sMessage += sIndent; 54 sMessage += m_sBlockDescription; 55 sMessage += " {"; 56 DBG_TRACE(sMessage.GetBuffer()); 57 } 58 59 //------------------------------------------------------------------------------ 60 Tracer::~Tracer() 61 { 62 ::vos::OGuard aGuard(s_aMapSafety); 63 sal_Int32 nIndent = --s_aThreadIndents[ ::vos::OThread::getCurrentIdentifier() ]; 64 65 ByteString sIndent; 66 while (nIndent--) 67 sIndent += '\t'; 68 69 ByteString sThread( ByteString::CreateFromInt32( (sal_Int32)::vos::OThread::getCurrentIdentifier() ) ); 70 sThread += '\t'; 71 72 ByteString sMessage(sThread); 73 sMessage += sIndent; 74 sMessage += "} // "; 75 sMessage += m_sBlockDescription; 76 DBG_TRACE(sMessage.GetBuffer()); 77 } 78 79 //------------------------------------------------------------------------------ 80 void Tracer::TraceString(const char* _pMessage) 81 { 82 ::vos::OGuard aGuard(s_aMapSafety); 83 sal_Int32 nIndent = s_aThreadIndents[ ::vos::OThread::getCurrentIdentifier() ]; 84 85 ByteString sIndent; 86 while (nIndent--) 87 sIndent += '\t'; 88 89 ByteString sThread( ByteString::CreateFromInt32( (sal_Int32)::vos::OThread::getCurrentIdentifier() ) ); 90 sThread += '\t'; 91 92 ByteString sMessage(sThread); 93 sMessage += sIndent; 94 sMessage += m_sBlockDescription; 95 sMessage += ": "; 96 sMessage += _pMessage; 97 DBG_TRACE(sMessage.GetBuffer()); 98 } 99 100 //------------------------------------------------------------------------------ 101 void Tracer::TraceString1StringParam(const char* _pMessage, const char* _pParam) 102 { 103 ::vos::OGuard aGuard(s_aMapSafety); 104 sal_Int32 nIndent = s_aThreadIndents[ ::vos::OThread::getCurrentIdentifier() ]; 105 106 ByteString sIndent; 107 while (nIndent--) 108 sIndent += '\t'; 109 110 ByteString sThread( ByteString::CreateFromInt32( (sal_Int32)::vos::OThread::getCurrentIdentifier() ) ); 111 sThread += '\t'; 112 113 ByteString sMessage(sThread); 114 sMessage += sIndent; 115 sMessage += m_sBlockDescription; 116 sMessage += ": "; 117 sMessage += _pMessage; 118 DBG_TRACE1(sMessage.GetBuffer(), _pParam); 119 } 120 #endif 121