Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / testtools / source / performance / ubtest.cxx
blob838f252e2498aaae9048340f3f19b7e299b36ea2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <stdio.h>
22 #include <math.h>
23 #include <string>
24 #include <boost/unordered_map.hpp>
25 #include <map>
27 #include <osl/diagnose.h>
28 #include <osl/mutex.hxx>
29 #include <osl/module.h>
30 #include <osl/process.h>
31 #include <osl/thread.h>
32 #include <osl/conditn.hxx>
33 #include <osl/time.h>
35 #ifdef SAL_W32
36 #include <windows.h>
37 #else
38 #include <sys/times.h>
39 #include <unistd.h>
40 #endif
42 #include <rtl/string.hxx>
43 #include <rtl/strbuf.hxx>
44 #include <rtl/ustrbuf.hxx>
46 #include <uno/environment.hxx>
47 #include <uno/mapping.hxx>
49 #include <cppuhelper/factory.hxx>
50 #include <cppuhelper/implbase2.hxx>
52 #include <com/sun/star/lang/XServiceInfo.hpp>
53 #include <com/sun/star/lang/XComponent.hpp>
54 #include <com/sun/star/lang/XMain.hpp>
55 #include <com/sun/star/lang/XInitialization.hpp>
56 #include <com/sun/star/loader/XImplementationLoader.hpp>
57 #include <com/sun/star/registry/XRegistryKey.hpp>
58 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
59 #include <com/sun/star/container/XSet.hpp>
60 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
62 #define NLOOP 200000000
64 using namespace osl;
65 using namespace cppu;
66 using namespace com::sun::star::uno;
67 using namespace com::sun::star::lang;
68 using namespace com::sun::star::loader;
69 using namespace com::sun::star::registry;
70 using namespace com::sun::star::bridge;
71 using namespace com::sun::star::container;
72 using namespace com::sun::star::test::performance;
74 using ::rtl::OUString;
75 using ::rtl::OString;
76 using ::rtl::OUStringToOString;
78 #define SERVICENAME "com.sun.star.test.performance.PerformanceTest"
79 #define IMPLNAME "com.sun.star.comp.performance.PerformanceTest"
81 namespace benchmark_test
84 static inline sal_uInt32 getSystemTicks()
86 #ifdef SAL_W32
87 return (sal_uInt32)GetTickCount();
88 #else // only UNX supported for now
89 static sal_uInt32 nImplTicksPerSecond = 0;
90 static double dImplTicksPerSecond;
91 static double dImplTicksULONGMAX;
93 struct tms aTms;
94 sal_uInt32 nTicks = (sal_uInt32)times( &aTms );
96 if ( !nImplTicksPerSecond )
98 nImplTicksPerSecond = sysconf(_SC_CLK_TCK);
99 dImplTicksPerSecond = nImplTicksPerSecond;
100 dImplTicksULONGMAX = (double)(sal_uInt32)ULONG_MAX;
103 double fTicks = nTicks;
104 fTicks *= 1000;
105 fTicks /= dImplTicksPerSecond;
106 fTicks = fmod (fTicks, dImplTicksULONGMAX);
108 return (sal_uInt32)fTicks;
109 #endif
112 //--------------------------------------------------------------------------------------------------
113 static void out( const sal_Char * pText, FILE * stream = stderr,
114 sal_Int32 nStart = -1, sal_Char cFillchar = ' ' )
116 static sal_Int32 s_nPos = 0;
118 sal_Char ar[2] = { cFillchar, 0 };
119 while (s_nPos < nStart)
121 ::fprintf( stream, ar );
122 ++s_nPos;
125 ::fprintf( stream, pText );
127 for ( const sal_Char * p = pText; *p; ++p )
129 if (*p == '\n')
130 s_nPos = 0;
131 else
132 ++s_nPos;
135 //--------------------------------------------------------------------------------------------------
136 static inline void out( const OUString & rText, FILE * stream = stderr,
137 sal_Int32 nStart = -1, sal_Char cFillchar = ' ' )
139 OString aText( OUStringToOString( rText, RTL_TEXTENCODING_ASCII_US ) );
140 out( aText.getStr(), stream, nStart, cFillchar );
142 //--------------------------------------------------------------------------------------------------
143 static inline void out( double fVal, FILE * stream = stderr,
144 sal_Int32 nStart = -1, sal_Char cFillchar = ' ' )
146 sal_Char ar[128];
147 ::snprintf( ar, sizeof(ar), (fVal < 0.000001 ? "%g" : "%f"), fVal );
148 out( ar, stream, nStart, cFillchar );
150 //--------------------------------------------------------------------------------------------------
151 static inline void out( sal_Int64 nVal, FILE * stream = stderr,
152 sal_Int32 nStart = -1, sal_Char cFillchar = ' ' )
154 sal_Char ar[128];
155 ::snprintf( ar, sizeof(ar), "%ld", nVal );
156 out( ar, stream, nStart, cFillchar );
159 //==================================================================================================
160 Reference< XSingleServiceFactory > loadLibComponentFactory(
161 const OUString & rLibName, const OUString & rImplName,
162 const Reference< XMultiServiceFactory > & xSF, const Reference< XRegistryKey > & xKey )
164 Reference< XSingleServiceFactory > xRet;
166 OUStringBuffer aLibNameBuf( 32 );
167 #ifdef SAL_UNX
168 aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM("lib") );
169 aLibNameBuf.append( rLibName );
170 aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM(".so") );
171 #else
172 aLibNameBuf.append( rLibName );
173 aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM(".dll") );
174 #endif
175 OUString aLibName( aLibNameBuf.makeStringAndClear() );
176 oslModule lib = osl_loadModule( aLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
178 if (lib)
180 void * pSym;
182 // ========================= LATEST VERSION =========================
183 OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) );
184 if (pSym = osl_getSymbol( lib, aGetEnvName.pData ))
186 uno_Environment * pCurrentEnv = 0;
187 uno_Environment * pEnv = 0;
188 const sal_Char * pEnvTypeName = 0;
189 (*((component_getImplementationEnvironmentFunc)pSym))( &pEnvTypeName, &pEnv );
191 sal_Bool bNeedsMapping =
192 (pEnv || 0 != rtl_str_compare( pEnvTypeName, CPPU_CURRENT_LANGUAGE_BINDING_NAME ));
194 OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
196 if (bNeedsMapping)
198 if (! pEnv)
199 uno_getEnvironment( &pEnv, aEnvTypeName.pData, 0 );
200 if (pEnv)
202 OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
203 uno_getEnvironment( &pCurrentEnv, aCppEnvTypeName.pData, 0 );
204 if (pCurrentEnv)
205 bNeedsMapping = (pEnv != pCurrentEnv);
209 OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETFACTORY) );
210 if (pSym = osl_getSymbol( lib, aGetFactoryName.pData ))
212 OString aImplName( OUStringToOString( rImplName, RTL_TEXTENCODING_ASCII_US ) );
214 if (bNeedsMapping)
216 if (pEnv && pCurrentEnv)
218 Mapping aCurrent2Env( pCurrentEnv, pEnv );
219 Mapping aEnv2Current( pEnv, pCurrentEnv );
221 if (aCurrent2Env.is() && aEnv2Current.is())
223 void * pSMgr = aCurrent2Env.mapInterface(
224 xSF.get(), ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) );
225 void * pKey = aCurrent2Env.mapInterface(
226 xKey.get(), ::getCppuType( (const Reference< XRegistryKey > *)0 ) );
228 void * pSSF = (*((component_getFactoryFunc)pSym))(
229 aImplName.getStr(), pSMgr, pKey );
231 if (pKey)
232 (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pKey );
233 if (pSMgr)
234 (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSMgr );
236 if (pSSF)
238 aEnv2Current.mapInterface(
239 reinterpret_cast< void ** >( &xRet ),
240 pSSF, ::getCppuType( (const Reference< XSingleServiceFactory > *)0 ) );
241 (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSSF );
246 else
248 XSingleServiceFactory * pRet = (XSingleServiceFactory *)
249 (*((component_getFactoryFunc)pSym))(
250 aImplName.getStr(), xSF.get(), xKey.get() );
251 if (pRet)
253 xRet = pRet;
254 pRet->release();
259 if (pEnv)
260 (*pEnv->release)( pEnv );
261 if (pCurrentEnv)
262 (*pCurrentEnv->release)( pCurrentEnv );
265 // ========================= PREVIOUS VERSION =========================
266 else
268 OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(CREATE_COMPONENT_FACTORY_FUNCTION) );
269 if (pSym = osl_getSymbol( lib, aGetFactoryName.pData ))
271 OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
272 OUString aUnoEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) );
273 Mapping aUno2Cpp( aUnoEnvTypeName, aCppEnvTypeName );
274 Mapping aCpp2Uno( aCppEnvTypeName, aUnoEnvTypeName );
275 OSL_ENSURE( aUno2Cpp.is() && aCpp2Uno.is(), "### cannot get uno mappings!" );
277 if (aUno2Cpp.is() && aCpp2Uno.is())
279 uno_Interface * pUComponentFactory = 0;
281 uno_Interface * pUSFactory = (uno_Interface *)aCpp2Uno.mapInterface(
282 xSF.get(), ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) );
283 uno_Interface * pUKey = (uno_Interface *)aCpp2Uno.mapInterface(
284 xKey.get(), ::getCppuType( (const Reference< XRegistryKey > *)0 ) );
286 pUComponentFactory = (*((CreateComponentFactoryFunc)pSym))(
287 rImplName.getStr(), pUSFactory, pUKey );
289 if (pUKey)
290 (*pUKey->release)( pUKey );
291 if (pUSFactory)
292 (*pUSFactory->release)( pUSFactory );
294 if (pUComponentFactory)
296 XSingleServiceFactory * pXFactory =
297 (XSingleServiceFactory *)aUno2Cpp.mapInterface(
298 pUComponentFactory, ::getCppuType( (const Reference< XSingleServiceFactory > *)0 ) );
299 (*pUComponentFactory->release)( pUComponentFactory );
301 if (pXFactory)
303 xRet = pXFactory;
304 pXFactory->release();
311 if (! xRet.is())
312 osl_unloadModule( lib );
315 return xRet;
317 //--------------------------------------------------------------------------------------------------
318 template< class T >
319 static void createInstance( Reference< T > & rxOut,
320 const Reference< XMultiServiceFactory > & xMgr,
321 const OUString & rServiceName )
322 throw (RuntimeException)
324 Reference< XInterface > x( xMgr->createInstance( rServiceName ), UNO_QUERY );
326 if (! x.is())
328 static sal_Bool s_bSet = sal_False;
329 if (! s_bSet)
331 MutexGuard aGuard( Mutex::getGlobalMutex() );
332 if (! s_bSet)
334 Reference< XSet > xSet( xMgr, UNO_QUERY );
335 if (xSet.is())
337 // acceptor
338 xSet->insert( makeAny( loadLibComponentFactory(
339 OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor") ),
340 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.Acceptor") ),
341 xMgr, Reference< XRegistryKey >() ) ) );
342 // connector
343 xSet->insert( makeAny( loadLibComponentFactory(
344 OUString( RTL_CONSTASCII_USTRINGPARAM("connectr") ),
345 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.Connector") ),
346 xMgr, Reference< XRegistryKey >() ) ) );
347 // iiop bridge
348 xSet->insert( makeAny( loadLibComponentFactory(
349 OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge") ),
350 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.various") ),
351 xMgr, Reference< XRegistryKey >() ) ) );
352 // bridge factory
353 xSet->insert( makeAny( loadLibComponentFactory(
354 OUString( RTL_CONSTASCII_USTRINGPARAM("brdgfctr") ),
355 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.BridgeFactory") ),
356 xMgr, Reference< XRegistryKey >() ) ) );
357 // uno url resolver
358 xSet->insert( makeAny( loadLibComponentFactory(
359 OUString( RTL_CONSTASCII_USTRINGPARAM("uuresolver") ),
360 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.bridge.UnoUrlResolver") ),
361 xMgr, Reference< XRegistryKey >() ) ) );
362 // java loader
363 // xSet->insert( makeAny( loadLibComponentFactory(
364 // OUString( RTL_CONSTASCII_USTRINGPARAM("javaloader") ),
365 // OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.JavaComponentLoader") ),
366 // xMgr, Reference< XRegistryKey >() ) ) );
368 s_bSet = sal_True;
371 x = xMgr->createInstance( rServiceName );
374 if (! x.is())
376 OUStringBuffer buf( 64 );
377 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot get service instance \"") );
378 buf.append( rServiceName );
379 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
380 throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
383 rxOut = Reference< T >::query( x );
384 if (! rxOut.is())
386 OUStringBuffer buf( 64 );
387 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("service instance \"") );
388 buf.append( rServiceName );
389 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" does not support demanded interface \"") );
390 const Type & rType = ::getCppuType( (const Reference< T > *)0 );
391 buf.append( rType.getTypeName() );
392 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
393 throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
397 //--------------------------------------------------------------------------------------------------
398 inline static Sequence< OUString > getSupportedServiceNames()
400 OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
401 return Sequence< OUString >( &aName, 1 );
404 //==================================================================================================
405 class TestImpl : public WeakImplHelper2< XServiceInfo, XMain >
407 Reference< XMultiServiceFactory > _xSMgr;
409 Reference< XInterface > _xDirect;
410 Reference< XInterface > getDirect() throw (Exception);
411 Reference< XInterface > resolveObject( const OUString & rUnoUrl ) throw (Exception);
413 public:
414 TestImpl( const Reference< XMultiServiceFactory > & xSMgr );
415 virtual ~TestImpl();
417 // XServiceInfo
418 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
419 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
420 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
422 // XMain
423 virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException);
426 //##################################################################################################
428 //__________________________________________________________________________________________________
429 TestImpl::TestImpl( const Reference< XMultiServiceFactory > & xSMgr )
430 : _xSMgr( xSMgr )
433 //__________________________________________________________________________________________________
434 TestImpl::~TestImpl()
438 //==================================================================================================
439 static Reference< XInterface > SAL_CALL TestImpl_create( const Reference< XMultiServiceFactory > & xSMgr )
441 return Reference< XInterface >( *new TestImpl( xSMgr ) );
444 // XServiceInfo
445 //__________________________________________________________________________________________________
446 OUString TestImpl::getImplementationName()
447 throw (RuntimeException)
449 return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
451 //__________________________________________________________________________________________________
452 sal_Bool TestImpl::supportsService( const OUString & rServiceName )
453 throw (RuntimeException)
455 const Sequence< OUString > & rSNL = getSupportedServiceNames();
456 const OUString * pArray = rSNL.getConstArray();
457 for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
459 if (pArray[nPos] == rServiceName)
460 return sal_True;
462 return sal_False;
464 //__________________________________________________________________________________________________
465 Sequence< OUString > TestImpl::getSupportedServiceNames()
466 throw (RuntimeException)
468 return benchmark_test::getSupportedServiceNames();
471 //__________________________________________________________________________________________________
472 Reference< XInterface > TestImpl::getDirect()
473 throw (Exception)
475 if (! _xDirect.is())
477 MutexGuard aGuard( Mutex::getGlobalMutex() );
478 if (! _xDirect.is())
480 Reference< XSingleServiceFactory > xFac( loadLibComponentFactory(
481 OUString( RTL_CONSTASCII_USTRINGPARAM("perfobj") ),
482 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.performance.PerformanceTestObject") ),
483 _xSMgr, Reference< XRegistryKey >() ) );
484 if (! xFac.is())
485 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no test object available!") ), Reference< XInterface >() );
486 _xDirect = xFac->createInstance();
489 return _xDirect;
491 //--------------------------------------------------------------------------------------------------
492 Reference< XInterface > TestImpl::resolveObject( const OUString & rUnoUrl )
493 throw (Exception)
495 Reference< XUnoUrlResolver > xResolver;
496 createInstance(
497 xResolver, _xSMgr,
498 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.UnoUrlResolver") ) );
500 Reference< XInterface > xResolvedObject( xResolver->resolve( rUnoUrl ) );
502 if (! xResolvedObject.is())
504 OUStringBuffer buf( 32 );
505 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot resolve object \"") );
506 buf.append( rUnoUrl );
507 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
508 throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
511 return xResolvedObject;
514 //==================================================================================================
515 class TimeEntry
517 sal_Int64 nLoop;
518 sal_uInt32 nTicks;
520 public:
521 TimeEntry()
523 TimeEntry( sal_Int64 nLoop_, sal_uInt32 nTicks_ )
524 : nLoop( nLoop_ )
525 , nTicks( nTicks_ )
528 inline double secPerCall() const
529 { return (((double)nTicks) / (nLoop * 1000)); }
531 double ratio( const TimeEntry & rEntry ) const;
533 //__________________________________________________________________________________________________
534 double TimeEntry::ratio( const TimeEntry & rEntry ) const
536 double f = rEntry.nTicks * nLoop;
537 if (f == 0.0)
539 return 0.0;
541 else
543 return (((double)(nTicks * rEntry.nLoop)) / f);
547 //==================================================================================================
548 typedef std::map< std::string, TimeEntry > t_TimeEntryMap;
550 //==================================================================================================
551 struct TimingSheet
553 t_TimeEntryMap _entries;
554 void insert( const sal_Char * pText, sal_Int64 nLoop, sal_uInt32 nTicks );
556 //__________________________________________________________________________________________________
557 void TimingSheet::insert( const sal_Char * pText, sal_Int64 nLoop, sal_uInt32 nTicks )
559 _entries[ pText ] = TimeEntry( nLoop, nTicks );
562 //==================================================================================================
563 typedef boost::unordered_map< std::string, TimingSheet > t_TimingSheetMap;
565 //--------------------------------------------------------------------------------------------------
566 static void benchmark(
567 TimingSheet & rSheet, const Reference< XInterface > & xInstance, sal_Int64 nLoop )
568 throw (Exception)
570 Reference< XPerformanceTest > xBench( xInstance, UNO_QUERY );
571 if (! xBench.is())
572 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("illegal test object!") ), Reference< XInterface >() );
574 sal_Int64 i;
575 sal_uInt32 tStart, tEnd;
577 const Type & rKnownType = ::getCppuType( (const Reference< XPerformanceTest > *)0 );
578 const Type & rUnKnownType = ::getCppuType( (const Reference< XSet > *)0 );
580 ComplexTypes aDummyStruct;
582 //------------------------------------
583 // oneway calls
584 i = nLoop;
585 tStart = getSystemTicks();
586 while (i--)
587 xBench->async();
588 sal_uInt32 tEndSend = getSystemTicks();
589 xBench->sync();
590 tEnd = getSystemTicks();
591 rSheet.insert( "1a: sending simple oneway calls (no params, no return)", nLoop, tEndSend - tStart );
592 rSheet.insert( "1b: simple oneway calls (no params, no return)", nLoop, tEnd - tStart );
593 // synchron calls
594 i = nLoop;
595 tStart = getSystemTicks();
596 while (i--)
597 xBench->sync();
598 xBench->sync();
599 tEnd = getSystemTicks();
600 rSheet.insert( "1c: simple synchron calls (no params no return)", nLoop+1, tEnd - tStart );
602 // acquire
603 i = nLoop;
604 tStart = getSystemTicks();
605 while (i--)
606 xBench->acquire();
607 tEnd = getSystemTicks();
608 rSheet.insert( "2a: interface acquire() calls", nLoop, tEnd - tStart );
609 // release
610 i = nLoop;
611 tStart = getSystemTicks();
612 while (i--)
613 xBench->release();
614 tEnd = getSystemTicks();
615 rSheet.insert( "2b: interface release() calls", nLoop, tEnd - tStart );
617 // queryInterface() for known type
618 i = nLoop;
619 tStart = getSystemTicks();
620 while (i--)
621 xBench->queryInterface( rKnownType );
622 tEnd = getSystemTicks();
623 rSheet.insert( "2c: interface query for implemented type", nLoop, tEnd - tStart );
624 // queryInterface() for unknown type
625 i = nLoop;
626 tStart = getSystemTicks();
627 while (i--)
628 xBench->queryInterface( rUnKnownType );
629 tEnd = getSystemTicks();
630 rSheet.insert( "2d: interface query for unknown type", nLoop, tEnd - tStart );
632 // create and forget objects
633 Reference< XPerformanceTest > xBench2( xBench );
634 i = nLoop;
635 tStart = getSystemTicks();
636 while (i--)
637 xBench2 = xBench2->createObject();
638 tEnd = getSystemTicks();
639 rSheet.insert( "3a: create and release test objects", nLoop, tEnd - tStart );
641 // hold new objects
642 Sequence< Reference< XInterface > > aSeq( nLoop / 100 );
643 Reference< XInterface > * pSeq = aSeq.getArray();
644 xBench2 = xBench;
645 i = aSeq.getLength();
646 tStart = getSystemTicks();
647 while (i--)
648 pSeq[i] = xBench2 = xBench2->createObject();
649 tEnd = getSystemTicks();
650 rSheet.insert( "3b: create and hold test objects", nLoop, tEnd - tStart );
652 // structs
653 i = nLoop;
654 tStart = getSystemTicks();
655 while (i--)
656 xBench->complex_in( aDummyStruct );
657 tEnd = getSystemTicks();
658 rSheet.insert( "4a: complex_in() calls (in struct; return struct)", nLoop, tEnd - tStart );
659 i = nLoop;
660 tStart = getSystemTicks();
661 while (i--)
662 xBench->complex_inout( aDummyStruct );
663 tEnd = getSystemTicks();
664 rSheet.insert( "4b: complex_inout() calls (inout struct; return struct)", nLoop, tEnd - tStart );
666 i = nLoop;
667 tStart = getSystemTicks();
668 while (i--)
669 xBench->complex_oneway( aDummyStruct );
670 tEnd = getSystemTicks();
671 rSheet.insert( "4c: complex_oneway() oneway calls (in struct)", nLoop, tEnd - tStart );
672 i = nLoop;
673 tStart = getSystemTicks();
674 while (i--)
675 xBench->complex_noreturn( aDummyStruct );
676 tEnd = getSystemTicks();
677 rSheet.insert( "4d: complex_noreturn() calls (in struct)", nLoop, tEnd - tStart );
679 // attributes, get() methods
680 i = nLoop;
681 tStart = getSystemTicks();
682 while (i--)
683 xBench->getLong();
684 tEnd = getSystemTicks();
685 rSheet.insert( "5a: getLong() call", nLoop, tEnd - tStart );
686 i = nLoop;
687 tStart = getSystemTicks();
688 while (i--)
689 xBench->getLong_attr();
690 tEnd = getSystemTicks();
691 rSheet.insert( "5b: get long attribute", nLoop, tEnd - tStart );
693 i = nLoop;
694 tStart = getSystemTicks();
695 while (i--)
696 xBench->setLong( 0 );
697 tEnd = getSystemTicks();
698 rSheet.insert( "5c: setLong() call", nLoop, tEnd - tStart );
699 i = nLoop;
700 tStart = getSystemTicks();
701 while (i--)
702 xBench->setLong_attr( 0 );
703 tEnd = getSystemTicks();
704 rSheet.insert( "5d: set long attribute", nLoop, tEnd - tStart );
706 i = nLoop;
707 tStart = getSystemTicks();
708 while (i--)
709 xBench->getHyper();
710 tEnd = getSystemTicks();
711 rSheet.insert( "5e: getHyper() call", nLoop, tEnd - tStart );
712 i = nLoop;
713 tStart = getSystemTicks();
714 while (i--)
715 xBench->getHyper_attr();
716 tEnd = getSystemTicks();
717 rSheet.insert( "5f: get hyper attribute", nLoop, tEnd - tStart );
719 i = nLoop;
720 tStart = getSystemTicks();
721 while (i--)
722 xBench->setHyper( 0 );
723 tEnd = getSystemTicks();
724 rSheet.insert( "5g: setHyper() call", nLoop, tEnd - tStart );
725 i = nLoop;
726 tStart = getSystemTicks();
727 while (i--)
728 xBench->setHyper_attr( 0 );
729 tEnd = getSystemTicks();
730 rSheet.insert( "5h: set hyper attribute", nLoop, tEnd - tStart );
732 i = nLoop;
733 tStart = getSystemTicks();
734 while (i--)
735 xBench->getFloat();
736 tEnd = getSystemTicks();
737 rSheet.insert( "5i: getFloat() call", nLoop, tEnd - tStart );
738 i = nLoop;
739 tStart = getSystemTicks();
740 while (i--)
741 xBench->getFloat_attr();
742 tEnd = getSystemTicks();
743 rSheet.insert( "5j: get float attribute",nLoop, tEnd - tStart );
745 i = nLoop;
746 tStart = getSystemTicks();
747 while (i--)
748 xBench->setFloat( 0.0 );
749 tEnd = getSystemTicks();
750 rSheet.insert( "5k: setFloat() call", nLoop, tEnd - tStart );
751 i = nLoop;
752 tStart = getSystemTicks();
753 while (i--)
754 xBench->setFloat_attr( 0.0 );
755 tEnd = getSystemTicks();
756 rSheet.insert( "5l: set float attribute", nLoop, tEnd - tStart );
758 i = nLoop;
759 tStart = getSystemTicks();
760 while (i--)
761 xBench->getDouble();
762 tEnd = getSystemTicks();
763 rSheet.insert( "5m: getDouble() call", nLoop, tEnd - tStart );
764 i = nLoop;
765 tStart = getSystemTicks();
766 while (i--)
767 xBench->getDouble_attr();
768 tEnd = getSystemTicks();
769 rSheet.insert( "5n: get double attribute", nLoop, tEnd - tStart );
770 i = nLoop;
771 tStart = getSystemTicks();
772 while (i--)
773 xBench->setDouble( 0.0 );
774 tEnd = getSystemTicks();
775 rSheet.insert( "5o: setDouble() call", nLoop, tEnd - tStart );
776 i = nLoop;
777 tStart = getSystemTicks();
778 while (i--)
779 xBench->setDouble_attr( 0.0 );
780 tEnd = getSystemTicks();
781 rSheet.insert( "5p: set double attribute", nLoop, tEnd - tStart );
783 i = nLoop;
784 tStart = getSystemTicks();
785 while (i--)
786 xBench->getString();
787 tEnd = getSystemTicks();
788 rSheet.insert( "6a: getString() call (empty)", nLoop, tEnd - tStart );
789 i = nLoop;
790 tStart = getSystemTicks();
791 while (i--)
792 xBench->getString_attr();
793 tEnd = getSystemTicks();
794 rSheet.insert( "6b: get empty string attribute", nLoop, tEnd - tStart );
796 i = nLoop;
797 OUString aDummyString;
798 tStart = getSystemTicks();
799 while (i--)
800 xBench->setString( aDummyString );
801 tEnd = getSystemTicks();
802 rSheet.insert( "6c: setString() call (emtpy)", nLoop, tEnd - tStart );
803 i = nLoop;
804 tStart = getSystemTicks();
805 while (i--)
806 xBench->setString_attr( aDummyString );
807 tEnd = getSystemTicks();
808 rSheet.insert( "6d: set empty string attribute", nLoop, tEnd - tStart );
810 i = nLoop;
811 tStart = getSystemTicks();
812 while (i--)
813 xBench->getInterface();
814 tEnd = getSystemTicks();
815 rSheet.insert( "7a: getInterface() call (null)", nLoop, tEnd - tStart );
816 i = nLoop;
817 tStart = getSystemTicks();
818 while (i--)
819 xBench->getInterface_attr();
820 tEnd = getSystemTicks();
821 rSheet.insert( "7b: get interface attribute", nLoop, tEnd - tStart );
823 i = nLoop;
824 Reference< XInterface > aDummyInterface;
825 tStart = getSystemTicks();
826 while (i--)
827 xBench->setInterface( aDummyInterface );
828 tEnd = getSystemTicks();
829 rSheet.insert( "7c: setInterface() call (null)", nLoop, tEnd - tStart );
830 i = nLoop;
831 tStart = getSystemTicks();
832 while (i--)
833 xBench->setInterface_attr( Reference< XInterface >() );
834 tEnd = getSystemTicks();
835 rSheet.insert( "7d: set interface attribute", nLoop, tEnd - tStart );
837 i = nLoop;
838 tStart = getSystemTicks();
839 while (i--)
840 xBench->getAny();
841 tEnd = getSystemTicks();
842 rSheet.insert( "8a: getAny() call (empty)", nLoop, tEnd - tStart );
843 i = nLoop;
844 tStart = getSystemTicks();
845 while (i--)
846 xBench->getAny_attr();
847 tEnd = getSystemTicks();
848 rSheet.insert( "8b: get empty any attribute", nLoop, tEnd - tStart );
850 i = nLoop;
851 Any aDummyAny;
852 tStart = getSystemTicks();
853 while (i--)
854 xBench->setAny( aDummyAny );
855 tEnd = getSystemTicks();
856 rSheet.insert( "8c: setAny() call (empty)", nLoop, tEnd - tStart );
857 i = nLoop;
858 tStart = getSystemTicks();
859 while (i--)
860 xBench->setAny_attr( aDummyAny );
861 tEnd = getSystemTicks();
862 rSheet.insert( "8d: set empty any attribute", nLoop, tEnd - tStart );
864 i = nLoop;
865 tStart = getSystemTicks();
866 while (i--)
867 xBench->getSequence();
868 tEnd = getSystemTicks();
869 rSheet.insert( "9a: getSequence() call (empty)", nLoop, tEnd - tStart );
870 i = nLoop;
871 tStart = getSystemTicks();
872 while (i--)
873 xBench->getSequence_attr();
874 tEnd = getSystemTicks();
875 rSheet.insert( "9b: get empty sequence attribute", nLoop, tEnd - tStart );
876 i = nLoop;
877 Sequence< Reference< XInterface > > aDummySeq;
878 tStart = getSystemTicks();
879 while (i--)
880 xBench->setSequence( aDummySeq );
881 tEnd = getSystemTicks();
882 rSheet.insert( "9c: setSequence() call (empty)", nLoop, tEnd - tStart );
883 i = nLoop;
884 tStart = getSystemTicks();
885 while (i--)
886 xBench->setSequence_attr( aDummySeq );
887 tEnd = getSystemTicks();
888 rSheet.insert( "9d: set empty sequence attribute", nLoop, tEnd - tStart );
890 i = nLoop;
891 tStart = getSystemTicks();
892 while (i--)
893 xBench->getStruct();
894 tEnd = getSystemTicks();
895 rSheet.insert( "Aa: getStruct() call", nLoop, tEnd - tStart );
896 i = nLoop;
897 tStart = getSystemTicks();
898 while (i--)
899 xBench->getStruct_attr();
900 tEnd = getSystemTicks();
901 rSheet.insert( "Ab: get struct attribute", nLoop, tEnd - tStart );
903 i = nLoop;
904 tStart = getSystemTicks();
905 while (i--)
906 xBench->setStruct( aDummyStruct );
907 tEnd = getSystemTicks();
908 rSheet.insert( "Ac: setStruct() call", nLoop, tEnd - tStart );
909 i = nLoop;
910 tStart = getSystemTicks();
911 while (i--)
912 xBench->setStruct_attr( aDummyStruct );
913 tEnd = getSystemTicks();
914 rSheet.insert( "Ad: set struct attribute", nLoop, tEnd - tStart );
916 // load
917 // i = nLoop;
918 // tStart = getSystemTicks();
919 // while (i--)
920 // xBench->setSequence( aSeq );
921 // tEnd = getSystemTicks();
922 // rSheet.insert( "transfer of exisiting objects", nLoop, tEnd - tStart );
924 // exceptions
925 i = nLoop;
926 tStart = getSystemTicks();
927 while (i--)
931 xBench->raiseRuntimeException();
933 catch (RuntimeException &)
937 tEnd = getSystemTicks();
938 rSheet.insert( "Ba: raising RuntimeException", nLoop, tEnd - tStart );
940 //------------------------------------
943 //--------------------------------------------------------------------------------------------------
944 static OUString extractParam( const Sequence< OUString > & rArgs, const OUString & rParam )
946 const OUString * pArgs = rArgs.getConstArray();
947 for ( sal_Int32 nPos = rArgs.getLength(); nPos--; )
949 if (pArgs[nPos].indexOf( rParam ) == 0 &&
950 pArgs[nPos].getLength() > (rParam.getLength()+1))
952 return pArgs[nPos].copy( rParam.getLength() +1 ); // XXX=bla
955 return OUString();
958 const sal_Int32 nMagicNumberDirect = 34000;
960 //XMain
961 //__________________________________________________________________________________________________
962 sal_Int32 TestImpl::run( const Sequence< OUString > & rArgs )
963 throw (RuntimeException)
965 // defaults
966 FILE * stream = stderr;
967 sal_Int64 nLoop = NLOOP;
968 OUString aArg( RTL_CONSTASCII_USTRINGPARAM("dms") );
972 OUString aLoopStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("loop") ) ) );
973 if (aLoopStr.getLength())
975 sal_Int64 n = aLoopStr.toInt64();
976 if (n > 0)
977 nLoop = n;
980 OUString aDurationStr( extractParam( rArgs , OUString( RTL_CONSTASCII_USTRINGPARAM("duration" ) ) ) );
981 if( aDurationStr.getLength() )
983 sal_Int64 n = aDurationStr.toInt64();
984 if( n >0 )
985 nLoop = nMagicNumberDirect * n;
988 OUString aLogStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("log") ) ) );
989 if (aLogStr.getLength())
991 if (aLogStr.compareToAscii( "stderr" ) == 0)
993 stream = stderr;
995 else if (aLogStr.compareToAscii( "stdout" ) == 0)
997 stream = stdout;
999 else
1001 OString aFileName( OUStringToOString( aLogStr, RTL_TEXTENCODING_ASCII_US ) );
1002 stream = ::fopen( aFileName.getStr(), "w" );
1003 if (! stream)
1005 OUStringBuffer buf( 32 );
1006 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot open file for writing: \"") );
1007 buf.append( aLogStr );
1008 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
1009 throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
1014 OUString aArgStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("opt") ) ) );
1015 if (aArgStr.getLength())
1017 aArg = aArgStr;
1020 if (! rArgs.getLength())
1021 out( "\n> no options given, using defaults" );
1023 // params
1024 out( "\n> opt=" );
1025 out( aArg );
1026 out( " log=" );
1027 if (stream == stderr)
1028 out( "stderr" );
1029 else if (stream == stdout)
1030 out( "stdout loop=" );
1031 else
1032 out( aLogStr );
1033 out( " loop=" );
1034 out( nLoop );
1035 out( "\n" );
1036 t_TimingSheetMap aSheets;
1037 TimingSheet aDirect;
1039 //------------------------------------------------------------------------------------------
1041 if (aArg.indexOf( 'd' ) >= 0)
1043 // in process direct test
1044 sal_uInt32 nStart = getSystemTicks();
1045 benchmark( aDirect, getDirect(), nLoop );
1046 sal_uInt32 nEnd = getSystemTicks();
1047 fprintf( stderr, "Duration (direct in process): %g s\n", (nEnd - nStart)/1000. );
1050 //------------------------------------------------------------------------------------------
1052 if (aArg.indexOf( 'm' ) >= 0)
1054 // in process uno dispatch
1055 Environment aCppEnv, aAnoCppEnv;
1056 OUString aCurrentLanguageBindingName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
1057 uno_getEnvironment( reinterpret_cast< uno_Environment ** >( &aCppEnv ),
1058 aCurrentLanguageBindingName.pData, 0 );
1059 // anonymous
1060 uno_createEnvironment( reinterpret_cast< uno_Environment ** >( &aAnoCppEnv ),
1061 aCurrentLanguageBindingName.pData, 0 );
1063 // pseudo mapping uno<->uno: does nothing!
1064 Mapping aMapping( aCppEnv.get(), aAnoCppEnv.get(), OUString( RTL_CONSTASCII_USTRINGPARAM("pseudo") ) );
1065 if (! aMapping.is())
1066 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no pseudo mapping available!") ), Reference< XInterface >() );
1068 Reference< XInterface > xMapped;
1069 Reference< XInterface > xDirect( getDirect() );
1070 aMapping.mapInterface( reinterpret_cast< void ** >( &xMapped ), xDirect.get(),
1071 ::getCppuType( &xDirect ) );
1072 if (! xMapped.is())
1073 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("mapping object failed!") ), Reference< XInterface >() );
1075 sal_uInt32 nStart = getSystemTicks();
1076 benchmark( aSheets[ "mapped in process" ], xMapped, nLoop / 100 );
1077 sal_uInt32 nEnd = getSystemTicks();
1078 fprintf( stderr, "Duration (mapped in process): %g s\n", (nStart - nEnd)/1000. );
1081 //------------------------------------------------------------------------------------------
1083 if (aArg.indexOf( 's' ) >= 0)
1085 // start server process
1086 oslSecurity hSecurity = osl_getCurrentSecurity();
1087 if (! hSecurity)
1088 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get current security handle!") ), Reference< XInterface >() );
1090 OUString aArgs[] = {
1091 OUString( RTL_CONSTASCII_USTRINGPARAM("-c") ),
1092 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.performance.PerformanceTestObject") ),
1093 OUString( RTL_CONSTASCII_USTRINGPARAM("-l") ),
1094 #ifdef SAL_UNX
1095 OUString( RTL_CONSTASCII_USTRINGPARAM("libperfobj.so") ),
1096 #else
1097 OUString( RTL_CONSTASCII_USTRINGPARAM("perfobj.dll") ),
1098 #endif
1099 OUString( RTL_CONSTASCII_USTRINGPARAM("-r") ),
1100 OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb") ),
1101 OUString( RTL_CONSTASCII_USTRINGPARAM("-u") ),
1102 OUString( RTL_CONSTASCII_USTRINGPARAM("uno:socket,host=localhost,port=6000;iiop;TestRemoteObject") ),
1103 OUString( RTL_CONSTASCII_USTRINGPARAM("--singleaccept") )
1105 rtl_uString * pArgs[] = {
1106 aArgs[0].pData,
1107 aArgs[1].pData,
1108 aArgs[2].pData,
1109 aArgs[3].pData,
1110 aArgs[4].pData,
1111 aArgs[5].pData,
1112 aArgs[6].pData,
1113 aArgs[7].pData,
1114 aArgs[8].pData,
1117 out( "\n> executing: \"uno" );
1118 for ( sal_Int32 nPos = 0; nPos < (sizeof(aArgs) / sizeof(OUString)); ++nPos )
1120 out( " " );
1121 out( aArgs[nPos] );
1123 out( "\" ..." );
1125 oslProcess hProcess = 0;
1126 OUString aUnoExe( RTL_CONSTASCII_USTRINGPARAM("uno") );
1127 OUString aWorkingDir( RTL_CONSTASCII_USTRINGPARAM(".") );
1128 osl_executeProcess(
1129 aUnoExe.pData, pArgs, sizeof(aArgs) / sizeof(OUString),
1130 osl_Process_SEARCHPATH | osl_Process_DETACHED | osl_Process_NORMAL,
1131 hSecurity, aWorkingDir.pData, 0, 0, &hProcess );
1133 osl_freeSecurityHandle( hSecurity );
1134 if (! hProcess)
1135 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("cannot start server process!") ), Reference< XInterface >() );
1136 osl_freeProcessHandle( hProcess );
1138 // wait three seconds
1139 TimeValue threeSeconds;
1140 threeSeconds.Seconds = 3;
1141 osl_waitThread( &threeSeconds );
1143 // connect and resolve outer process object
1144 Reference< XInterface > xResolvedObject( resolveObject( OUString(
1145 RTL_CONSTASCII_USTRINGPARAM("uno:socket,host=localhost,port=6000;iiop;TestRemoteObject") ) ) );
1147 benchmark( aSheets[ "remote same host" ], xResolvedObject, nLoop / 300 );
1150 //------------------------------------------------------------------------------------------
1152 if (aArg.indexOf( 'r' ) >= 0)
1154 // remote
1155 OUString aUnoUrl( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("url") ) ) );
1156 if (! aUnoUrl.getLength())
1157 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("performance test r(emote) needs additional uno url!") ), Reference< XInterface >() );
1159 // connect and resolve outer process object
1160 Reference< XInterface > xResolvedObject( resolveObject( aUnoUrl ) );
1162 sal_Int32 t1 = getSystemTicks();
1163 OString o = OUStringToOString( aUnoUrl, RTL_TEXTENCODING_ASCII_US );
1164 benchmark( aSheets[ o.getStr() ], xResolvedObject, nLoop / 900 );
1165 sal_Int32 t2 = getSystemTicks();
1166 fprintf( stderr, "Duration (%s): %g s\n", o.getStr(),(t2 - t1)/1000. );
1169 //------------------------------------------------------------------------------------------
1171 if (aArg.indexOf( 'j' ) >= 0)
1173 // java
1174 benchmark( aSheets[ "java in process" ],
1175 _xSMgr->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.benchmark.JavaTestObject"))),
1176 nLoop / 1000 );
1179 //------------------------------------------------------------------------------------------
1180 // dump out tables
1182 out( "\nTimes( ratio to direct in process )", stream );
1183 #if OSL_DEBUG_LEVEL > 1
1184 out ("; compiled with OSL_DEBUG_LEVEL > 1", stream );
1185 #endif
1186 out( ":", stream );
1188 sal_Int32 nPos = 60;
1189 out( "[direct in process]", stream, nPos );
1190 t_TimingSheetMap::const_iterator iSheets( aSheets.begin() );
1191 for ( ; iSheets != aSheets.end(); ++iSheets )
1193 nPos += 40;
1194 out( "[", stream, nPos );
1195 out( (*iSheets).first.c_str(), stream );
1196 out( "]", stream );
1198 for ( t_TimeEntryMap::const_iterator iTopics( aDirect._entries.begin() );
1199 iTopics != aDirect._entries.end(); ++iTopics )
1201 const std::string & rTopic = (*iTopics).first;
1203 out( "\n", stream );
1204 out( rTopic.c_str(), stream );
1206 out( ":", stream, 58, '.' );
1208 sal_Int32 nPos = 60;
1210 double secs = (*iTopics).second.secPerCall();
1211 if (secs > 0.0)
1213 out( secs * 1000, stream, nPos );
1214 out( "ms", stream );
1216 else
1218 out( "NA", stream, nPos );
1221 iSheets = aSheets.begin();
1222 for ( ; iSheets != aSheets.end(); ++iSheets )
1224 const t_TimeEntryMap::const_iterator iFind( (*iSheets).second._entries.find( rTopic ) );
1225 OSL_ENSURE( iFind != (*iSheets).second._entries.end(), "####" );
1227 nPos += 40;
1229 double secs = (*iFind).second.secPerCall();
1230 if (secs != 0.0)
1232 out( secs * 1000, stream, nPos );
1233 out( "ms", stream );
1235 out( " (", stream );
1236 double ratio = (*iFind).second.ratio( (*iTopics).second );
1237 if (ratio != 0.0)
1239 out( ratio, stream );
1240 out( " x)", stream );
1242 else
1244 out( "NA)", stream );
1247 else
1249 out( "NA", stream, nPos );
1254 catch (Exception & rExc)
1256 if (stream != stderr && stream != stdout)
1257 ::fclose( stream );
1258 throw RuntimeException( rExc.Message, rExc.Context );
1261 if (stream != stderr && stream != stdout)
1262 ::fclose( stream );
1264 out( "\n> done.\n" );
1265 return 0;
1271 //##################################################################################################
1272 //##################################################################################################
1273 //##################################################################################################
1276 extern "C"
1278 //==================================================================================================
1279 sal_Bool SAL_CALL component_writeInfo(
1280 void * pServiceManager, void * pRegistryKey )
1282 if (pRegistryKey)
1286 Reference< XRegistryKey > xNewKey(
1287 reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
1288 OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) );
1289 xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) );
1291 return sal_True;
1293 catch (InvalidRegistryException &)
1295 OSL_FAIL( "### InvalidRegistryException!" );
1298 return sal_False;
1300 //==================================================================================================
1301 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
1302 const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
1304 void * pRet = 0;
1306 if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
1308 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
1309 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
1310 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
1311 benchmark_test::TestImpl_create,
1312 benchmark_test::getSupportedServiceNames() ) );
1314 if (xFactory.is())
1316 xFactory->acquire();
1317 pRet = xFactory.get();
1321 return pRet;
1325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */