1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_testtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdio.h> 32*cdf0e10cSrcweir #include <math.h> 33*cdf0e10cSrcweir #include <string> 34*cdf0e10cSrcweir #include <hash_map> 35*cdf0e10cSrcweir #include <map> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <osl/diagnose.h> 38*cdf0e10cSrcweir #include <osl/mutex.hxx> 39*cdf0e10cSrcweir #include <osl/module.h> 40*cdf0e10cSrcweir #include <osl/process.h> 41*cdf0e10cSrcweir #include <osl/thread.h> 42*cdf0e10cSrcweir #include <osl/conditn.hxx> 43*cdf0e10cSrcweir #include <osl/time.h> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #ifdef SAL_W32 46*cdf0e10cSrcweir #include <windows.h> 47*cdf0e10cSrcweir #else 48*cdf0e10cSrcweir #include <sys/times.h> 49*cdf0e10cSrcweir #include <unistd.h> 50*cdf0e10cSrcweir #endif 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <rtl/string.hxx> 53*cdf0e10cSrcweir #include <rtl/strbuf.hxx> 54*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include <uno/environment.hxx> 57*cdf0e10cSrcweir #include <uno/mapping.hxx> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 60*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/lang/XMain.hpp> 65*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 66*cdf0e10cSrcweir #include <com/sun/star/loader/XImplementationLoader.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/bridge/XUnoUrlResolver.hpp> 69*cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp> 70*cdf0e10cSrcweir #include <com/sun/star/test/performance/XPerformanceTest.hpp> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #define NLOOP 200000000 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir using namespace rtl; 75*cdf0e10cSrcweir using namespace osl; 76*cdf0e10cSrcweir using namespace cppu; 77*cdf0e10cSrcweir using namespace com::sun::star::uno; 78*cdf0e10cSrcweir using namespace com::sun::star::lang; 79*cdf0e10cSrcweir using namespace com::sun::star::loader; 80*cdf0e10cSrcweir using namespace com::sun::star::registry; 81*cdf0e10cSrcweir using namespace com::sun::star::bridge; 82*cdf0e10cSrcweir using namespace com::sun::star::container; 83*cdf0e10cSrcweir using namespace com::sun::star::test::performance; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir #define SERVICENAME "com.sun.star.test.performance.PerformanceTest" 86*cdf0e10cSrcweir #define IMPLNAME "com.sun.star.comp.performance.PerformanceTest" 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir namespace benchmark_test 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir static inline sal_uInt32 getSystemTicks() 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir #ifdef SAL_W32 94*cdf0e10cSrcweir return (sal_uInt32)GetTickCount(); 95*cdf0e10cSrcweir #else // only UNX supported for now 96*cdf0e10cSrcweir static sal_uInt32 nImplTicksPerSecond = 0; 97*cdf0e10cSrcweir static double dImplTicksPerSecond; 98*cdf0e10cSrcweir static double dImplTicksULONGMAX; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir struct tms aTms; 101*cdf0e10cSrcweir sal_uInt32 nTicks = (sal_uInt32)times( &aTms ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir if ( !nImplTicksPerSecond ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir nImplTicksPerSecond = sysconf(_SC_CLK_TCK); 106*cdf0e10cSrcweir dImplTicksPerSecond = nImplTicksPerSecond; 107*cdf0e10cSrcweir dImplTicksULONGMAX = (double)(sal_uInt32)ULONG_MAX; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir double fTicks = nTicks; 111*cdf0e10cSrcweir fTicks *= 1000; 112*cdf0e10cSrcweir fTicks /= dImplTicksPerSecond; 113*cdf0e10cSrcweir fTicks = fmod (fTicks, dImplTicksULONGMAX); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir return (sal_uInt32)fTicks; 116*cdf0e10cSrcweir #endif 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 120*cdf0e10cSrcweir static void out( const sal_Char * pText, FILE * stream = stderr, 121*cdf0e10cSrcweir sal_Int32 nStart = -1, sal_Char cFillchar = ' ' ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir static sal_Int32 s_nPos = 0; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir sal_Char ar[2] = { cFillchar, 0 }; 126*cdf0e10cSrcweir while (s_nPos < nStart) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir ::fprintf( stream, ar ); 129*cdf0e10cSrcweir ++s_nPos; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir ::fprintf( stream, pText ); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir for ( const sal_Char * p = pText; *p; ++p ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir if (*p == '\n') 137*cdf0e10cSrcweir s_nPos = 0; 138*cdf0e10cSrcweir else 139*cdf0e10cSrcweir ++s_nPos; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 143*cdf0e10cSrcweir static inline void out( const OUString & rText, FILE * stream = stderr, 144*cdf0e10cSrcweir sal_Int32 nStart = -1, sal_Char cFillchar = ' ' ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir OString aText( OUStringToOString( rText, RTL_TEXTENCODING_ASCII_US ) ); 147*cdf0e10cSrcweir out( aText.getStr(), stream, nStart, cFillchar ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 150*cdf0e10cSrcweir static inline void out( double fVal, FILE * stream = stderr, 151*cdf0e10cSrcweir sal_Int32 nStart = -1, sal_Char cFillchar = ' ' ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir sal_Char ar[128]; 154*cdf0e10cSrcweir ::snprintf( ar, sizeof(ar), (fVal < 0.000001 ? "%g" : "%f"), fVal ); 155*cdf0e10cSrcweir out( ar, stream, nStart, cFillchar ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 158*cdf0e10cSrcweir static inline void out( sal_Int64 nVal, FILE * stream = stderr, 159*cdf0e10cSrcweir sal_Int32 nStart = -1, sal_Char cFillchar = ' ' ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir sal_Char ar[128]; 162*cdf0e10cSrcweir ::snprintf( ar, sizeof(ar), "%ld", nVal ); 163*cdf0e10cSrcweir out( ar, stream, nStart, cFillchar ); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir //================================================================================================== 167*cdf0e10cSrcweir Reference< XSingleServiceFactory > loadLibComponentFactory( 168*cdf0e10cSrcweir const OUString & rLibName, const OUString & rImplName, 169*cdf0e10cSrcweir const Reference< XMultiServiceFactory > & xSF, const Reference< XRegistryKey > & xKey ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir Reference< XSingleServiceFactory > xRet; 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir OUStringBuffer aLibNameBuf( 32 ); 174*cdf0e10cSrcweir #ifdef SAL_UNX 175*cdf0e10cSrcweir aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM("lib") ); 176*cdf0e10cSrcweir aLibNameBuf.append( rLibName ); 177*cdf0e10cSrcweir aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM(".so") ); 178*cdf0e10cSrcweir #else 179*cdf0e10cSrcweir aLibNameBuf.append( rLibName ); 180*cdf0e10cSrcweir aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM(".dll") ); 181*cdf0e10cSrcweir #endif 182*cdf0e10cSrcweir OUString aLibName( aLibNameBuf.makeStringAndClear() ); 183*cdf0e10cSrcweir oslModule lib = osl_loadModule( aLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir if (lib) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir void * pSym; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // ========================= LATEST VERSION ========================= 190*cdf0e10cSrcweir OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) ); 191*cdf0e10cSrcweir if (pSym = osl_getSymbol( lib, aGetEnvName.pData )) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir uno_Environment * pCurrentEnv = 0; 194*cdf0e10cSrcweir uno_Environment * pEnv = 0; 195*cdf0e10cSrcweir const sal_Char * pEnvTypeName = 0; 196*cdf0e10cSrcweir (*((component_getImplementationEnvironmentFunc)pSym))( &pEnvTypeName, &pEnv ); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir sal_Bool bNeedsMapping = 199*cdf0e10cSrcweir (pEnv || 0 != rtl_str_compare( pEnvTypeName, CPPU_CURRENT_LANGUAGE_BINDING_NAME )); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) ); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if (bNeedsMapping) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir if (! pEnv) 206*cdf0e10cSrcweir uno_getEnvironment( &pEnv, aEnvTypeName.pData, 0 ); 207*cdf0e10cSrcweir if (pEnv) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); 210*cdf0e10cSrcweir uno_getEnvironment( &pCurrentEnv, aCppEnvTypeName.pData, 0 ); 211*cdf0e10cSrcweir if (pCurrentEnv) 212*cdf0e10cSrcweir bNeedsMapping = (pEnv != pCurrentEnv); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETFACTORY) ); 217*cdf0e10cSrcweir if (pSym = osl_getSymbol( lib, aGetFactoryName.pData )) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir OString aImplName( OUStringToOString( rImplName, RTL_TEXTENCODING_ASCII_US ) ); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if (bNeedsMapping) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir if (pEnv && pCurrentEnv) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir Mapping aCurrent2Env( pCurrentEnv, pEnv ); 226*cdf0e10cSrcweir Mapping aEnv2Current( pEnv, pCurrentEnv ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir if (aCurrent2Env.is() && aEnv2Current.is()) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir void * pSMgr = aCurrent2Env.mapInterface( 231*cdf0e10cSrcweir xSF.get(), ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) ); 232*cdf0e10cSrcweir void * pKey = aCurrent2Env.mapInterface( 233*cdf0e10cSrcweir xKey.get(), ::getCppuType( (const Reference< XRegistryKey > *)0 ) ); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir void * pSSF = (*((component_getFactoryFunc)pSym))( 236*cdf0e10cSrcweir aImplName.getStr(), pSMgr, pKey ); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir if (pKey) 239*cdf0e10cSrcweir (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pKey ); 240*cdf0e10cSrcweir if (pSMgr) 241*cdf0e10cSrcweir (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSMgr ); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir if (pSSF) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir aEnv2Current.mapInterface( 246*cdf0e10cSrcweir reinterpret_cast< void ** >( &xRet ), 247*cdf0e10cSrcweir pSSF, ::getCppuType( (const Reference< XSingleServiceFactory > *)0 ) ); 248*cdf0e10cSrcweir (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSSF ); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir else 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir XSingleServiceFactory * pRet = (XSingleServiceFactory *) 256*cdf0e10cSrcweir (*((component_getFactoryFunc)pSym))( 257*cdf0e10cSrcweir aImplName.getStr(), xSF.get(), xKey.get() ); 258*cdf0e10cSrcweir if (pRet) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir xRet = pRet; 261*cdf0e10cSrcweir pRet->release(); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir if (pEnv) 267*cdf0e10cSrcweir (*pEnv->release)( pEnv ); 268*cdf0e10cSrcweir if (pCurrentEnv) 269*cdf0e10cSrcweir (*pCurrentEnv->release)( pCurrentEnv ); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir // ========================= PREVIOUS VERSION ========================= 273*cdf0e10cSrcweir else 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(CREATE_COMPONENT_FACTORY_FUNCTION) ); 276*cdf0e10cSrcweir if (pSym = osl_getSymbol( lib, aGetFactoryName.pData )) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); 279*cdf0e10cSrcweir OUString aUnoEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ); 280*cdf0e10cSrcweir Mapping aUno2Cpp( aUnoEnvTypeName, aCppEnvTypeName ); 281*cdf0e10cSrcweir Mapping aCpp2Uno( aCppEnvTypeName, aUnoEnvTypeName ); 282*cdf0e10cSrcweir OSL_ENSURE( aUno2Cpp.is() && aCpp2Uno.is(), "### cannot get uno mappings!" ); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir if (aUno2Cpp.is() && aCpp2Uno.is()) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir uno_Interface * pUComponentFactory = 0; 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir uno_Interface * pUSFactory = (uno_Interface *)aCpp2Uno.mapInterface( 289*cdf0e10cSrcweir xSF.get(), ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) ); 290*cdf0e10cSrcweir uno_Interface * pUKey = (uno_Interface *)aCpp2Uno.mapInterface( 291*cdf0e10cSrcweir xKey.get(), ::getCppuType( (const Reference< XRegistryKey > *)0 ) ); 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir pUComponentFactory = (*((CreateComponentFactoryFunc)pSym))( 294*cdf0e10cSrcweir rImplName.getStr(), pUSFactory, pUKey ); 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir if (pUKey) 297*cdf0e10cSrcweir (*pUKey->release)( pUKey ); 298*cdf0e10cSrcweir if (pUSFactory) 299*cdf0e10cSrcweir (*pUSFactory->release)( pUSFactory ); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir if (pUComponentFactory) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir XSingleServiceFactory * pXFactory = 304*cdf0e10cSrcweir (XSingleServiceFactory *)aUno2Cpp.mapInterface( 305*cdf0e10cSrcweir pUComponentFactory, ::getCppuType( (const Reference< XSingleServiceFactory > *)0 ) ); 306*cdf0e10cSrcweir (*pUComponentFactory->release)( pUComponentFactory ); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir if (pXFactory) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir xRet = pXFactory; 311*cdf0e10cSrcweir pXFactory->release(); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir if (! xRet.is()) 319*cdf0e10cSrcweir osl_unloadModule( lib ); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir return xRet; 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 325*cdf0e10cSrcweir template< class T > 326*cdf0e10cSrcweir static void createInstance( Reference< T > & rxOut, 327*cdf0e10cSrcweir const Reference< XMultiServiceFactory > & xMgr, 328*cdf0e10cSrcweir const OUString & rServiceName ) 329*cdf0e10cSrcweir throw (RuntimeException) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir Reference< XInterface > x( xMgr->createInstance( rServiceName ), UNO_QUERY ); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir if (! x.is()) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir static sal_Bool s_bSet = sal_False; 336*cdf0e10cSrcweir if (! s_bSet) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 339*cdf0e10cSrcweir if (! s_bSet) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir Reference< XSet > xSet( xMgr, UNO_QUERY ); 342*cdf0e10cSrcweir if (xSet.is()) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir // acceptor 345*cdf0e10cSrcweir xSet->insert( makeAny( loadLibComponentFactory( 346*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor") ), 347*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.Acceptor") ), 348*cdf0e10cSrcweir xMgr, Reference< XRegistryKey >() ) ) ); 349*cdf0e10cSrcweir // connector 350*cdf0e10cSrcweir xSet->insert( makeAny( loadLibComponentFactory( 351*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("connectr") ), 352*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.Connector") ), 353*cdf0e10cSrcweir xMgr, Reference< XRegistryKey >() ) ) ); 354*cdf0e10cSrcweir // iiop bridge 355*cdf0e10cSrcweir xSet->insert( makeAny( loadLibComponentFactory( 356*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge") ), 357*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.various") ), 358*cdf0e10cSrcweir xMgr, Reference< XRegistryKey >() ) ) ); 359*cdf0e10cSrcweir // bridge factory 360*cdf0e10cSrcweir xSet->insert( makeAny( loadLibComponentFactory( 361*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("brdgfctr") ), 362*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.BridgeFactory") ), 363*cdf0e10cSrcweir xMgr, Reference< XRegistryKey >() ) ) ); 364*cdf0e10cSrcweir // uno url resolver 365*cdf0e10cSrcweir xSet->insert( makeAny( loadLibComponentFactory( 366*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("uuresolver") ), 367*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.bridge.UnoUrlResolver") ), 368*cdf0e10cSrcweir xMgr, Reference< XRegistryKey >() ) ) ); 369*cdf0e10cSrcweir // java loader 370*cdf0e10cSrcweir // xSet->insert( makeAny( loadLibComponentFactory( 371*cdf0e10cSrcweir // OUString( RTL_CONSTASCII_USTRINGPARAM("javaloader") ), 372*cdf0e10cSrcweir // OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.JavaComponentLoader") ), 373*cdf0e10cSrcweir // xMgr, Reference< XRegistryKey >() ) ) ); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir s_bSet = sal_True; 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir x = xMgr->createInstance( rServiceName ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir if (! x.is()) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir OUStringBuffer buf( 64 ); 384*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot get service instance \"") ); 385*cdf0e10cSrcweir buf.append( rServiceName ); 386*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") ); 387*cdf0e10cSrcweir throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir rxOut = Reference< T >::query( x ); 391*cdf0e10cSrcweir if (! rxOut.is()) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir OUStringBuffer buf( 64 ); 394*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("service instance \"") ); 395*cdf0e10cSrcweir buf.append( rServiceName ); 396*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" does not support demanded interface \"") ); 397*cdf0e10cSrcweir const Type & rType = ::getCppuType( (const Reference< T > *)0 ); 398*cdf0e10cSrcweir buf.append( rType.getTypeName() ); 399*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") ); 400*cdf0e10cSrcweir throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 405*cdf0e10cSrcweir inline static Sequence< OUString > getSupportedServiceNames() 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ); 408*cdf0e10cSrcweir return Sequence< OUString >( &aName, 1 ); 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir //================================================================================================== 412*cdf0e10cSrcweir class TestImpl : public WeakImplHelper2< XServiceInfo, XMain > 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir Reference< XMultiServiceFactory > _xSMgr; 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir Reference< XInterface > _xDirect; 417*cdf0e10cSrcweir Reference< XInterface > getDirect() throw (Exception); 418*cdf0e10cSrcweir Reference< XInterface > resolveObject( const OUString & rUnoUrl ) throw (Exception); 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir public: 421*cdf0e10cSrcweir TestImpl( const Reference< XMultiServiceFactory > & xSMgr ); 422*cdf0e10cSrcweir virtual ~TestImpl(); 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir // XServiceInfo 425*cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName() throw (RuntimeException); 426*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException); 427*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir // XMain 430*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException); 431*cdf0e10cSrcweir }; 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir //################################################################################################## 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir //__________________________________________________________________________________________________ 436*cdf0e10cSrcweir TestImpl::TestImpl( const Reference< XMultiServiceFactory > & xSMgr ) 437*cdf0e10cSrcweir : _xSMgr( xSMgr ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir //__________________________________________________________________________________________________ 441*cdf0e10cSrcweir TestImpl::~TestImpl() 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir //================================================================================================== 446*cdf0e10cSrcweir static Reference< XInterface > SAL_CALL TestImpl_create( const Reference< XMultiServiceFactory > & xSMgr ) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir return Reference< XInterface >( *new TestImpl( xSMgr ) ); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir // XServiceInfo 452*cdf0e10cSrcweir //__________________________________________________________________________________________________ 453*cdf0e10cSrcweir OUString TestImpl::getImplementationName() 454*cdf0e10cSrcweir throw (RuntimeException) 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir //__________________________________________________________________________________________________ 459*cdf0e10cSrcweir sal_Bool TestImpl::supportsService( const OUString & rServiceName ) 460*cdf0e10cSrcweir throw (RuntimeException) 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir const Sequence< OUString > & rSNL = getSupportedServiceNames(); 463*cdf0e10cSrcweir const OUString * pArray = rSNL.getConstArray(); 464*cdf0e10cSrcweir for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir if (pArray[nPos] == rServiceName) 467*cdf0e10cSrcweir return sal_True; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir return sal_False; 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir //__________________________________________________________________________________________________ 472*cdf0e10cSrcweir Sequence< OUString > TestImpl::getSupportedServiceNames() 473*cdf0e10cSrcweir throw (RuntimeException) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir return benchmark_test::getSupportedServiceNames(); 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir //__________________________________________________________________________________________________ 479*cdf0e10cSrcweir Reference< XInterface > TestImpl::getDirect() 480*cdf0e10cSrcweir throw (Exception) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir if (! _xDirect.is()) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 485*cdf0e10cSrcweir if (! _xDirect.is()) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir Reference< XSingleServiceFactory > xFac( loadLibComponentFactory( 488*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("perfobj") ), 489*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.performance.PerformanceTestObject") ), 490*cdf0e10cSrcweir _xSMgr, Reference< XRegistryKey >() ) ); 491*cdf0e10cSrcweir if (! xFac.is()) 492*cdf0e10cSrcweir throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no test object available!") ), Reference< XInterface >() ); 493*cdf0e10cSrcweir _xDirect = xFac->createInstance(); 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir return _xDirect; 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 499*cdf0e10cSrcweir Reference< XInterface > TestImpl::resolveObject( const OUString & rUnoUrl ) 500*cdf0e10cSrcweir throw (Exception) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir Reference< XUnoUrlResolver > xResolver; 503*cdf0e10cSrcweir createInstance( 504*cdf0e10cSrcweir xResolver, _xSMgr, 505*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.UnoUrlResolver") ) ); 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir Reference< XInterface > xResolvedObject( xResolver->resolve( rUnoUrl ) ); 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir if (! xResolvedObject.is()) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir OUStringBuffer buf( 32 ); 512*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot resolve object \"") ); 513*cdf0e10cSrcweir buf.append( rUnoUrl ); 514*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") ); 515*cdf0e10cSrcweir throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir return xResolvedObject; 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir //================================================================================================== 522*cdf0e10cSrcweir class TimeEntry 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir sal_Int64 nLoop; 525*cdf0e10cSrcweir sal_uInt32 nTicks; 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir public: 528*cdf0e10cSrcweir TimeEntry() 529*cdf0e10cSrcweir {} 530*cdf0e10cSrcweir TimeEntry( sal_Int64 nLoop_, sal_uInt32 nTicks_ ) 531*cdf0e10cSrcweir : nLoop( nLoop_ ) 532*cdf0e10cSrcweir , nTicks( nTicks_ ) 533*cdf0e10cSrcweir {} 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir inline double secPerCall() const 536*cdf0e10cSrcweir { return (((double)nTicks) / (nLoop * 1000)); } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir double ratio( const TimeEntry & rEntry ) const; 539*cdf0e10cSrcweir }; 540*cdf0e10cSrcweir //__________________________________________________________________________________________________ 541*cdf0e10cSrcweir double TimeEntry::ratio( const TimeEntry & rEntry ) const 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir double f = rEntry.nTicks * nLoop; 544*cdf0e10cSrcweir if (f == 0.0) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir return 0.0; 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir else 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir return (((double)(nTicks * rEntry.nLoop)) / f); 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir //================================================================================================== 555*cdf0e10cSrcweir typedef std::map< std::string, TimeEntry > t_TimeEntryMap; 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir //================================================================================================== 558*cdf0e10cSrcweir struct TimingSheet 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir t_TimeEntryMap _entries; 561*cdf0e10cSrcweir void insert( const sal_Char * pText, sal_Int64 nLoop, sal_uInt32 nTicks ); 562*cdf0e10cSrcweir }; 563*cdf0e10cSrcweir //__________________________________________________________________________________________________ 564*cdf0e10cSrcweir void TimingSheet::insert( const sal_Char * pText, sal_Int64 nLoop, sal_uInt32 nTicks ) 565*cdf0e10cSrcweir { 566*cdf0e10cSrcweir _entries[ pText ] = TimeEntry( nLoop, nTicks ); 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir //================================================================================================== 570*cdf0e10cSrcweir typedef std::hash_map< std::string, TimingSheet > t_TimingSheetMap; 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 573*cdf0e10cSrcweir static void benchmark( 574*cdf0e10cSrcweir TimingSheet & rSheet, const Reference< XInterface > & xInstance, sal_Int64 nLoop ) 575*cdf0e10cSrcweir throw (Exception) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir Reference< XPerformanceTest > xBench( xInstance, UNO_QUERY ); 578*cdf0e10cSrcweir if (! xBench.is()) 579*cdf0e10cSrcweir throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("illegal test object!") ), Reference< XInterface >() ); 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir sal_Int64 i; 582*cdf0e10cSrcweir sal_uInt32 tStart, tEnd; 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir const Type & rKnownType = ::getCppuType( (const Reference< XPerformanceTest > *)0 ); 585*cdf0e10cSrcweir const Type & rUnKnownType = ::getCppuType( (const Reference< XSet > *)0 ); 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir ComplexTypes aDummyStruct; 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir //------------------------------------ 590*cdf0e10cSrcweir // oneway calls 591*cdf0e10cSrcweir i = nLoop; 592*cdf0e10cSrcweir tStart = getSystemTicks(); 593*cdf0e10cSrcweir while (i--) 594*cdf0e10cSrcweir xBench->async(); 595*cdf0e10cSrcweir sal_uInt32 tEndSend = getSystemTicks(); 596*cdf0e10cSrcweir xBench->sync(); 597*cdf0e10cSrcweir tEnd = getSystemTicks(); 598*cdf0e10cSrcweir rSheet.insert( "1a: sending simple oneway calls (no params, no return)", nLoop, tEndSend - tStart ); 599*cdf0e10cSrcweir rSheet.insert( "1b: simple oneway calls (no params, no return)", nLoop, tEnd - tStart ); 600*cdf0e10cSrcweir // synchron calls 601*cdf0e10cSrcweir i = nLoop; 602*cdf0e10cSrcweir tStart = getSystemTicks(); 603*cdf0e10cSrcweir while (i--) 604*cdf0e10cSrcweir xBench->sync(); 605*cdf0e10cSrcweir xBench->sync(); 606*cdf0e10cSrcweir tEnd = getSystemTicks(); 607*cdf0e10cSrcweir rSheet.insert( "1c: simple synchron calls (no params no return)", nLoop+1, tEnd - tStart ); 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir // acquire 610*cdf0e10cSrcweir i = nLoop; 611*cdf0e10cSrcweir tStart = getSystemTicks(); 612*cdf0e10cSrcweir while (i--) 613*cdf0e10cSrcweir xBench->acquire(); 614*cdf0e10cSrcweir tEnd = getSystemTicks(); 615*cdf0e10cSrcweir rSheet.insert( "2a: interface acquire() calls", nLoop, tEnd - tStart ); 616*cdf0e10cSrcweir // release 617*cdf0e10cSrcweir i = nLoop; 618*cdf0e10cSrcweir tStart = getSystemTicks(); 619*cdf0e10cSrcweir while (i--) 620*cdf0e10cSrcweir xBench->release(); 621*cdf0e10cSrcweir tEnd = getSystemTicks(); 622*cdf0e10cSrcweir rSheet.insert( "2b: interface release() calls", nLoop, tEnd - tStart ); 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir // queryInterface() for known type 625*cdf0e10cSrcweir i = nLoop; 626*cdf0e10cSrcweir tStart = getSystemTicks(); 627*cdf0e10cSrcweir while (i--) 628*cdf0e10cSrcweir xBench->queryInterface( rKnownType ); 629*cdf0e10cSrcweir tEnd = getSystemTicks(); 630*cdf0e10cSrcweir rSheet.insert( "2c: interface query for implemented type", nLoop, tEnd - tStart ); 631*cdf0e10cSrcweir // queryInterface() for unknown type 632*cdf0e10cSrcweir i = nLoop; 633*cdf0e10cSrcweir tStart = getSystemTicks(); 634*cdf0e10cSrcweir while (i--) 635*cdf0e10cSrcweir xBench->queryInterface( rUnKnownType ); 636*cdf0e10cSrcweir tEnd = getSystemTicks(); 637*cdf0e10cSrcweir rSheet.insert( "2d: interface query for unknown type", nLoop, tEnd - tStart ); 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir // create and forget objects 640*cdf0e10cSrcweir Reference< XPerformanceTest > xBench2( xBench ); 641*cdf0e10cSrcweir i = nLoop; 642*cdf0e10cSrcweir tStart = getSystemTicks(); 643*cdf0e10cSrcweir while (i--) 644*cdf0e10cSrcweir xBench2 = xBench2->createObject(); 645*cdf0e10cSrcweir tEnd = getSystemTicks(); 646*cdf0e10cSrcweir rSheet.insert( "3a: create and release test objects", nLoop, tEnd - tStart ); 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir // hold new objects 649*cdf0e10cSrcweir Sequence< Reference< XInterface > > aSeq( nLoop / 100 ); 650*cdf0e10cSrcweir Reference< XInterface > * pSeq = aSeq.getArray(); 651*cdf0e10cSrcweir xBench2 = xBench; 652*cdf0e10cSrcweir i = aSeq.getLength(); 653*cdf0e10cSrcweir tStart = getSystemTicks(); 654*cdf0e10cSrcweir while (i--) 655*cdf0e10cSrcweir pSeq[i] = xBench2 = xBench2->createObject(); 656*cdf0e10cSrcweir tEnd = getSystemTicks(); 657*cdf0e10cSrcweir rSheet.insert( "3b: create and hold test objects", nLoop, tEnd - tStart ); 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir // structs 660*cdf0e10cSrcweir i = nLoop; 661*cdf0e10cSrcweir tStart = getSystemTicks(); 662*cdf0e10cSrcweir while (i--) 663*cdf0e10cSrcweir xBench->complex_in( aDummyStruct ); 664*cdf0e10cSrcweir tEnd = getSystemTicks(); 665*cdf0e10cSrcweir rSheet.insert( "4a: complex_in() calls (in struct; return struct)", nLoop, tEnd - tStart ); 666*cdf0e10cSrcweir i = nLoop; 667*cdf0e10cSrcweir tStart = getSystemTicks(); 668*cdf0e10cSrcweir while (i--) 669*cdf0e10cSrcweir xBench->complex_inout( aDummyStruct ); 670*cdf0e10cSrcweir tEnd = getSystemTicks(); 671*cdf0e10cSrcweir rSheet.insert( "4b: complex_inout() calls (inout struct; return struct)", nLoop, tEnd - tStart ); 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir i = nLoop; 674*cdf0e10cSrcweir tStart = getSystemTicks(); 675*cdf0e10cSrcweir while (i--) 676*cdf0e10cSrcweir xBench->complex_oneway( aDummyStruct ); 677*cdf0e10cSrcweir tEnd = getSystemTicks(); 678*cdf0e10cSrcweir rSheet.insert( "4c: complex_oneway() oneway calls (in struct)", nLoop, tEnd - tStart ); 679*cdf0e10cSrcweir i = nLoop; 680*cdf0e10cSrcweir tStart = getSystemTicks(); 681*cdf0e10cSrcweir while (i--) 682*cdf0e10cSrcweir xBench->complex_noreturn( aDummyStruct ); 683*cdf0e10cSrcweir tEnd = getSystemTicks(); 684*cdf0e10cSrcweir rSheet.insert( "4d: complex_noreturn() calls (in struct)", nLoop, tEnd - tStart ); 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir // attributes, get() methods 687*cdf0e10cSrcweir i = nLoop; 688*cdf0e10cSrcweir tStart = getSystemTicks(); 689*cdf0e10cSrcweir while (i--) 690*cdf0e10cSrcweir xBench->getLong(); 691*cdf0e10cSrcweir tEnd = getSystemTicks(); 692*cdf0e10cSrcweir rSheet.insert( "5a: getLong() call", nLoop, tEnd - tStart ); 693*cdf0e10cSrcweir i = nLoop; 694*cdf0e10cSrcweir tStart = getSystemTicks(); 695*cdf0e10cSrcweir while (i--) 696*cdf0e10cSrcweir xBench->getLong_attr(); 697*cdf0e10cSrcweir tEnd = getSystemTicks(); 698*cdf0e10cSrcweir rSheet.insert( "5b: get long attribute", nLoop, tEnd - tStart ); 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir i = nLoop; 701*cdf0e10cSrcweir tStart = getSystemTicks(); 702*cdf0e10cSrcweir while (i--) 703*cdf0e10cSrcweir xBench->setLong( 0 ); 704*cdf0e10cSrcweir tEnd = getSystemTicks(); 705*cdf0e10cSrcweir rSheet.insert( "5c: setLong() call", nLoop, tEnd - tStart ); 706*cdf0e10cSrcweir i = nLoop; 707*cdf0e10cSrcweir tStart = getSystemTicks(); 708*cdf0e10cSrcweir while (i--) 709*cdf0e10cSrcweir xBench->setLong_attr( 0 ); 710*cdf0e10cSrcweir tEnd = getSystemTicks(); 711*cdf0e10cSrcweir rSheet.insert( "5d: set long attribute", nLoop, tEnd - tStart ); 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir i = nLoop; 714*cdf0e10cSrcweir tStart = getSystemTicks(); 715*cdf0e10cSrcweir while (i--) 716*cdf0e10cSrcweir xBench->getHyper(); 717*cdf0e10cSrcweir tEnd = getSystemTicks(); 718*cdf0e10cSrcweir rSheet.insert( "5e: getHyper() call", nLoop, tEnd - tStart ); 719*cdf0e10cSrcweir i = nLoop; 720*cdf0e10cSrcweir tStart = getSystemTicks(); 721*cdf0e10cSrcweir while (i--) 722*cdf0e10cSrcweir xBench->getHyper_attr(); 723*cdf0e10cSrcweir tEnd = getSystemTicks(); 724*cdf0e10cSrcweir rSheet.insert( "5f: get hyper attribute", nLoop, tEnd - tStart ); 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir i = nLoop; 727*cdf0e10cSrcweir tStart = getSystemTicks(); 728*cdf0e10cSrcweir while (i--) 729*cdf0e10cSrcweir xBench->setHyper( 0 ); 730*cdf0e10cSrcweir tEnd = getSystemTicks(); 731*cdf0e10cSrcweir rSheet.insert( "5g: setHyper() call", nLoop, tEnd - tStart ); 732*cdf0e10cSrcweir i = nLoop; 733*cdf0e10cSrcweir tStart = getSystemTicks(); 734*cdf0e10cSrcweir while (i--) 735*cdf0e10cSrcweir xBench->setHyper_attr( 0 ); 736*cdf0e10cSrcweir tEnd = getSystemTicks(); 737*cdf0e10cSrcweir rSheet.insert( "5h: set hyper attribute", nLoop, tEnd - tStart ); 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir i = nLoop; 740*cdf0e10cSrcweir tStart = getSystemTicks(); 741*cdf0e10cSrcweir while (i--) 742*cdf0e10cSrcweir xBench->getFloat(); 743*cdf0e10cSrcweir tEnd = getSystemTicks(); 744*cdf0e10cSrcweir rSheet.insert( "5i: getFloat() call", nLoop, tEnd - tStart ); 745*cdf0e10cSrcweir i = nLoop; 746*cdf0e10cSrcweir tStart = getSystemTicks(); 747*cdf0e10cSrcweir while (i--) 748*cdf0e10cSrcweir xBench->getFloat_attr(); 749*cdf0e10cSrcweir tEnd = getSystemTicks(); 750*cdf0e10cSrcweir rSheet.insert( "5j: get float attribute",nLoop, tEnd - tStart ); 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir i = nLoop; 753*cdf0e10cSrcweir tStart = getSystemTicks(); 754*cdf0e10cSrcweir while (i--) 755*cdf0e10cSrcweir xBench->setFloat( 0.0 ); 756*cdf0e10cSrcweir tEnd = getSystemTicks(); 757*cdf0e10cSrcweir rSheet.insert( "5k: setFloat() call", nLoop, tEnd - tStart ); 758*cdf0e10cSrcweir i = nLoop; 759*cdf0e10cSrcweir tStart = getSystemTicks(); 760*cdf0e10cSrcweir while (i--) 761*cdf0e10cSrcweir xBench->setFloat_attr( 0.0 ); 762*cdf0e10cSrcweir tEnd = getSystemTicks(); 763*cdf0e10cSrcweir rSheet.insert( "5l: set float attribute", nLoop, tEnd - tStart ); 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir i = nLoop; 766*cdf0e10cSrcweir tStart = getSystemTicks(); 767*cdf0e10cSrcweir while (i--) 768*cdf0e10cSrcweir xBench->getDouble(); 769*cdf0e10cSrcweir tEnd = getSystemTicks(); 770*cdf0e10cSrcweir rSheet.insert( "5m: getDouble() call", nLoop, tEnd - tStart ); 771*cdf0e10cSrcweir i = nLoop; 772*cdf0e10cSrcweir tStart = getSystemTicks(); 773*cdf0e10cSrcweir while (i--) 774*cdf0e10cSrcweir xBench->getDouble_attr(); 775*cdf0e10cSrcweir tEnd = getSystemTicks(); 776*cdf0e10cSrcweir rSheet.insert( "5n: get double attribute", nLoop, tEnd - tStart ); 777*cdf0e10cSrcweir i = nLoop; 778*cdf0e10cSrcweir tStart = getSystemTicks(); 779*cdf0e10cSrcweir while (i--) 780*cdf0e10cSrcweir xBench->setDouble( 0.0 ); 781*cdf0e10cSrcweir tEnd = getSystemTicks(); 782*cdf0e10cSrcweir rSheet.insert( "5o: setDouble() call", nLoop, tEnd - tStart ); 783*cdf0e10cSrcweir i = nLoop; 784*cdf0e10cSrcweir tStart = getSystemTicks(); 785*cdf0e10cSrcweir while (i--) 786*cdf0e10cSrcweir xBench->setDouble_attr( 0.0 ); 787*cdf0e10cSrcweir tEnd = getSystemTicks(); 788*cdf0e10cSrcweir rSheet.insert( "5p: set double attribute", nLoop, tEnd - tStart ); 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir i = nLoop; 791*cdf0e10cSrcweir tStart = getSystemTicks(); 792*cdf0e10cSrcweir while (i--) 793*cdf0e10cSrcweir xBench->getString(); 794*cdf0e10cSrcweir tEnd = getSystemTicks(); 795*cdf0e10cSrcweir rSheet.insert( "6a: getString() call (empty)", nLoop, tEnd - tStart ); 796*cdf0e10cSrcweir i = nLoop; 797*cdf0e10cSrcweir tStart = getSystemTicks(); 798*cdf0e10cSrcweir while (i--) 799*cdf0e10cSrcweir xBench->getString_attr(); 800*cdf0e10cSrcweir tEnd = getSystemTicks(); 801*cdf0e10cSrcweir rSheet.insert( "6b: get empty string attribute", nLoop, tEnd - tStart ); 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir i = nLoop; 804*cdf0e10cSrcweir OUString aDummyString; 805*cdf0e10cSrcweir tStart = getSystemTicks(); 806*cdf0e10cSrcweir while (i--) 807*cdf0e10cSrcweir xBench->setString( aDummyString ); 808*cdf0e10cSrcweir tEnd = getSystemTicks(); 809*cdf0e10cSrcweir rSheet.insert( "6c: setString() call (emtpy)", nLoop, tEnd - tStart ); 810*cdf0e10cSrcweir i = nLoop; 811*cdf0e10cSrcweir tStart = getSystemTicks(); 812*cdf0e10cSrcweir while (i--) 813*cdf0e10cSrcweir xBench->setString_attr( aDummyString ); 814*cdf0e10cSrcweir tEnd = getSystemTicks(); 815*cdf0e10cSrcweir rSheet.insert( "6d: set empty string attribute", nLoop, tEnd - tStart ); 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir i = nLoop; 818*cdf0e10cSrcweir tStart = getSystemTicks(); 819*cdf0e10cSrcweir while (i--) 820*cdf0e10cSrcweir xBench->getInterface(); 821*cdf0e10cSrcweir tEnd = getSystemTicks(); 822*cdf0e10cSrcweir rSheet.insert( "7a: getInterface() call (null)", nLoop, tEnd - tStart ); 823*cdf0e10cSrcweir i = nLoop; 824*cdf0e10cSrcweir tStart = getSystemTicks(); 825*cdf0e10cSrcweir while (i--) 826*cdf0e10cSrcweir xBench->getInterface_attr(); 827*cdf0e10cSrcweir tEnd = getSystemTicks(); 828*cdf0e10cSrcweir rSheet.insert( "7b: get interface attribute", nLoop, tEnd - tStart ); 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir i = nLoop; 831*cdf0e10cSrcweir Reference< XInterface > aDummyInterface; 832*cdf0e10cSrcweir tStart = getSystemTicks(); 833*cdf0e10cSrcweir while (i--) 834*cdf0e10cSrcweir xBench->setInterface( aDummyInterface ); 835*cdf0e10cSrcweir tEnd = getSystemTicks(); 836*cdf0e10cSrcweir rSheet.insert( "7c: setInterface() call (null)", nLoop, tEnd - tStart ); 837*cdf0e10cSrcweir i = nLoop; 838*cdf0e10cSrcweir tStart = getSystemTicks(); 839*cdf0e10cSrcweir while (i--) 840*cdf0e10cSrcweir xBench->setInterface_attr( Reference< XInterface >() ); 841*cdf0e10cSrcweir tEnd = getSystemTicks(); 842*cdf0e10cSrcweir rSheet.insert( "7d: set interface attribute", nLoop, tEnd - tStart ); 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir i = nLoop; 845*cdf0e10cSrcweir tStart = getSystemTicks(); 846*cdf0e10cSrcweir while (i--) 847*cdf0e10cSrcweir xBench->getAny(); 848*cdf0e10cSrcweir tEnd = getSystemTicks(); 849*cdf0e10cSrcweir rSheet.insert( "8a: getAny() call (empty)", nLoop, tEnd - tStart ); 850*cdf0e10cSrcweir i = nLoop; 851*cdf0e10cSrcweir tStart = getSystemTicks(); 852*cdf0e10cSrcweir while (i--) 853*cdf0e10cSrcweir xBench->getAny_attr(); 854*cdf0e10cSrcweir tEnd = getSystemTicks(); 855*cdf0e10cSrcweir rSheet.insert( "8b: get empty any attribute", nLoop, tEnd - tStart ); 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir i = nLoop; 858*cdf0e10cSrcweir Any aDummyAny; 859*cdf0e10cSrcweir tStart = getSystemTicks(); 860*cdf0e10cSrcweir while (i--) 861*cdf0e10cSrcweir xBench->setAny( aDummyAny ); 862*cdf0e10cSrcweir tEnd = getSystemTicks(); 863*cdf0e10cSrcweir rSheet.insert( "8c: setAny() call (empty)", nLoop, tEnd - tStart ); 864*cdf0e10cSrcweir i = nLoop; 865*cdf0e10cSrcweir tStart = getSystemTicks(); 866*cdf0e10cSrcweir while (i--) 867*cdf0e10cSrcweir xBench->setAny_attr( aDummyAny ); 868*cdf0e10cSrcweir tEnd = getSystemTicks(); 869*cdf0e10cSrcweir rSheet.insert( "8d: set empty any attribute", nLoop, tEnd - tStart ); 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir i = nLoop; 872*cdf0e10cSrcweir tStart = getSystemTicks(); 873*cdf0e10cSrcweir while (i--) 874*cdf0e10cSrcweir xBench->getSequence(); 875*cdf0e10cSrcweir tEnd = getSystemTicks(); 876*cdf0e10cSrcweir rSheet.insert( "9a: getSequence() call (empty)", nLoop, tEnd - tStart ); 877*cdf0e10cSrcweir i = nLoop; 878*cdf0e10cSrcweir tStart = getSystemTicks(); 879*cdf0e10cSrcweir while (i--) 880*cdf0e10cSrcweir xBench->getSequence_attr(); 881*cdf0e10cSrcweir tEnd = getSystemTicks(); 882*cdf0e10cSrcweir rSheet.insert( "9b: get empty sequence attribute", nLoop, tEnd - tStart ); 883*cdf0e10cSrcweir i = nLoop; 884*cdf0e10cSrcweir Sequence< Reference< XInterface > > aDummySeq; 885*cdf0e10cSrcweir tStart = getSystemTicks(); 886*cdf0e10cSrcweir while (i--) 887*cdf0e10cSrcweir xBench->setSequence( aDummySeq ); 888*cdf0e10cSrcweir tEnd = getSystemTicks(); 889*cdf0e10cSrcweir rSheet.insert( "9c: setSequence() call (empty)", nLoop, tEnd - tStart ); 890*cdf0e10cSrcweir i = nLoop; 891*cdf0e10cSrcweir tStart = getSystemTicks(); 892*cdf0e10cSrcweir while (i--) 893*cdf0e10cSrcweir xBench->setSequence_attr( aDummySeq ); 894*cdf0e10cSrcweir tEnd = getSystemTicks(); 895*cdf0e10cSrcweir rSheet.insert( "9d: set empty sequence attribute", nLoop, tEnd - tStart ); 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir i = nLoop; 898*cdf0e10cSrcweir tStart = getSystemTicks(); 899*cdf0e10cSrcweir while (i--) 900*cdf0e10cSrcweir xBench->getStruct(); 901*cdf0e10cSrcweir tEnd = getSystemTicks(); 902*cdf0e10cSrcweir rSheet.insert( "Aa: getStruct() call", nLoop, tEnd - tStart ); 903*cdf0e10cSrcweir i = nLoop; 904*cdf0e10cSrcweir tStart = getSystemTicks(); 905*cdf0e10cSrcweir while (i--) 906*cdf0e10cSrcweir xBench->getStruct_attr(); 907*cdf0e10cSrcweir tEnd = getSystemTicks(); 908*cdf0e10cSrcweir rSheet.insert( "Ab: get struct attribute", nLoop, tEnd - tStart ); 909*cdf0e10cSrcweir 910*cdf0e10cSrcweir i = nLoop; 911*cdf0e10cSrcweir tStart = getSystemTicks(); 912*cdf0e10cSrcweir while (i--) 913*cdf0e10cSrcweir xBench->setStruct( aDummyStruct ); 914*cdf0e10cSrcweir tEnd = getSystemTicks(); 915*cdf0e10cSrcweir rSheet.insert( "Ac: setStruct() call", nLoop, tEnd - tStart ); 916*cdf0e10cSrcweir i = nLoop; 917*cdf0e10cSrcweir tStart = getSystemTicks(); 918*cdf0e10cSrcweir while (i--) 919*cdf0e10cSrcweir xBench->setStruct_attr( aDummyStruct ); 920*cdf0e10cSrcweir tEnd = getSystemTicks(); 921*cdf0e10cSrcweir rSheet.insert( "Ad: set struct attribute", nLoop, tEnd - tStart ); 922*cdf0e10cSrcweir 923*cdf0e10cSrcweir // load 924*cdf0e10cSrcweir // i = nLoop; 925*cdf0e10cSrcweir // tStart = getSystemTicks(); 926*cdf0e10cSrcweir // while (i--) 927*cdf0e10cSrcweir // xBench->setSequence( aSeq ); 928*cdf0e10cSrcweir // tEnd = getSystemTicks(); 929*cdf0e10cSrcweir // rSheet.insert( "transfer of exisiting objects", nLoop, tEnd - tStart ); 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir // exceptions 932*cdf0e10cSrcweir i = nLoop; 933*cdf0e10cSrcweir tStart = getSystemTicks(); 934*cdf0e10cSrcweir while (i--) 935*cdf0e10cSrcweir { 936*cdf0e10cSrcweir try 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir xBench->raiseRuntimeException(); 939*cdf0e10cSrcweir } 940*cdf0e10cSrcweir catch (RuntimeException &) 941*cdf0e10cSrcweir { 942*cdf0e10cSrcweir } 943*cdf0e10cSrcweir } 944*cdf0e10cSrcweir tEnd = getSystemTicks(); 945*cdf0e10cSrcweir rSheet.insert( "Ba: raising RuntimeException", nLoop, tEnd - tStart ); 946*cdf0e10cSrcweir 947*cdf0e10cSrcweir //------------------------------------ 948*cdf0e10cSrcweir } 949*cdf0e10cSrcweir 950*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 951*cdf0e10cSrcweir static OUString extractParam( const Sequence< OUString > & rArgs, const OUString & rParam ) 952*cdf0e10cSrcweir { 953*cdf0e10cSrcweir const OUString * pArgs = rArgs.getConstArray(); 954*cdf0e10cSrcweir for ( sal_Int32 nPos = rArgs.getLength(); nPos--; ) 955*cdf0e10cSrcweir { 956*cdf0e10cSrcweir if (pArgs[nPos].indexOf( rParam ) == 0 && 957*cdf0e10cSrcweir pArgs[nPos].getLength() > (rParam.getLength()+1)) 958*cdf0e10cSrcweir { 959*cdf0e10cSrcweir return pArgs[nPos].copy( rParam.getLength() +1 ); // XXX=bla 960*cdf0e10cSrcweir } 961*cdf0e10cSrcweir } 962*cdf0e10cSrcweir return OUString(); 963*cdf0e10cSrcweir } 964*cdf0e10cSrcweir 965*cdf0e10cSrcweir const sal_Int32 nMagicNumberDirect = 34000; 966*cdf0e10cSrcweir 967*cdf0e10cSrcweir //XMain 968*cdf0e10cSrcweir //__________________________________________________________________________________________________ 969*cdf0e10cSrcweir sal_Int32 TestImpl::run( const Sequence< OUString > & rArgs ) 970*cdf0e10cSrcweir throw (RuntimeException) 971*cdf0e10cSrcweir { 972*cdf0e10cSrcweir // defaults 973*cdf0e10cSrcweir FILE * stream = stderr; 974*cdf0e10cSrcweir sal_Int64 nLoop = NLOOP; 975*cdf0e10cSrcweir OUString aArg( RTL_CONSTASCII_USTRINGPARAM("dms") ); 976*cdf0e10cSrcweir 977*cdf0e10cSrcweir try 978*cdf0e10cSrcweir { 979*cdf0e10cSrcweir OUString aLoopStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("loop") ) ) ); 980*cdf0e10cSrcweir if (aLoopStr.getLength()) 981*cdf0e10cSrcweir { 982*cdf0e10cSrcweir sal_Int64 n = aLoopStr.toInt64(); 983*cdf0e10cSrcweir if (n > 0) 984*cdf0e10cSrcweir nLoop = n; 985*cdf0e10cSrcweir } 986*cdf0e10cSrcweir 987*cdf0e10cSrcweir OUString aDurationStr( extractParam( rArgs , OUString( RTL_CONSTASCII_USTRINGPARAM("duration" ) ) ) ); 988*cdf0e10cSrcweir if( aDurationStr.getLength() ) 989*cdf0e10cSrcweir { 990*cdf0e10cSrcweir sal_Int64 n = aDurationStr.toInt64(); 991*cdf0e10cSrcweir if( n >0 ) 992*cdf0e10cSrcweir nLoop = nMagicNumberDirect * n; 993*cdf0e10cSrcweir } 994*cdf0e10cSrcweir 995*cdf0e10cSrcweir OUString aLogStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("log") ) ) ); 996*cdf0e10cSrcweir if (aLogStr.getLength()) 997*cdf0e10cSrcweir { 998*cdf0e10cSrcweir if (aLogStr.compareToAscii( "stderr" ) == 0) 999*cdf0e10cSrcweir { 1000*cdf0e10cSrcweir stream = stderr; 1001*cdf0e10cSrcweir } 1002*cdf0e10cSrcweir else if (aLogStr.compareToAscii( "stdout" ) == 0) 1003*cdf0e10cSrcweir { 1004*cdf0e10cSrcweir stream = stdout; 1005*cdf0e10cSrcweir } 1006*cdf0e10cSrcweir else 1007*cdf0e10cSrcweir { 1008*cdf0e10cSrcweir OString aFileName( OUStringToOString( aLogStr, RTL_TEXTENCODING_ASCII_US ) ); 1009*cdf0e10cSrcweir stream = ::fopen( aFileName.getStr(), "w" ); 1010*cdf0e10cSrcweir if (! stream) 1011*cdf0e10cSrcweir { 1012*cdf0e10cSrcweir OUStringBuffer buf( 32 ); 1013*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot open file for writing: \"") ); 1014*cdf0e10cSrcweir buf.append( aLogStr ); 1015*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") ); 1016*cdf0e10cSrcweir throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); 1017*cdf0e10cSrcweir } 1018*cdf0e10cSrcweir } 1019*cdf0e10cSrcweir } 1020*cdf0e10cSrcweir 1021*cdf0e10cSrcweir OUString aArgStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("opt") ) ) ); 1022*cdf0e10cSrcweir if (aArgStr.getLength()) 1023*cdf0e10cSrcweir { 1024*cdf0e10cSrcweir aArg = aArgStr; 1025*cdf0e10cSrcweir } 1026*cdf0e10cSrcweir 1027*cdf0e10cSrcweir if (! rArgs.getLength()) 1028*cdf0e10cSrcweir out( "\n> no options given, using defaults" ); 1029*cdf0e10cSrcweir 1030*cdf0e10cSrcweir // params 1031*cdf0e10cSrcweir out( "\n> opt=" ); 1032*cdf0e10cSrcweir out( aArg ); 1033*cdf0e10cSrcweir out( " log=" ); 1034*cdf0e10cSrcweir if (stream == stderr) 1035*cdf0e10cSrcweir out( "stderr" ); 1036*cdf0e10cSrcweir else if (stream == stderr) 1037*cdf0e10cSrcweir out( "stdout loop=" ); 1038*cdf0e10cSrcweir else 1039*cdf0e10cSrcweir out( aLogStr ); 1040*cdf0e10cSrcweir out( " loop=" ); 1041*cdf0e10cSrcweir out( nLoop ); 1042*cdf0e10cSrcweir out( "\n" ); 1043*cdf0e10cSrcweir t_TimingSheetMap aSheets; 1044*cdf0e10cSrcweir TimingSheet aDirect; 1045*cdf0e10cSrcweir 1046*cdf0e10cSrcweir //------------------------------------------------------------------------------------------ 1047*cdf0e10cSrcweir 1048*cdf0e10cSrcweir if (aArg.indexOf( 'd' ) >= 0) 1049*cdf0e10cSrcweir { 1050*cdf0e10cSrcweir // in process direct test 1051*cdf0e10cSrcweir sal_uInt32 nStart = getSystemTicks(); 1052*cdf0e10cSrcweir benchmark( aDirect, getDirect(), nLoop ); 1053*cdf0e10cSrcweir sal_uInt32 nEnd = getSystemTicks(); 1054*cdf0e10cSrcweir fprintf( stderr, "Duration (direct in process): %g s\n", (nEnd - nStart)/1000. ); 1055*cdf0e10cSrcweir } 1056*cdf0e10cSrcweir 1057*cdf0e10cSrcweir //------------------------------------------------------------------------------------------ 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir if (aArg.indexOf( 'm' ) >= 0) 1060*cdf0e10cSrcweir { 1061*cdf0e10cSrcweir // in process uno dispatch 1062*cdf0e10cSrcweir Environment aCppEnv, aAnoCppEnv; 1063*cdf0e10cSrcweir OUString aCurrentLanguageBindingName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); 1064*cdf0e10cSrcweir uno_getEnvironment( reinterpret_cast< uno_Environment ** >( &aCppEnv ), 1065*cdf0e10cSrcweir aCurrentLanguageBindingName.pData, 0 ); 1066*cdf0e10cSrcweir // anonymous 1067*cdf0e10cSrcweir uno_createEnvironment( reinterpret_cast< uno_Environment ** >( &aAnoCppEnv ), 1068*cdf0e10cSrcweir aCurrentLanguageBindingName.pData, 0 ); 1069*cdf0e10cSrcweir 1070*cdf0e10cSrcweir // pseudo mapping uno<->uno: does nothing! 1071*cdf0e10cSrcweir Mapping aMapping( aCppEnv.get(), aAnoCppEnv.get(), OUString( RTL_CONSTASCII_USTRINGPARAM("pseudo") ) ); 1072*cdf0e10cSrcweir if (! aMapping.is()) 1073*cdf0e10cSrcweir throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no pseudo mapping available!") ), Reference< XInterface >() ); 1074*cdf0e10cSrcweir 1075*cdf0e10cSrcweir Reference< XInterface > xMapped; 1076*cdf0e10cSrcweir Reference< XInterface > xDirect( getDirect() ); 1077*cdf0e10cSrcweir aMapping.mapInterface( reinterpret_cast< void ** >( &xMapped ), xDirect.get(), 1078*cdf0e10cSrcweir ::getCppuType( &xDirect ) ); 1079*cdf0e10cSrcweir if (! xMapped.is()) 1080*cdf0e10cSrcweir throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("mapping object failed!") ), Reference< XInterface >() ); 1081*cdf0e10cSrcweir 1082*cdf0e10cSrcweir sal_uInt32 nStart = getSystemTicks(); 1083*cdf0e10cSrcweir benchmark( aSheets[ "mapped in process" ], xMapped, nLoop / 100 ); 1084*cdf0e10cSrcweir sal_uInt32 nEnd = getSystemTicks(); 1085*cdf0e10cSrcweir fprintf( stderr, "Duration (mapped in process): %g s\n", (nStart - nEnd)/1000. ); 1086*cdf0e10cSrcweir } 1087*cdf0e10cSrcweir 1088*cdf0e10cSrcweir //------------------------------------------------------------------------------------------ 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir if (aArg.indexOf( 's' ) >= 0) 1091*cdf0e10cSrcweir { 1092*cdf0e10cSrcweir // start server process 1093*cdf0e10cSrcweir oslSecurity hSecurity = osl_getCurrentSecurity(); 1094*cdf0e10cSrcweir if (! hSecurity) 1095*cdf0e10cSrcweir throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get current security handle!") ), Reference< XInterface >() ); 1096*cdf0e10cSrcweir 1097*cdf0e10cSrcweir OUString aArgs[] = { 1098*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("-c") ), 1099*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.performance.PerformanceTestObject") ), 1100*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("-l") ), 1101*cdf0e10cSrcweir #ifdef SAL_UNX 1102*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("libperfobj.so") ), 1103*cdf0e10cSrcweir #else 1104*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("perfobj.dll") ), 1105*cdf0e10cSrcweir #endif 1106*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("-r") ), 1107*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb") ), 1108*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("-u") ), 1109*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("uno:socket,host=localhost,port=6000;iiop;TestRemoteObject") ), 1110*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("--singleaccept") ) 1111*cdf0e10cSrcweir }; 1112*cdf0e10cSrcweir rtl_uString * pArgs[] = { 1113*cdf0e10cSrcweir aArgs[0].pData, 1114*cdf0e10cSrcweir aArgs[1].pData, 1115*cdf0e10cSrcweir aArgs[2].pData, 1116*cdf0e10cSrcweir aArgs[3].pData, 1117*cdf0e10cSrcweir aArgs[4].pData, 1118*cdf0e10cSrcweir aArgs[5].pData, 1119*cdf0e10cSrcweir aArgs[6].pData, 1120*cdf0e10cSrcweir aArgs[7].pData, 1121*cdf0e10cSrcweir aArgs[8].pData, 1122*cdf0e10cSrcweir aArgs[9].pData, 1123*cdf0e10cSrcweir }; 1124*cdf0e10cSrcweir 1125*cdf0e10cSrcweir out( "\n> executing: \"uno" ); 1126*cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < (sizeof(aArgs) / sizeof(OUString)); ++nPos ) 1127*cdf0e10cSrcweir { 1128*cdf0e10cSrcweir out( " " ); 1129*cdf0e10cSrcweir out( aArgs[nPos] ); 1130*cdf0e10cSrcweir } 1131*cdf0e10cSrcweir out( "\" ..." ); 1132*cdf0e10cSrcweir 1133*cdf0e10cSrcweir oslProcess hProcess = 0; 1134*cdf0e10cSrcweir OUString aUnoExe( RTL_CONSTASCII_USTRINGPARAM("uno") ); 1135*cdf0e10cSrcweir OUString aWorkingDir( RTL_CONSTASCII_USTRINGPARAM(".") ); 1136*cdf0e10cSrcweir osl_executeProcess( 1137*cdf0e10cSrcweir aUnoExe.pData, pArgs, sizeof(aArgs) / sizeof(OUString), 1138*cdf0e10cSrcweir osl_Process_SEARCHPATH | osl_Process_DETACHED | osl_Process_NORMAL, 1139*cdf0e10cSrcweir hSecurity, aWorkingDir.pData, 0, 0, &hProcess ); 1140*cdf0e10cSrcweir 1141*cdf0e10cSrcweir osl_freeSecurityHandle( hSecurity ); 1142*cdf0e10cSrcweir if (! hProcess) 1143*cdf0e10cSrcweir throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("cannot start server process!") ), Reference< XInterface >() ); 1144*cdf0e10cSrcweir osl_freeProcessHandle( hProcess ); 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir // wait three seconds 1147*cdf0e10cSrcweir TimeValue threeSeconds; 1148*cdf0e10cSrcweir threeSeconds.Seconds = 3; 1149*cdf0e10cSrcweir osl_waitThread( &threeSeconds ); 1150*cdf0e10cSrcweir 1151*cdf0e10cSrcweir // connect and resolve outer process object 1152*cdf0e10cSrcweir Reference< XInterface > xResolvedObject( resolveObject( OUString( 1153*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("uno:socket,host=localhost,port=6000;iiop;TestRemoteObject") ) ) ); 1154*cdf0e10cSrcweir 1155*cdf0e10cSrcweir benchmark( aSheets[ "remote same host" ], xResolvedObject, nLoop / 300 ); 1156*cdf0e10cSrcweir } 1157*cdf0e10cSrcweir 1158*cdf0e10cSrcweir //------------------------------------------------------------------------------------------ 1159*cdf0e10cSrcweir 1160*cdf0e10cSrcweir if (aArg.indexOf( 'r' ) >= 0) 1161*cdf0e10cSrcweir { 1162*cdf0e10cSrcweir // remote 1163*cdf0e10cSrcweir OUString aUnoUrl( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("url") ) ) ); 1164*cdf0e10cSrcweir if (! aUnoUrl.getLength()) 1165*cdf0e10cSrcweir throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("performance test r(emote) needs additional uno url!") ), Reference< XInterface >() ); 1166*cdf0e10cSrcweir 1167*cdf0e10cSrcweir // connect and resolve outer process object 1168*cdf0e10cSrcweir Reference< XInterface > xResolvedObject( resolveObject( aUnoUrl ) ); 1169*cdf0e10cSrcweir 1170*cdf0e10cSrcweir sal_Int32 t1 = getSystemTicks(); 1171*cdf0e10cSrcweir OString o = OUStringToOString( aUnoUrl, RTL_TEXTENCODING_ASCII_US ); 1172*cdf0e10cSrcweir benchmark( aSheets[ o.getStr() ], xResolvedObject, nLoop / 900 ); 1173*cdf0e10cSrcweir sal_Int32 t2 = getSystemTicks(); 1174*cdf0e10cSrcweir fprintf( stderr, "Duration (%s): %g s\n", o.getStr(),(t2 - t1)/1000. ); 1175*cdf0e10cSrcweir } 1176*cdf0e10cSrcweir 1177*cdf0e10cSrcweir //------------------------------------------------------------------------------------------ 1178*cdf0e10cSrcweir 1179*cdf0e10cSrcweir if (aArg.indexOf( 'j' ) >= 0) 1180*cdf0e10cSrcweir { 1181*cdf0e10cSrcweir // java 1182*cdf0e10cSrcweir benchmark( aSheets[ "java in process" ], 1183*cdf0e10cSrcweir _xSMgr->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.benchmark.JavaTestObject"))), 1184*cdf0e10cSrcweir nLoop / 1000 ); 1185*cdf0e10cSrcweir } 1186*cdf0e10cSrcweir 1187*cdf0e10cSrcweir //------------------------------------------------------------------------------------------ 1188*cdf0e10cSrcweir // dump out tables 1189*cdf0e10cSrcweir 1190*cdf0e10cSrcweir out( "\nTimes( ratio to direct in process )", stream ); 1191*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 1192*cdf0e10cSrcweir out ("; compiled with OSL_DEBUG_LEVEL > 1", stream ); 1193*cdf0e10cSrcweir #endif 1194*cdf0e10cSrcweir out( ":", stream ); 1195*cdf0e10cSrcweir 1196*cdf0e10cSrcweir sal_Int32 nPos = 60; 1197*cdf0e10cSrcweir out( "[direct in process]", stream, nPos ); 1198*cdf0e10cSrcweir t_TimingSheetMap::const_iterator iSheets( aSheets.begin() ); 1199*cdf0e10cSrcweir for ( ; iSheets != aSheets.end(); ++iSheets ) 1200*cdf0e10cSrcweir { 1201*cdf0e10cSrcweir nPos += 40; 1202*cdf0e10cSrcweir out( "[", stream, nPos ); 1203*cdf0e10cSrcweir out( (*iSheets).first.c_str(), stream ); 1204*cdf0e10cSrcweir out( "]", stream ); 1205*cdf0e10cSrcweir } 1206*cdf0e10cSrcweir for ( t_TimeEntryMap::const_iterator iTopics( aDirect._entries.begin() ); 1207*cdf0e10cSrcweir iTopics != aDirect._entries.end(); ++iTopics ) 1208*cdf0e10cSrcweir { 1209*cdf0e10cSrcweir const std::string & rTopic = (*iTopics).first; 1210*cdf0e10cSrcweir 1211*cdf0e10cSrcweir out( "\n", stream ); 1212*cdf0e10cSrcweir out( rTopic.c_str(), stream ); 1213*cdf0e10cSrcweir 1214*cdf0e10cSrcweir out( ":", stream, 58, '.' ); 1215*cdf0e10cSrcweir 1216*cdf0e10cSrcweir sal_Int32 nPos = 60; 1217*cdf0e10cSrcweir 1218*cdf0e10cSrcweir double secs = (*iTopics).second.secPerCall(); 1219*cdf0e10cSrcweir if (secs > 0.0) 1220*cdf0e10cSrcweir { 1221*cdf0e10cSrcweir out( secs * 1000, stream, nPos ); 1222*cdf0e10cSrcweir out( "ms", stream ); 1223*cdf0e10cSrcweir } 1224*cdf0e10cSrcweir else 1225*cdf0e10cSrcweir { 1226*cdf0e10cSrcweir out( "NA", stream, nPos ); 1227*cdf0e10cSrcweir } 1228*cdf0e10cSrcweir 1229*cdf0e10cSrcweir iSheets = aSheets.begin(); 1230*cdf0e10cSrcweir for ( ; iSheets != aSheets.end(); ++iSheets ) 1231*cdf0e10cSrcweir { 1232*cdf0e10cSrcweir const t_TimeEntryMap::const_iterator iFind( (*iSheets).second._entries.find( rTopic ) ); 1233*cdf0e10cSrcweir OSL_ENSURE( iFind != (*iSheets).second._entries.end(), "####" ); 1234*cdf0e10cSrcweir 1235*cdf0e10cSrcweir nPos += 40; 1236*cdf0e10cSrcweir 1237*cdf0e10cSrcweir double secs = (*iFind).second.secPerCall(); 1238*cdf0e10cSrcweir if (secs != 0.0) 1239*cdf0e10cSrcweir { 1240*cdf0e10cSrcweir out( secs * 1000, stream, nPos ); 1241*cdf0e10cSrcweir out( "ms", stream ); 1242*cdf0e10cSrcweir 1243*cdf0e10cSrcweir out( " (", stream ); 1244*cdf0e10cSrcweir double ratio = (*iFind).second.ratio( (*iTopics).second ); 1245*cdf0e10cSrcweir if (ratio != 0.0) 1246*cdf0e10cSrcweir { 1247*cdf0e10cSrcweir out( ratio, stream ); 1248*cdf0e10cSrcweir out( " x)", stream ); 1249*cdf0e10cSrcweir } 1250*cdf0e10cSrcweir else 1251*cdf0e10cSrcweir { 1252*cdf0e10cSrcweir out( "NA)", stream ); 1253*cdf0e10cSrcweir } 1254*cdf0e10cSrcweir } 1255*cdf0e10cSrcweir else 1256*cdf0e10cSrcweir { 1257*cdf0e10cSrcweir out( "NA", stream, nPos ); 1258*cdf0e10cSrcweir } 1259*cdf0e10cSrcweir } 1260*cdf0e10cSrcweir } 1261*cdf0e10cSrcweir } 1262*cdf0e10cSrcweir catch (Exception & rExc) 1263*cdf0e10cSrcweir { 1264*cdf0e10cSrcweir if (stream != stderr && stream != stdout) 1265*cdf0e10cSrcweir ::fclose( stream ); 1266*cdf0e10cSrcweir throw RuntimeException( rExc.Message, rExc.Context ); 1267*cdf0e10cSrcweir } 1268*cdf0e10cSrcweir 1269*cdf0e10cSrcweir if (stream != stderr && stream != stdout) 1270*cdf0e10cSrcweir ::fclose( stream ); 1271*cdf0e10cSrcweir 1272*cdf0e10cSrcweir out( "\n> done.\n" ); 1273*cdf0e10cSrcweir return 0; 1274*cdf0e10cSrcweir } 1275*cdf0e10cSrcweir 1276*cdf0e10cSrcweir } 1277*cdf0e10cSrcweir 1278*cdf0e10cSrcweir 1279*cdf0e10cSrcweir //################################################################################################## 1280*cdf0e10cSrcweir //################################################################################################## 1281*cdf0e10cSrcweir //################################################################################################## 1282*cdf0e10cSrcweir 1283*cdf0e10cSrcweir 1284*cdf0e10cSrcweir extern "C" 1285*cdf0e10cSrcweir { 1286*cdf0e10cSrcweir //================================================================================================== 1287*cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( 1288*cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) 1289*cdf0e10cSrcweir { 1290*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 1291*cdf0e10cSrcweir } 1292*cdf0e10cSrcweir //================================================================================================== 1293*cdf0e10cSrcweir sal_Bool SAL_CALL component_writeInfo( 1294*cdf0e10cSrcweir void * pServiceManager, void * pRegistryKey ) 1295*cdf0e10cSrcweir { 1296*cdf0e10cSrcweir if (pRegistryKey) 1297*cdf0e10cSrcweir { 1298*cdf0e10cSrcweir try 1299*cdf0e10cSrcweir { 1300*cdf0e10cSrcweir Reference< XRegistryKey > xNewKey( 1301*cdf0e10cSrcweir reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( 1302*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) ); 1303*cdf0e10cSrcweir xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) ); 1304*cdf0e10cSrcweir 1305*cdf0e10cSrcweir return sal_True; 1306*cdf0e10cSrcweir } 1307*cdf0e10cSrcweir catch (InvalidRegistryException &) 1308*cdf0e10cSrcweir { 1309*cdf0e10cSrcweir OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); 1310*cdf0e10cSrcweir } 1311*cdf0e10cSrcweir } 1312*cdf0e10cSrcweir return sal_False; 1313*cdf0e10cSrcweir } 1314*cdf0e10cSrcweir //================================================================================================== 1315*cdf0e10cSrcweir void * SAL_CALL component_getFactory( 1316*cdf0e10cSrcweir const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) 1317*cdf0e10cSrcweir { 1318*cdf0e10cSrcweir void * pRet = 0; 1319*cdf0e10cSrcweir 1320*cdf0e10cSrcweir if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) 1321*cdf0e10cSrcweir { 1322*cdf0e10cSrcweir Reference< XSingleServiceFactory > xFactory( createSingleFactory( 1323*cdf0e10cSrcweir reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), 1324*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ), 1325*cdf0e10cSrcweir benchmark_test::TestImpl_create, 1326*cdf0e10cSrcweir benchmark_test::getSupportedServiceNames() ) ); 1327*cdf0e10cSrcweir 1328*cdf0e10cSrcweir if (xFactory.is()) 1329*cdf0e10cSrcweir { 1330*cdf0e10cSrcweir xFactory->acquire(); 1331*cdf0e10cSrcweir pRet = xFactory.get(); 1332*cdf0e10cSrcweir } 1333*cdf0e10cSrcweir } 1334*cdf0e10cSrcweir 1335*cdf0e10cSrcweir return pRet; 1336*cdf0e10cSrcweir } 1337*cdf0e10cSrcweir } 1338