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