perfsrv/memspy/Engine/Source/Helpers/MemSpyEngineHelperServer.cpp
changeset 51 98307c651589
parent 0 a03f92240627
equal deleted inserted replaced
42:0ff24a8f6ca2 51:98307c651589
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <memspy/engine/memspyenginehelperserver.h>
       
    19 
       
    20 // Driver includes
       
    21 #include <memspy/driver/memspydriverclient.h>
       
    22 #include <memspy/driver/memspydriverconstants.h>
       
    23 
       
    24 // User includes
       
    25 #include <memspy/engine/memspyengine.h>
       
    26 #include <memspy/engine/memspyengineoutputsink.h>
       
    27 #include <memspy/engine/memspyengineobjectthread.h>
       
    28 #include <memspy/engine/memspyengineobjectprocess.h>
       
    29 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    30 #include <memspy/engine/memspyenginehelperchunk.h>
       
    31 
       
    32 // Literal constants
       
    33 _LIT( KMemSpyEngineServListOutputComma, ", " );
       
    34 
       
    35 
       
    36 
       
    37 CMemSpyEngineHelperServer::CMemSpyEngineHelperServer( CMemSpyEngine& aEngine )
       
    38 :   iEngine( aEngine )
       
    39     {
       
    40     }
       
    41 
       
    42     
       
    43 CMemSpyEngineHelperServer::~CMemSpyEngineHelperServer()
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 void CMemSpyEngineHelperServer::ConstructL()
       
    49     {
       
    50     }
       
    51 
       
    52 
       
    53 CMemSpyEngineHelperServer* CMemSpyEngineHelperServer::NewL( CMemSpyEngine& aEngine )
       
    54     {
       
    55     CMemSpyEngineHelperServer* self = new(ELeave) CMemSpyEngineHelperServer( aEngine );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 EXPORT_C void CMemSpyEngineHelperServer::GetServerSessionsL( TAny* aServerHandle, RArray<TMemSpyDriverServerSessionInfo>& aSessions )
       
    64     {
       
    65 	const TInt KMaxCount = 256;
       
    66 	TAny* handles[KMaxCount];
       
    67 	TInt c = KMaxCount;
       
    68 
       
    69 	TInt r = iEngine.Driver().GetServerSessionHandles( aServerHandle, handles, c );
       
    70 	if  ( r == KErrNone )
       
    71     	{
       
    72         if  ( c > 0 )
       
    73             {
       
    74         	if (c > KMaxCount)
       
    75         		{
       
    76         		c = KMaxCount;
       
    77         		}
       
    78 
       
    79         	TMemSpyDriverServerSessionInfo info;
       
    80         	for (TInt i=0; i<c; i++)
       
    81         		{
       
    82         		r = iEngine.Driver().GetServerSessionInfo( handles[i], info );
       
    83         		if (r == KErrNone)
       
    84         			{
       
    85         			aSessions.AppendL( info );
       
    86         			}
       
    87         		}
       
    88             }
       
    89         }
       
    90     }
       
    91 
       
    92 
       
    93 EXPORT_C void CMemSpyEngineHelperServer::GetServerSessionsL( const TMemSpyDriverHandleInfoGeneric& aServerDetails, RArray<TMemSpyDriverServerSessionInfo>& aSessions )
       
    94     {
       
    95     GetServerSessionsL( aServerDetails.iHandle, aSessions );
       
    96     }
       
    97 
       
    98 
       
    99 EXPORT_C void CMemSpyEngineHelperServer::GetServerListL( RArray<TMemSpyDriverHandleInfoGeneric>& aServers )
       
   100     {
       
   101 	const TInt KMaxCount = 256;
       
   102 	TAny* handles[KMaxCount];
       
   103 	TInt c = KMaxCount;
       
   104 
       
   105 	TInt r = iEngine.Driver().GetContainerHandles( EMemSpyDriverContainerTypeServer, handles, c );
       
   106 	if  ( r == KErrNone )
       
   107     	{
       
   108         if  ( c > 0 )
       
   109             {
       
   110         	if (c > KMaxCount)
       
   111         		{
       
   112         		c = KMaxCount;
       
   113         		}
       
   114 
       
   115         	TMemSpyDriverHandleInfoGeneric info;
       
   116         	for (TInt i=0; i<c; i++)
       
   117         		{
       
   118         		r = iEngine.Driver().GetGenericHandleInfo( KMemSpyDriverEnumerateContainerHandles, EMemSpyDriverContainerTypeServer, handles[i], info );
       
   119         		if (r == KErrNone)
       
   120         			{
       
   121         			aServers.AppendL( info );
       
   122         			}
       
   123         		}
       
   124             }
       
   125         }
       
   126     }
       
   127 
       
   128 
       
   129 EXPORT_C CMemSpyEngineServerList* CMemSpyEngineHelperServer::ServerListL()
       
   130     {
       
   131     CMemSpyEngineServerList* list = CMemSpyEngineServerList::NewLC();
       
   132     //
       
   133     RArray<TMemSpyDriverHandleInfoGeneric> servers;
       
   134     CleanupClosePushL( servers );
       
   135     //
       
   136     GetServerListL( servers );
       
   137     //
       
   138     const TInt count = servers.Count();
       
   139     for( TInt i=0; i<count; i++ )
       
   140         {
       
   141         const TMemSpyDriverHandleInfoGeneric& details = servers[ i ];
       
   142         //
       
   143         CMemSpyEngineServerEntry* serverEntry = CMemSpyEngineServerEntry::NewLC( details );
       
   144         list->AddItemL( serverEntry );
       
   145         CleanupStack::Pop( serverEntry );
       
   146         }
       
   147     //
       
   148     CleanupStack::PopAndDestroy( &servers );
       
   149 
       
   150     // Sort the list by session count
       
   151     list->SortBySessionCountL();
       
   152 
       
   153     // Done
       
   154     CleanupStack::Pop( list );
       
   155     return list;
       
   156     }
       
   157 
       
   158 
       
   159 CMemSpyEngine& CMemSpyEngineHelperServer::Engine() const
       
   160     {
       
   161     return iEngine;
       
   162     }
       
   163 
       
   164 
       
   165 
       
   166 
       
   167 
       
   168 
       
   169 
       
   170 
       
   171 
       
   172 
       
   173 
       
   174 
       
   175 
       
   176 
       
   177 
       
   178 
       
   179 
       
   180 
       
   181 
       
   182 
       
   183 
       
   184 
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 
       
   190 
       
   191 
       
   192 
       
   193 
       
   194 
       
   195 
       
   196 
       
   197 
       
   198 CMemSpyEngineServerList::CMemSpyEngineServerList()
       
   199     {
       
   200     }
       
   201 
       
   202 
       
   203 EXPORT_C CMemSpyEngineServerList::~CMemSpyEngineServerList()
       
   204     {
       
   205     iItems.ResetAndDestroy();
       
   206     iItems.Close();
       
   207     }
       
   208 
       
   209 
       
   210 void CMemSpyEngineServerList::ConstructL()
       
   211     {
       
   212     }
       
   213 
       
   214 
       
   215 CMemSpyEngineServerList* CMemSpyEngineServerList::NewLC()
       
   216     {
       
   217     CMemSpyEngineServerList* self = new(ELeave) CMemSpyEngineServerList();
       
   218     CleanupStack::PushL( self );
       
   219     self->ConstructL();
       
   220     return self;
       
   221     }
       
   222 
       
   223 
       
   224 EXPORT_C TInt CMemSpyEngineServerList::Count() const
       
   225     {
       
   226     return iItems.Count();
       
   227     }
       
   228 
       
   229 
       
   230 EXPORT_C const CMemSpyEngineServerEntry& CMemSpyEngineServerList::At( TInt aIndex ) const
       
   231     {
       
   232     return *iItems[ aIndex ];
       
   233     }
       
   234 
       
   235 
       
   236 EXPORT_C void CMemSpyEngineServerList::SortByNameL()
       
   237     {
       
   238     TLinearOrder< CMemSpyEngineServerEntry > comparer( CompareByName );
       
   239     iItems.Sort( comparer );
       
   240     }
       
   241 
       
   242 
       
   243 EXPORT_C void CMemSpyEngineServerList::SortBySessionCountL()
       
   244     {
       
   245     TLinearOrder< CMemSpyEngineServerEntry > comparer( CompareBySessionCount );
       
   246     iItems.Sort( comparer );
       
   247     }
       
   248 
       
   249 
       
   250 EXPORT_C TInt CMemSpyEngineServerList::ItemIndex( const CMemSpyEngineServerEntry& aEntry ) const
       
   251     {
       
   252     TInt ret = KErrNotFound;
       
   253     //
       
   254     const TInt count = Count();
       
   255     for( TInt i=0; i<count; i++ )
       
   256         {
       
   257         const CMemSpyEngineServerEntry* item = iItems[ i ];
       
   258         //
       
   259         if  ( item == &aEntry )
       
   260             {
       
   261             ret = i;
       
   262             break;
       
   263             }
       
   264         }
       
   265     //
       
   266     return ret;
       
   267     }
       
   268 
       
   269 
       
   270 EXPORT_C void CMemSpyEngineServerList::OutputDataColumnsL( CMemSpyEngine& aEngine, TBool aClientThreadColumns )
       
   271     {
       
   272     HBufC* columns = HBufC::NewLC( 1024 );
       
   273     TPtr pColumns( columns->Des() );
       
   274     //
       
   275     _LIT(KCol1, "Thread/Process Id");
       
   276     pColumns.Append( KCol1 );
       
   277     pColumns.Append( KMemSpyEngineServListOutputComma );
       
   278     //
       
   279     _LIT(KCol2, "Name");
       
   280     pColumns.Append( KCol2 );
       
   281     pColumns.Append( KMemSpyEngineServListOutputComma );
       
   282     //
       
   283     _LIT(KCol3, "Connected Session Count");
       
   284     pColumns.Append( KCol3 );
       
   285     //
       
   286     if  ( aClientThreadColumns )
       
   287         {
       
   288         _LIT(KCol4, "Connected Client");
       
   289         pColumns.Append( KMemSpyEngineServListOutputComma );
       
   290         pColumns.Append( KCol4 );
       
   291         }
       
   292     //
       
   293     aEngine.Sink().OutputLineL( pColumns );
       
   294     CleanupStack::PopAndDestroy( columns );
       
   295     }
       
   296 
       
   297 
       
   298 void CMemSpyEngineServerList::AddItemL( CMemSpyEngineServerEntry* aItem )
       
   299     {
       
   300     iItems.AppendL( aItem );
       
   301     }
       
   302 
       
   303 
       
   304 EXPORT_C TInt CMemSpyEngineServerList::MdcaCount() const
       
   305     {
       
   306     return Count();
       
   307     }
       
   308 
       
   309 
       
   310 EXPORT_C TPtrC CMemSpyEngineServerList::MdcaPoint( TInt aIndex ) const
       
   311     {
       
   312     const CMemSpyEngineServerEntry& item = At( aIndex );
       
   313     return TPtrC( item.Caption() );
       
   314     }
       
   315 
       
   316 
       
   317 TInt CMemSpyEngineServerList::CompareByName( const CMemSpyEngineServerEntry& aLeft, const CMemSpyEngineServerEntry& aRight )
       
   318     {
       
   319     const TInt ret = aLeft.Name().CompareF( aRight.Name() );
       
   320     return ret;
       
   321     }
       
   322 
       
   323 
       
   324 TInt CMemSpyEngineServerList::CompareBySessionCount( const CMemSpyEngineServerEntry& aLeft, const CMemSpyEngineServerEntry& aRight )
       
   325     {
       
   326     TInt ret = -1;
       
   327     //
       
   328     if  ( aLeft.SessionCount() < aRight.SessionCount() )
       
   329         {
       
   330         ret = 1;
       
   331         }
       
   332     else if ( aLeft.SessionCount() == aRight.SessionCount() )
       
   333         {
       
   334         ret = 0;
       
   335         }
       
   336     //
       
   337     return ret;
       
   338     }
       
   339 
       
   340 
       
   341 
       
   342 
       
   343 
       
   344 
       
   345 
       
   346 
       
   347 
       
   348 
       
   349 
       
   350 
       
   351 
       
   352 
       
   353 
       
   354 
       
   355 
       
   356 
       
   357 
       
   358 CMemSpyEngineServerEntry::CMemSpyEngineServerEntry()
       
   359     {
       
   360     }
       
   361 
       
   362 
       
   363 EXPORT_C CMemSpyEngineServerEntry::~CMemSpyEngineServerEntry()
       
   364     {
       
   365     delete iCaption;
       
   366     delete iName;
       
   367     }
       
   368 
       
   369 
       
   370 void CMemSpyEngineServerEntry::ConstructL( const TMemSpyDriverHandleInfoGeneric& aInfo )
       
   371     {
       
   372     iName = HBufC::NewL( aInfo.iName.Length() );
       
   373     iName->Des().Copy( aInfo.iName );
       
   374     iSessionCount = aInfo.iCount;
       
   375     iId = aInfo.iId;
       
   376     iHandle = aInfo.iHandle;
       
   377 
       
   378     // Make caption
       
   379     _LIT(KServerListFormat, "\t%S\t\t%d session");
       
   380     TBuf<KMaxFullName + 128> item;
       
   381     //
       
   382     item.Format( KServerListFormat, iName, iSessionCount );
       
   383     //
       
   384     if  ( iSessionCount != 1 )
       
   385         {
       
   386         // Add missing 's' 
       
   387         item.Append( TChar('s') );
       
   388         }
       
   389     //
       
   390     iCaption = item.AllocL();
       
   391     }
       
   392 
       
   393 
       
   394 CMemSpyEngineServerEntry* CMemSpyEngineServerEntry::NewLC( const TMemSpyDriverHandleInfoGeneric& aInfo )
       
   395     {
       
   396     CMemSpyEngineServerEntry* self = new(ELeave) CMemSpyEngineServerEntry();
       
   397     CleanupStack::PushL( self );
       
   398     self->ConstructL( aInfo );
       
   399     return self;
       
   400     }
       
   401 
       
   402 
       
   403 EXPORT_C void CMemSpyEngineServerEntry::OutputDataL( CMemSpyEngineHelperServer& aHelper, TBool aClientThreadColumns ) const
       
   404     {
       
   405     _LIT(KMemSpyEngineServListOutputDecimal, "%d");
       
   406     _LIT(KMemSpyEngineServListOutputString, "%S");
       
   407     //
       
   408     HBufC* columns = HBufC::NewLC( 1024 );
       
   409     TPtr pColumns( columns->Des() );
       
   410     //
       
   411     pColumns.AppendFormat( KMemSpyEngineServListOutputDecimal, Id() );
       
   412     pColumns.Append( KMemSpyEngineServListOutputComma );
       
   413     //
       
   414     pColumns.AppendFormat( KMemSpyEngineServListOutputString, &Name() );
       
   415     pColumns.Append( KMemSpyEngineServListOutputComma );
       
   416     //
       
   417     pColumns.AppendFormat( KMemSpyEngineServListOutputDecimal, SessionCount() );
       
   418     //
       
   419     aHelper.Engine().Sink().OutputLineL( pColumns );
       
   420 
       
   421     if  ( aClientThreadColumns )
       
   422         {
       
   423         RArray<TMemSpyDriverServerSessionInfo> sessions;
       
   424         CleanupClosePushL( sessions );
       
   425 
       
   426         // Get the sessions
       
   427         GetSessionsL( aHelper, sessions );
       
   428 
       
   429         // Output an additional line per entry
       
   430         const TInt count = sessions.Count();
       
   431         for( TInt i=0; i<count; i++ )
       
   432             {
       
   433             const TMemSpyDriverServerSessionInfo& session = sessions[ i ];
       
   434             //
       
   435             pColumns.Copy( session.iName );
       
   436             pColumns.Insert( 0, KMemSpyEngineServListOutputComma );
       
   437             pColumns.Insert( 0, KMemSpyEngineServListOutputComma );
       
   438             pColumns.Insert( 0, KMemSpyEngineServListOutputComma );
       
   439             //
       
   440             aHelper.Engine().Sink().OutputLineL( pColumns );
       
   441             }
       
   442         //
       
   443         CleanupStack::PopAndDestroy( &sessions );
       
   444         }
       
   445 
       
   446     CleanupStack::PopAndDestroy( columns );
       
   447     }
       
   448 
       
   449 
       
   450 EXPORT_C void CMemSpyEngineServerEntry::GetSessionsL( CMemSpyEngineHelperServer& aHelper, RArray<TMemSpyDriverServerSessionInfo>& aSessions ) const
       
   451     {
       
   452     aHelper.GetServerSessionsL( Handle(), aSessions );
       
   453     }
       
   454 
       
   455