perfsrv/piprofiler/plugins/GeneralsPlugin/src/MemoryEventHandler.cpp
author hgs
Tue, 26 Oct 2010 16:20:32 +0300
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
permissions -rw-r--r--
201043
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <e32def.h>
hgs
parents:
diff changeset
    19
#include <e32cmn.h>
hgs
parents:
diff changeset
    20
#include <arm.h>
hgs
parents:
diff changeset
    21
#include <kernel.h>
hgs
parents:
diff changeset
    22
#include <kern_priv.h>
hgs
parents:
diff changeset
    23
#include <nk_trace.h>
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
#include "MemoryEventHandler.h"
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
62
hgs
parents: 51
diff changeset
    28
DMemoryEventHandler::DMemoryEventHandler(DProfilerSampleBuffer* aSampleBuffer, TProfilerGppSamplerData* aGppSamplerDataIn)
20
hgs
parents:
diff changeset
    29
    :   DKernelEventHandler(EventHandler, this), 
hgs
parents:
diff changeset
    30
        iSampleBuffer(aSampleBuffer), 
62
hgs
parents: 51
diff changeset
    31
        iSampleDescriptor(&(this->iSample[1]),0,256),
hgs
parents: 51
diff changeset
    32
        gppSamplerData(aGppSamplerDataIn)
20
hgs
parents:
diff changeset
    33
    {
hgs
parents:
diff changeset
    34
    iPreviousCount = 0;
62
hgs
parents: 51
diff changeset
    35
    iSampleAvailable = false;
20
hgs
parents:
diff changeset
    36
    }
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
TInt DMemoryEventHandler::Create()
hgs
parents:
diff changeset
    40
    {
62
hgs
parents: 51
diff changeset
    41
    TInt err(Kern::MutexCreate(iLock, _L("MemoryEventHandlerLock"), KMutexOrdResourceManager));
20
hgs
parents:
diff changeset
    42
    if (err != KErrNone)
hgs
parents:
diff changeset
    43
        return err;
hgs
parents:
diff changeset
    44
    
hgs
parents:
diff changeset
    45
    return Add();
hgs
parents:
diff changeset
    46
    }
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
hgs
parents:
diff changeset
    49
DMemoryEventHandler::~DMemoryEventHandler()
hgs
parents:
diff changeset
    50
    {
hgs
parents:
diff changeset
    51
    if (iLock)
hgs
parents:
diff changeset
    52
        iLock->Close(NULL);
hgs
parents:
diff changeset
    53
       
hgs
parents:
diff changeset
    54
    }
hgs
parents:
diff changeset
    55
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
TInt DMemoryEventHandler::Start()
hgs
parents:
diff changeset
    58
    {
hgs
parents:
diff changeset
    59
    iTracking = ETrue;
hgs
parents:
diff changeset
    60
    return KErrNone;
hgs
parents:
diff changeset
    61
    }
hgs
parents:
diff changeset
    62
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
TInt DMemoryEventHandler::Stop()
hgs
parents:
diff changeset
    65
    {
hgs
parents:
diff changeset
    66
    iTracking = EFalse;
hgs
parents:
diff changeset
    67
    return KErrNone;
hgs
parents:
diff changeset
    68
    }
hgs
parents:
diff changeset
    69
hgs
parents:
diff changeset
    70
TBool DMemoryEventHandler::SampleNeeded()
hgs
parents:
diff changeset
    71
    {
hgs
parents:
diff changeset
    72
    LOGTEXT("DMemoryEventHandler::SampleNeeded()");
hgs
parents:
diff changeset
    73
    
hgs
parents:
diff changeset
    74
    // check if event handler was not running
62
hgs
parents: 51
diff changeset
    75
    if(!iTracking)
hgs
parents: 51
diff changeset
    76
        return false; // return false
hgs
parents: 51
diff changeset
    77
    // check if a new sample is available
hgs
parents: 51
diff changeset
    78
    if(iSampleAvailable)
hgs
parents: 51
diff changeset
    79
        {
hgs
parents: 51
diff changeset
    80
        return true;
hgs
parents: 51
diff changeset
    81
        }
hgs
parents: 51
diff changeset
    82
    else
hgs
parents: 51
diff changeset
    83
        {
hgs
parents: 51
diff changeset
    84
        return false;
hgs
parents: 51
diff changeset
    85
        }
hgs
parents: 51
diff changeset
    86
    }
hgs
parents: 51
diff changeset
    87
void DMemoryEventHandler::SampleHandled()
hgs
parents: 51
diff changeset
    88
    {
hgs
parents: 51
diff changeset
    89
    iSampleAvailable = false;
20
hgs
parents:
diff changeset
    90
    }
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
hgs
parents:
diff changeset
    93
TUint DMemoryEventHandler::EventHandler(TKernelEvent aType, TAny* a1, TAny* a2, TAny* aThis)
hgs
parents:
diff changeset
    94
    {
hgs
parents:
diff changeset
    95
    return ((DMemoryEventHandler*)aThis)->HandleEvent(aType, a1, a2);
hgs
parents:
diff changeset
    96
    }
hgs
parents:
diff changeset
    97
hgs
parents:
diff changeset
    98
hgs
parents:
diff changeset
    99
hgs
parents:
diff changeset
   100
TUint DMemoryEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2)
hgs
parents:
diff changeset
   101
    {
hgs
parents:
diff changeset
   102
    // debug
62
hgs
parents: 51
diff changeset
   103
    // Kern::Printf("New kernel event received, %d", aType);
20
hgs
parents:
diff changeset
   104
    
62
hgs
parents: 51
diff changeset
   105
    if (iTracking)
20
hgs
parents:
diff changeset
   106
        {
hgs
parents:
diff changeset
   107
        iCounters[aType]++;
hgs
parents:
diff changeset
   108
        switch (aType)
hgs
parents:
diff changeset
   109
            {
hgs
parents:
diff changeset
   110
            // capture only chunk creation, updates and destroyal
hgs
parents:
diff changeset
   111
            case EEventNewChunk:
hgs
parents:
diff changeset
   112
                {
hgs
parents:
diff changeset
   113
                DChunk* chunk = (DChunk*)a1;
hgs
parents:
diff changeset
   114
                HandleAddChunk(chunk);
hgs
parents:
diff changeset
   115
                break;
hgs
parents:
diff changeset
   116
                }
hgs
parents:
diff changeset
   117
            case EEventUpdateChunk:   
hgs
parents:
diff changeset
   118
                HandleUpdateChunk((DChunk*)a1);
hgs
parents:
diff changeset
   119
                break;
hgs
parents:
diff changeset
   120
            case EEventDeleteChunk:      
hgs
parents:
diff changeset
   121
                HandleDeleteChunk((DChunk*)a1);
hgs
parents:
diff changeset
   122
                break;
hgs
parents:
diff changeset
   123
//            case EEventAddProcess:
hgs
parents:
diff changeset
   124
//                Kern::Printf("Process added: 0x%08x", (DProcess*)a1);
hgs
parents:
diff changeset
   125
//                break;
hgs
parents:
diff changeset
   126
//            case EEventUpdateProcess:
hgs
parents:
diff changeset
   127
//                Kern::Printf("DProcess updated: 0x%08x", (DProcess*)a1);
hgs
parents:
diff changeset
   128
//                break;
hgs
parents:
diff changeset
   129
//            case EEventRemoveProcess:
hgs
parents:
diff changeset
   130
//                Kern::Printf("DProcess removed: 0x%08x", (DProcess*)a1);
hgs
parents:
diff changeset
   131
//                break;
hgs
parents:
diff changeset
   132
//            case EEventAddCodeSeg:
hgs
parents:
diff changeset
   133
//                Kern::Printf("DCodeSeg added: 0x%08x", (DCodeSeg*)a1);
hgs
parents:
diff changeset
   134
//                break;
hgs
parents:
diff changeset
   135
//            case EEventRemoveCodeSeg:
hgs
parents:
diff changeset
   136
//                Kern::Printf("DCodeSeg deleted: 0x%08x", (DCodeSeg*)a1);
hgs
parents:
diff changeset
   137
//                break;
hgs
parents:
diff changeset
   138
            case EEventAddThread:
hgs
parents:
diff changeset
   139
                HandleAddThread((DThread*)a1);
hgs
parents:
diff changeset
   140
                break;
hgs
parents:
diff changeset
   141
            case EEventUpdateThread:    // thread renaming
hgs
parents:
diff changeset
   142
                HandleUpdateThread((DThread*)a1);
hgs
parents:
diff changeset
   143
                break;
hgs
parents:
diff changeset
   144
//            case EEventKillThread:
hgs
parents:
diff changeset
   145
            case EEventRemoveThread:
hgs
parents:
diff changeset
   146
                HandleDeleteThread((DThread*)a1);
hgs
parents:
diff changeset
   147
                break;
hgs
parents:
diff changeset
   148
#ifdef MEM_EVENT_HANDLER_LIBRARY_EVENTS
hgs
parents:
diff changeset
   149
            case EEventAddLibrary:
hgs
parents:
diff changeset
   150
                HandleAddLibrary((DLibrary*)a1, (DThread*)a2);
hgs
parents:
diff changeset
   151
                break;
hgs
parents:
diff changeset
   152
            case EEventRemoveLibrary:
hgs
parents:
diff changeset
   153
                HandleDeleteLibrary((DLibrary*)a1);
hgs
parents:
diff changeset
   154
                break;
hgs
parents:
diff changeset
   155
#endif
hgs
parents:
diff changeset
   156
            
hgs
parents:
diff changeset
   157
            // ignore exception events
hgs
parents:
diff changeset
   158
            case EEventSwExc:
hgs
parents:
diff changeset
   159
            case EEventHwExc:
hgs
parents:
diff changeset
   160
         
hgs
parents:
diff changeset
   161
            default:
hgs
parents:
diff changeset
   162
                break;
hgs
parents:
diff changeset
   163
            }
hgs
parents:
diff changeset
   164
        }
hgs
parents:
diff changeset
   165
    return DKernelEventHandler::ERunNext;
hgs
parents:
diff changeset
   166
    }
hgs
parents:
diff changeset
   167
hgs
parents:
diff changeset
   168
TInt DMemoryEventHandler::EncodeNameCode()
hgs
parents:
diff changeset
   169
    {
hgs
parents:
diff changeset
   170
    iSample[0] = 1;
hgs
parents:
diff changeset
   171
    iSample[1] = 0xaa;
hgs
parents:
diff changeset
   172
    return 2;
hgs
parents:
diff changeset
   173
    }
hgs
parents:
diff changeset
   174
hgs
parents:
diff changeset
   175
// encode mark for new chunk or thread
hgs
parents:
diff changeset
   176
TInt DMemoryEventHandler::EncodeNewCode()
hgs
parents:
diff changeset
   177
    {
hgs
parents:
diff changeset
   178
    iSample[0] = 1;
hgs
parents:
diff changeset
   179
    iSample[1] = 0xda;
hgs
parents:
diff changeset
   180
    return 2;
hgs
parents:
diff changeset
   181
    }
hgs
parents:
diff changeset
   182
hgs
parents:
diff changeset
   183
// encode mark for update of chunk or thread
hgs
parents:
diff changeset
   184
TInt DMemoryEventHandler::EncodeUpdateCode()
hgs
parents:
diff changeset
   185
    {
hgs
parents:
diff changeset
   186
    iSample[0] = 1;
hgs
parents:
diff changeset
   187
    iSample[1] = 0xdb;
hgs
parents:
diff changeset
   188
    return 2;
hgs
parents:
diff changeset
   189
    }
hgs
parents:
diff changeset
   190
hgs
parents:
diff changeset
   191
// encode mark for removal of chunk or thread
hgs
parents:
diff changeset
   192
TInt DMemoryEventHandler::EncodeRemoveCode()
hgs
parents:
diff changeset
   193
    {
hgs
parents:
diff changeset
   194
    iSample[0] = 1;
hgs
parents:
diff changeset
   195
    iSample[1] = 0xdc;
hgs
parents:
diff changeset
   196
    return 2;
hgs
parents:
diff changeset
   197
    }
hgs
parents:
diff changeset
   198
hgs
parents:
diff changeset
   199
// encode the memory sample header in all memory changes
hgs
parents:
diff changeset
   200
TInt DMemoryEventHandler::AddHeader()
hgs
parents:
diff changeset
   201
    {
hgs
parents:
diff changeset
   202
    TInt err(KErrNone);
hgs
parents:
diff changeset
   203
    
hgs
parents:
diff changeset
   204
    TUint8 number(4);    // mem sampler id
62
hgs
parents: 51
diff changeset
   205
    TUint32 sampleNum= this->gppSamplerData->sampleNumber;
20
hgs
parents:
diff changeset
   206
    // check if iCount bigger than previous, i.e. at least 1 ms has passed from the previous sample
62
hgs
parents: 51
diff changeset
   207
    if(sampleNum > iPreviousCount)
20
hgs
parents:
diff changeset
   208
        {
hgs
parents:
diff changeset
   209
        err = this->iSampleBuffer->AddSample(&number,1);
62
hgs
parents: 51
diff changeset
   210
        err = this->iSampleBuffer->AddSample((TUint8*)&(sampleNum),4);
20
hgs
parents:
diff changeset
   211
    
hgs
parents:
diff changeset
   212
        // add data chunk header
hgs
parents:
diff changeset
   213
        TInt length(EncodeUpdateCode());
hgs
parents:
diff changeset
   214
        err = iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   215
        
hgs
parents:
diff changeset
   216
        // add total memory sample in the beginning of each sample
hgs
parents:
diff changeset
   217
        length = EncodeTotalMemory();
hgs
parents:
diff changeset
   218
        err = iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   219
        AddFooter();    // end mark for total memory sample
hgs
parents:
diff changeset
   220
        }
62
hgs
parents: 51
diff changeset
   221
    iPreviousCount = sampleNum;
20
hgs
parents:
diff changeset
   222
    
hgs
parents:
diff changeset
   223
    // add actual sample
hgs
parents:
diff changeset
   224
    err = this->iSampleBuffer->AddSample(&number,1);
62
hgs
parents: 51
diff changeset
   225
    err = this->iSampleBuffer->AddSample((TUint8*)&(sampleNum),4);
hgs
parents: 51
diff changeset
   226
    LOGSTRING2("handler timestamp : 0x%04x", sampleNum);
20
hgs
parents:
diff changeset
   227
hgs
parents:
diff changeset
   228
    return err;
hgs
parents:
diff changeset
   229
    }
hgs
parents:
diff changeset
   230
hgs
parents:
diff changeset
   231
// encode the memory sample header in all memory changes
hgs
parents:
diff changeset
   232
TInt DMemoryEventHandler::AddFooter()
hgs
parents:
diff changeset
   233
    {
hgs
parents:
diff changeset
   234
    TInt err(KErrNone);
hgs
parents:
diff changeset
   235
    
hgs
parents:
diff changeset
   236
    TUint8 number(0);    // end mark
hgs
parents:
diff changeset
   237
    err = this->iSampleBuffer->AddSample(&number,1);
hgs
parents:
diff changeset
   238
    
hgs
parents:
diff changeset
   239
    return err;
hgs
parents:
diff changeset
   240
    }
hgs
parents:
diff changeset
   241
hgs
parents:
diff changeset
   242
TInt DMemoryEventHandler::EncodeTotalMemory()
hgs
parents:
diff changeset
   243
    {   
hgs
parents:
diff changeset
   244
    
hgs
parents:
diff changeset
   245
    TUint8* size(&iSample[0]);
hgs
parents:
diff changeset
   246
    *size = 0;
hgs
parents:
diff changeset
   247
hgs
parents:
diff changeset
   248
    NKern::LockSystem();
hgs
parents:
diff changeset
   249
    TInt freeRam(Kern::FreeRamInBytes());
hgs
parents:
diff changeset
   250
    TInt totalRam(Kern::SuperPage().iTotalRamSize);
hgs
parents:
diff changeset
   251
    NKern::UnlockSystem();
hgs
parents:
diff changeset
   252
hgs
parents:
diff changeset
   253
    iSampleDescriptor.Zero();
hgs
parents:
diff changeset
   254
    
hgs
parents:
diff changeset
   255
    TUint32 id(0xbabbeaaa);
hgs
parents:
diff changeset
   256
    TInt zero(0);
hgs
parents:
diff changeset
   257
        
hgs
parents:
diff changeset
   258
    iSampleDescriptor.Append((TUint8*)&(id),sizeof(TUint32));
hgs
parents:
diff changeset
   259
    *size += sizeof(TUint);
hgs
parents:
diff changeset
   260
    
hgs
parents:
diff changeset
   261
    iSampleDescriptor.Append((TUint8*)&(totalRam),sizeof(TInt));
hgs
parents:
diff changeset
   262
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   263
        
hgs
parents:
diff changeset
   264
    // append the cell amount allocated
hgs
parents:
diff changeset
   265
    iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
hgs
parents:
diff changeset
   266
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   267
    
hgs
parents:
diff changeset
   268
    // append the chunk size
hgs
parents:
diff changeset
   269
    iSampleDescriptor.Append((TUint8*)&(freeRam),sizeof(TInt));
hgs
parents:
diff changeset
   270
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   271
        
hgs
parents:
diff changeset
   272
    // append the thread user stack size
hgs
parents:
diff changeset
   273
    iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
hgs
parents:
diff changeset
   274
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   275
hgs
parents:
diff changeset
   276
    return ((TInt)(*size))+1;
hgs
parents:
diff changeset
   277
    }
hgs
parents:
diff changeset
   278
hgs
parents:
diff changeset
   279
// handle chunk activity
hgs
parents:
diff changeset
   280
TBool DMemoryEventHandler::HandleAddChunk(DChunk* aChunk)
hgs
parents:
diff changeset
   281
    {    
hgs
parents:
diff changeset
   282
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   283
    Kern::MutexWait(*iLock);
hgs
parents:
diff changeset
   284
    // add header first
hgs
parents:
diff changeset
   285
    TInt err(AddHeader());
hgs
parents:
diff changeset
   286
    
hgs
parents:
diff changeset
   287
    if(err != KErrNone)
hgs
parents:
diff changeset
   288
        {
62
hgs
parents: 51
diff changeset
   289
        Kern::MutexSignal(*iLock);
hgs
parents: 51
diff changeset
   290
        NKern::ThreadLeaveCS();
20
hgs
parents:
diff changeset
   291
        return EFalse;
hgs
parents:
diff changeset
   292
        }
hgs
parents:
diff changeset
   293
    
hgs
parents:
diff changeset
   294
    // new chunk, add name of it
hgs
parents:
diff changeset
   295
    TInt length(EncodeNameCode());
hgs
parents:
diff changeset
   296
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   297
hgs
parents:
diff changeset
   298
    // new chunk, add name of it
hgs
parents:
diff changeset
   299
    length = EncodeChunkName(*aChunk);
hgs
parents:
diff changeset
   300
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   301
    
hgs
parents:
diff changeset
   302
    // add new chunk tag
hgs
parents:
diff changeset
   303
    length = EncodeNewCode();
hgs
parents:
diff changeset
   304
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   305
hgs
parents:
diff changeset
   306
    length = EncodeChunkData(*aChunk);
hgs
parents:
diff changeset
   307
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   308
    
hgs
parents:
diff changeset
   309
    // add end mark
hgs
parents:
diff changeset
   310
    AddFooter();
hgs
parents:
diff changeset
   311
    Kern::MutexSignal(*iLock);
hgs
parents:
diff changeset
   312
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   313
    return ETrue;
hgs
parents:
diff changeset
   314
    }
hgs
parents:
diff changeset
   315
hgs
parents:
diff changeset
   316
TBool DMemoryEventHandler::HandleUpdateChunk(DChunk* aChunk)
hgs
parents:
diff changeset
   317
    {
hgs
parents:
diff changeset
   318
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   319
    Kern::MutexWait(*iLock);
hgs
parents:
diff changeset
   320
    // add header first
hgs
parents:
diff changeset
   321
    TInt err(AddHeader());
hgs
parents:
diff changeset
   322
    
hgs
parents:
diff changeset
   323
    if(err != KErrNone)
hgs
parents:
diff changeset
   324
        {
62
hgs
parents: 51
diff changeset
   325
        Kern::Printf("DChunk update error: %d", err);
hgs
parents: 51
diff changeset
   326
        Kern::MutexSignal(*iLock);
hgs
parents: 51
diff changeset
   327
        NKern::ThreadLeaveCS();
20
hgs
parents:
diff changeset
   328
        return EFalse;
hgs
parents:
diff changeset
   329
        }
hgs
parents:
diff changeset
   330
    
hgs
parents:
diff changeset
   331
    // add new chunk tag
hgs
parents:
diff changeset
   332
    TInt length(EncodeUpdateCode());
hgs
parents:
diff changeset
   333
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   334
hgs
parents:
diff changeset
   335
    length = EncodeChunkData(*aChunk);
hgs
parents:
diff changeset
   336
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   337
hgs
parents:
diff changeset
   338
    // add end mark
hgs
parents:
diff changeset
   339
    AddFooter();
hgs
parents:
diff changeset
   340
    Kern::MutexSignal(*iLock);
hgs
parents:
diff changeset
   341
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   342
    return ETrue;
hgs
parents:
diff changeset
   343
    }
hgs
parents:
diff changeset
   344
hgs
parents:
diff changeset
   345
TBool DMemoryEventHandler::HandleDeleteChunk(DChunk* aChunk)
hgs
parents:
diff changeset
   346
    {
hgs
parents:
diff changeset
   347
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   348
    Kern::MutexWait(*iLock);
hgs
parents:
diff changeset
   349
    // add header first
hgs
parents:
diff changeset
   350
    TInt err(AddHeader());
hgs
parents:
diff changeset
   351
    
hgs
parents:
diff changeset
   352
    if(err != KErrNone)
hgs
parents:
diff changeset
   353
        {
62
hgs
parents: 51
diff changeset
   354
        Kern::MutexSignal(*iLock);
hgs
parents: 51
diff changeset
   355
        NKern::ThreadLeaveCS();
20
hgs
parents:
diff changeset
   356
        return EFalse;
hgs
parents:
diff changeset
   357
        }
hgs
parents:
diff changeset
   358
    
hgs
parents:
diff changeset
   359
    // add new chunk tag
hgs
parents:
diff changeset
   360
    TInt length(EncodeRemoveCode());
hgs
parents:
diff changeset
   361
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   362
hgs
parents:
diff changeset
   363
    length = EncodeChunkData(*aChunk);
hgs
parents:
diff changeset
   364
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   365
hgs
parents:
diff changeset
   366
    // add end mark
hgs
parents:
diff changeset
   367
    AddFooter();
hgs
parents:
diff changeset
   368
    Kern::MutexSignal(*iLock);
hgs
parents:
diff changeset
   369
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   370
    return ETrue;
hgs
parents:
diff changeset
   371
    }
hgs
parents:
diff changeset
   372
hgs
parents:
diff changeset
   373
// handle process activity
hgs
parents:
diff changeset
   374
TBool DMemoryEventHandler::HandleAddProcess(DProcess *aProcess)
hgs
parents:
diff changeset
   375
    {
hgs
parents:
diff changeset
   376
    return ETrue;
hgs
parents:
diff changeset
   377
    }
hgs
parents:
diff changeset
   378
hgs
parents:
diff changeset
   379
TBool DMemoryEventHandler::HandleUpdateProcess(DProcess *aProcess)
hgs
parents:
diff changeset
   380
    {
hgs
parents:
diff changeset
   381
    return ETrue;
hgs
parents:
diff changeset
   382
    }
hgs
parents:
diff changeset
   383
hgs
parents:
diff changeset
   384
TBool DMemoryEventHandler::HandleDeleteProcess(DProcess *aProcess)
hgs
parents:
diff changeset
   385
    {
hgs
parents:
diff changeset
   386
    return ETrue;
hgs
parents:
diff changeset
   387
    }
hgs
parents:
diff changeset
   388
hgs
parents:
diff changeset
   389
// handle thread activity
hgs
parents:
diff changeset
   390
TBool DMemoryEventHandler::HandleAddThread(DThread* aThread)
hgs
parents:
diff changeset
   391
    {
hgs
parents:
diff changeset
   392
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   393
    Kern::MutexWait(*iLock);
hgs
parents:
diff changeset
   394
    // add header first
hgs
parents:
diff changeset
   395
    TInt err(AddHeader());
hgs
parents:
diff changeset
   396
    
hgs
parents:
diff changeset
   397
    if(err != KErrNone)
hgs
parents:
diff changeset
   398
        {
62
hgs
parents: 51
diff changeset
   399
        Kern::MutexSignal(*iLock);
hgs
parents: 51
diff changeset
   400
        NKern::ThreadLeaveCS();
20
hgs
parents:
diff changeset
   401
        return EFalse;
hgs
parents:
diff changeset
   402
        }
hgs
parents:
diff changeset
   403
    
hgs
parents:
diff changeset
   404
    // new thread, add name of it
hgs
parents:
diff changeset
   405
    TInt length(EncodeNameCode());
hgs
parents:
diff changeset
   406
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   407
    
hgs
parents:
diff changeset
   408
    // new chunk, add name of it
hgs
parents:
diff changeset
   409
    length = EncodeChunkName(*aThread);
hgs
parents:
diff changeset
   410
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   411
    
hgs
parents:
diff changeset
   412
    // add new chunk tag
hgs
parents:
diff changeset
   413
    length = EncodeNewCode();
hgs
parents:
diff changeset
   414
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   415
hgs
parents:
diff changeset
   416
    length = EncodeChunkData(*aThread);
hgs
parents:
diff changeset
   417
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   418
hgs
parents:
diff changeset
   419
    // add end mark
hgs
parents:
diff changeset
   420
    AddFooter();
hgs
parents:
diff changeset
   421
    Kern::MutexSignal(*iLock);
hgs
parents:
diff changeset
   422
    NKern::ThreadLeaveCS();
hgs
parents:
diff changeset
   423
    return ETrue;
hgs
parents:
diff changeset
   424
    }
hgs
parents:
diff changeset
   425
hgs
parents:
diff changeset
   426
TBool DMemoryEventHandler::HandleUpdateThread(DThread* aThread)
hgs
parents:
diff changeset
   427
    {
hgs
parents:
diff changeset
   428
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   429
    Kern::MutexWait(*iLock);
hgs
parents:
diff changeset
   430
    // add header first
hgs
parents:
diff changeset
   431
    TInt err(AddHeader());
hgs
parents:
diff changeset
   432
    
hgs
parents:
diff changeset
   433
    if(err != KErrNone)
hgs
parents:
diff changeset
   434
        {
62
hgs
parents: 51
diff changeset
   435
        Kern::MutexSignal(*iLock);
hgs
parents: 51
diff changeset
   436
        NKern::ThreadLeaveCS();
20
hgs
parents:
diff changeset
   437
        return EFalse;
hgs
parents:
diff changeset
   438
        }
hgs
parents:
diff changeset
   439
    
hgs
parents:
diff changeset
   440
    // add new chunk tag
hgs
parents:
diff changeset
   441
    TInt length(EncodeUpdateCode());
hgs
parents:
diff changeset
   442
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   443
hgs
parents:
diff changeset
   444
    length = EncodeChunkData(*aThread);
hgs
parents:
diff changeset
   445
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   446
hgs
parents:
diff changeset
   447
    // add end mark
hgs
parents:
diff changeset
   448
    AddFooter();
hgs
parents:
diff changeset
   449
    Kern::MutexSignal(*iLock);
hgs
parents:
diff changeset
   450
    NKern::ThreadLeaveCS();    
hgs
parents:
diff changeset
   451
    return ETrue;
hgs
parents:
diff changeset
   452
    }
hgs
parents:
diff changeset
   453
hgs
parents:
diff changeset
   454
TBool DMemoryEventHandler::HandleDeleteThread(DThread* aThread)
hgs
parents:
diff changeset
   455
    {
hgs
parents:
diff changeset
   456
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   457
    Kern::MutexWait(*iLock);
hgs
parents:
diff changeset
   458
    // add header first
hgs
parents:
diff changeset
   459
    TInt err(AddHeader());
hgs
parents:
diff changeset
   460
    
hgs
parents:
diff changeset
   461
    if(err != KErrNone)
hgs
parents:
diff changeset
   462
        {
62
hgs
parents: 51
diff changeset
   463
        Kern::MutexSignal(*iLock);
hgs
parents: 51
diff changeset
   464
        NKern::ThreadLeaveCS();
20
hgs
parents:
diff changeset
   465
        return EFalse;
hgs
parents:
diff changeset
   466
        }
hgs
parents:
diff changeset
   467
    
hgs
parents:
diff changeset
   468
    // add new chunk tag
hgs
parents:
diff changeset
   469
    TInt length(EncodeRemoveCode());
hgs
parents:
diff changeset
   470
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   471
hgs
parents:
diff changeset
   472
    length = EncodeChunkData(*aThread);
hgs
parents:
diff changeset
   473
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   474
hgs
parents:
diff changeset
   475
    // add end mark
hgs
parents:
diff changeset
   476
    AddFooter();
hgs
parents:
diff changeset
   477
    Kern::MutexSignal(*iLock);
hgs
parents:
diff changeset
   478
    NKern::ThreadLeaveCS();  
hgs
parents:
diff changeset
   479
    return ETrue;
hgs
parents:
diff changeset
   480
    }
hgs
parents:
diff changeset
   481
hgs
parents:
diff changeset
   482
TBool DMemoryEventHandler::HandleAddLibrary(DLibrary* aLibrary, DThread* aThread)
hgs
parents:
diff changeset
   483
    {
hgs
parents:
diff changeset
   484
    LOGTEXT("DMemoryEventHandler::HandleAddLibrary");
hgs
parents:
diff changeset
   485
    // add header first
hgs
parents:
diff changeset
   486
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   487
    Kern::MutexWait(*iLock);
hgs
parents:
diff changeset
   488
    TInt err(AddHeader());
hgs
parents:
diff changeset
   489
        
hgs
parents:
diff changeset
   490
    if(err != KErrNone)
hgs
parents:
diff changeset
   491
        {
62
hgs
parents: 51
diff changeset
   492
        Kern::MutexSignal(*iLock);
hgs
parents: 51
diff changeset
   493
        NKern::ThreadLeaveCS();
20
hgs
parents:
diff changeset
   494
        return EFalse;
hgs
parents:
diff changeset
   495
        }
hgs
parents:
diff changeset
   496
    
hgs
parents:
diff changeset
   497
    // new library, add name of it
hgs
parents:
diff changeset
   498
    TInt length(EncodeNameCode());
hgs
parents:
diff changeset
   499
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   500
        
hgs
parents:
diff changeset
   501
    // new chunk, add name of it
hgs
parents:
diff changeset
   502
    length = EncodeChunkName(*aLibrary);
hgs
parents:
diff changeset
   503
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   504
        
hgs
parents:
diff changeset
   505
    // add new chunk tag
hgs
parents:
diff changeset
   506
    length = EncodeNewCode();
hgs
parents:
diff changeset
   507
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   508
hgs
parents:
diff changeset
   509
    length = EncodeChunkData(*aLibrary, *aThread);
hgs
parents:
diff changeset
   510
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   511
hgs
parents:
diff changeset
   512
    // add end mark
hgs
parents:
diff changeset
   513
    AddFooter();
hgs
parents:
diff changeset
   514
    Kern::MutexSignal(*iLock);
hgs
parents:
diff changeset
   515
    NKern::ThreadLeaveCS();      
hgs
parents:
diff changeset
   516
    return ETrue;
hgs
parents:
diff changeset
   517
    }
hgs
parents:
diff changeset
   518
hgs
parents:
diff changeset
   519
TBool DMemoryEventHandler::HandleDeleteLibrary(DLibrary* aLibrary)
hgs
parents:
diff changeset
   520
    {
62
hgs
parents: 51
diff changeset
   521
    LOGTEXT("DMemoryEventHandler::HandleDeleteLibrary");
20
hgs
parents:
diff changeset
   522
    NKern::ThreadEnterCS();
hgs
parents:
diff changeset
   523
    Kern::MutexWait(*iLock);
hgs
parents:
diff changeset
   524
    // add header first
hgs
parents:
diff changeset
   525
    TInt err(AddHeader());
hgs
parents:
diff changeset
   526
        
hgs
parents:
diff changeset
   527
    if(err != KErrNone)
hgs
parents:
diff changeset
   528
        {
62
hgs
parents: 51
diff changeset
   529
        Kern::MutexSignal(*iLock);
hgs
parents: 51
diff changeset
   530
        NKern::ThreadLeaveCS();
20
hgs
parents:
diff changeset
   531
        return EFalse;
hgs
parents:
diff changeset
   532
        }
hgs
parents:
diff changeset
   533
        
hgs
parents:
diff changeset
   534
    // add new chunk tag
hgs
parents:
diff changeset
   535
    TInt length(EncodeRemoveCode());
hgs
parents:
diff changeset
   536
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   537
    
hgs
parents:
diff changeset
   538
    DThread* nullPointer = NULL;
hgs
parents:
diff changeset
   539
    length = EncodeChunkData(*aLibrary, *nullPointer);
hgs
parents:
diff changeset
   540
    iSampleBuffer->AddSample(iSample, length);
hgs
parents:
diff changeset
   541
hgs
parents:
diff changeset
   542
    // add end mark
hgs
parents:
diff changeset
   543
    AddFooter();
hgs
parents:
diff changeset
   544
    Kern::MutexSignal(*iLock);
hgs
parents:
diff changeset
   545
    NKern::ThreadLeaveCS();        
hgs
parents:
diff changeset
   546
    return ETrue;
hgs
parents:
diff changeset
   547
    }
hgs
parents:
diff changeset
   548
hgs
parents:
diff changeset
   549
// encode chunk name 
hgs
parents:
diff changeset
   550
TInt DMemoryEventHandler::EncodeChunkName(DChunk& c)
hgs
parents:
diff changeset
   551
    {   
hgs
parents:
diff changeset
   552
    // the size of the following name is in the first byte
hgs
parents:
diff changeset
   553
    TUint8* size(&iSample[0]);
hgs
parents:
diff changeset
   554
    *size = 0;
hgs
parents:
diff changeset
   555
        
hgs
parents:
diff changeset
   556
    // encode chunk name
hgs
parents:
diff changeset
   557
    iSampleDescriptor.Zero();
hgs
parents:
diff changeset
   558
    iSampleDescriptor.Append(_L("C_"));
hgs
parents:
diff changeset
   559
    c.TraceAppendFullName(iSampleDescriptor,false);
hgs
parents:
diff changeset
   560
    *size += iSampleDescriptor.Size();
hgs
parents:
diff changeset
   561
        
hgs
parents:
diff changeset
   562
    // add chunk object address here
hgs
parents:
diff changeset
   563
    TUint32 chunkAddr((TUint32)&c);
hgs
parents:
diff changeset
   564
    iSampleDescriptor.Append((TUint8*)&(chunkAddr),sizeof(TUint32));
hgs
parents:
diff changeset
   565
    *size += sizeof(TUint32);
hgs
parents:
diff changeset
   566
hgs
parents:
diff changeset
   567
    // the size is the descriptor length + the size field
hgs
parents:
diff changeset
   568
    LOGSTRING2("Non-Heap Chunk Name - %d",*size);
hgs
parents:
diff changeset
   569
    return ((TInt)(*size))+1;           
hgs
parents:
diff changeset
   570
    }
hgs
parents:
diff changeset
   571
hgs
parents:
diff changeset
   572
// encode chunk name 
hgs
parents:
diff changeset
   573
TInt DMemoryEventHandler::EncodeChunkName(DThread& t)
hgs
parents:
diff changeset
   574
    {       
hgs
parents:
diff changeset
   575
    // the size of the following name is in the first byte
hgs
parents:
diff changeset
   576
    TUint8* size(&iSample[0]);
hgs
parents:
diff changeset
   577
    *size = 0;
hgs
parents:
diff changeset
   578
    iSampleDescriptor.Zero();
hgs
parents:
diff changeset
   579
    
hgs
parents:
diff changeset
   580
    iSampleDescriptor.Append(_L("T_"));
hgs
parents:
diff changeset
   581
    t.TraceAppendFullName(iSampleDescriptor,false);
hgs
parents:
diff changeset
   582
    *size += iSampleDescriptor.Size();
hgs
parents:
diff changeset
   583
    
hgs
parents:
diff changeset
   584
    // copy the 4 bytes from the thread id field
hgs
parents:
diff changeset
   585
    iSampleDescriptor.Append((TUint8*)&(t.iId),sizeof(TUint));
hgs
parents:
diff changeset
   586
    *size += sizeof(TUint);
hgs
parents:
diff changeset
   587
hgs
parents:
diff changeset
   588
    // the size is the descriptor length + the size field
hgs
parents:
diff changeset
   589
    LOGSTRING2("Name - %d",*size);
hgs
parents:
diff changeset
   590
    return ((TInt)(*size))+1;
hgs
parents:
diff changeset
   591
    }
hgs
parents:
diff changeset
   592
hgs
parents:
diff changeset
   593
// encode chunk name 
hgs
parents:
diff changeset
   594
TInt DMemoryEventHandler::EncodeChunkName(DLibrary& l)
hgs
parents:
diff changeset
   595
    {       
hgs
parents:
diff changeset
   596
    LOGTEXT("DMemoryEventHandler::EncodeChunkName (LIBRARY)");
hgs
parents:
diff changeset
   597
    // the size of the following name is in the first byte
hgs
parents:
diff changeset
   598
    TUint8* size(&iSample[0]);
hgs
parents:
diff changeset
   599
    *size = 0;
hgs
parents:
diff changeset
   600
    iSampleDescriptor.Zero();
hgs
parents:
diff changeset
   601
    
hgs
parents:
diff changeset
   602
    iSampleDescriptor.Append(_L("L_"));
hgs
parents:
diff changeset
   603
    l.TraceAppendFullName(iSampleDescriptor,false);
hgs
parents:
diff changeset
   604
    *size += iSampleDescriptor.Size();
hgs
parents:
diff changeset
   605
    
hgs
parents:
diff changeset
   606
    // copy the library address here
hgs
parents:
diff changeset
   607
    TUint32 libAddr((TUint32)&l);
hgs
parents:
diff changeset
   608
    iSampleDescriptor.Append((TUint8*) &libAddr,sizeof(TUint32));
hgs
parents:
diff changeset
   609
    *size += sizeof(TUint32);
hgs
parents:
diff changeset
   610
hgs
parents:
diff changeset
   611
    // the size is the descriptor length + the size field
hgs
parents:
diff changeset
   612
    LOGSTRING2("Name - %d",*size);
hgs
parents:
diff changeset
   613
    return ((TInt)(*size))+1;
hgs
parents:
diff changeset
   614
    }
hgs
parents:
diff changeset
   615
hgs
parents:
diff changeset
   616
// record thread stack changes
hgs
parents:
diff changeset
   617
TInt DMemoryEventHandler::EncodeChunkData(DThread& t)
hgs
parents:
diff changeset
   618
    {
hgs
parents:
diff changeset
   619
    LOGSTRING("DMemoryEventHandler::EncodeChunkDataT - entry");
hgs
parents:
diff changeset
   620
        
hgs
parents:
diff changeset
   621
    // the size of the following name is in the first byte
hgs
parents:
diff changeset
   622
    TUint8* size(&iSample[0]);
hgs
parents:
diff changeset
   623
    *size = 0;
hgs
parents:
diff changeset
   624
    iSampleDescriptor.Zero();
hgs
parents:
diff changeset
   625
hgs
parents:
diff changeset
   626
    iSampleDescriptor.Append((TUint8*)&(t.iId),sizeof(TUint));
hgs
parents:
diff changeset
   627
    *size += sizeof(TUint);
hgs
parents:
diff changeset
   628
        
hgs
parents:
diff changeset
   629
    // copy the total amount of memory allocated for user side stack
hgs
parents:
diff changeset
   630
    iSampleDescriptor.Append((TUint8*)&(t.iUserStackSize),sizeof(TInt));
hgs
parents:
diff changeset
   631
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   632
hgs
parents:
diff changeset
   633
    TInt zero(0);      
hgs
parents:
diff changeset
   634
    // append the cell amount allocated (zero, not in use here)
hgs
parents:
diff changeset
   635
    iSampleDescriptor.Append((TUint8*)&zero,sizeof(TInt));
hgs
parents:
diff changeset
   636
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   637
    
hgs
parents:
diff changeset
   638
    // append the chunk size (this is not a chunk)
hgs
parents:
diff changeset
   639
    iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TUint));
hgs
parents:
diff changeset
   640
    *size += sizeof(TUint);
hgs
parents:
diff changeset
   641
hgs
parents:
diff changeset
   642
    // append user stack (max) size
hgs
parents:
diff changeset
   643
    iSampleDescriptor.Append((TUint8*)&(t.iUserStackSize),sizeof(TInt));
hgs
parents:
diff changeset
   644
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   645
62
hgs
parents: 51
diff changeset
   646
    LOGSTRING2("TData -> %d",*size);
20
hgs
parents:
diff changeset
   647
    return ((TInt)(*size))+1;
hgs
parents:
diff changeset
   648
    }
hgs
parents:
diff changeset
   649
hgs
parents:
diff changeset
   650
// record chunk changes
hgs
parents:
diff changeset
   651
TInt DMemoryEventHandler::EncodeChunkData(DChunk& c)
hgs
parents:
diff changeset
   652
    {
hgs
parents:
diff changeset
   653
    LOGSTRING("DMemoryEventHandler::EncodeChunkDataC - entry");
hgs
parents:
diff changeset
   654
    
hgs
parents:
diff changeset
   655
    // the size of the following name is in the first byte
hgs
parents:
diff changeset
   656
    TUint8* size(&iSample[0]);
hgs
parents:
diff changeset
   657
    *size = 0;
hgs
parents:
diff changeset
   658
    iSampleDescriptor.Zero();
hgs
parents:
diff changeset
   659
    TInt zero(0);
hgs
parents:
diff changeset
   660
hgs
parents:
diff changeset
   661
    TUint32 address((TUint32)&c);
62
hgs
parents: 51
diff changeset
   662
    LOGSTRING2("DMemoryEventHandler::EncodeChunkDataC - address 0x%x", *&address);
20
hgs
parents:
diff changeset
   663
    iSampleDescriptor.Append((TUint8*)&address,sizeof(TUint32));
hgs
parents:
diff changeset
   664
    *size += sizeof(TUint);
hgs
parents:
diff changeset
   665
    
hgs
parents:
diff changeset
   666
    // copy the total amount of memory allocated
hgs
parents:
diff changeset
   667
    iSampleDescriptor.Append((TUint8*)&(c.iSize),sizeof(TInt));
hgs
parents:
diff changeset
   668
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   669
        
hgs
parents:
diff changeset
   670
    // append the cell amount allocated
hgs
parents:
diff changeset
   671
    iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
hgs
parents:
diff changeset
   672
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   673
    
hgs
parents:
diff changeset
   674
    // append the chunk size
hgs
parents:
diff changeset
   675
    iSampleDescriptor.Append((TUint8*)&(c.iSize),sizeof(TUint));
hgs
parents:
diff changeset
   676
    *size += sizeof(TUint);
hgs
parents:
diff changeset
   677
        
hgs
parents:
diff changeset
   678
    // append the thread user stack size
hgs
parents:
diff changeset
   679
    iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
hgs
parents:
diff changeset
   680
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   681
62
hgs
parents: 51
diff changeset
   682
    LOGSTRING2("CData - %d",*size);
20
hgs
parents:
diff changeset
   683
    return ((TInt)(*size))+1;
hgs
parents:
diff changeset
   684
    }
hgs
parents:
diff changeset
   685
hgs
parents:
diff changeset
   686
// record loaded libraries changes
hgs
parents:
diff changeset
   687
TInt DMemoryEventHandler::EncodeChunkData(DLibrary& l, DThread& t)
hgs
parents:
diff changeset
   688
    {    
hgs
parents:
diff changeset
   689
    LOGSTRING("DMemoryEventHandler::EncodeChunkDataL - entry");
hgs
parents:
diff changeset
   690
    
hgs
parents:
diff changeset
   691
    // the size of the following name is in the first byte
hgs
parents:
diff changeset
   692
    TUint8* size(&iSample[0]);
hgs
parents:
diff changeset
   693
    *size = 0;
hgs
parents:
diff changeset
   694
    iSampleDescriptor.Zero();
hgs
parents:
diff changeset
   695
    TInt zero(0);
hgs
parents:
diff changeset
   696
hgs
parents:
diff changeset
   697
    TUint32 address((TUint32)&l);
hgs
parents:
diff changeset
   698
    
hgs
parents:
diff changeset
   699
    iSampleDescriptor.Append((TUint8*)&address,sizeof(TUint32));
hgs
parents:
diff changeset
   700
    *size += sizeof(TUint);
hgs
parents:
diff changeset
   701
    
hgs
parents:
diff changeset
   702
    // append amount of memory that library is allocated
hgs
parents:
diff changeset
   703
    iSampleDescriptor.Append((TUint8*)&(l.iCodeSeg->iSize),sizeof(TUint32));
hgs
parents:
diff changeset
   704
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   705
            
hgs
parents:
diff changeset
   706
    // append count of how many times librarys is allocated
hgs
parents:
diff changeset
   707
    iSampleDescriptor.Append((TUint8*)&(l.iMapCount),sizeof(TInt));
hgs
parents:
diff changeset
   708
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   709
    
hgs
parents:
diff changeset
   710
    if(&t != NULL)
hgs
parents:
diff changeset
   711
        {
hgs
parents:
diff changeset
   712
        // created by thread
hgs
parents:
diff changeset
   713
        iSampleDescriptor.Append((TUint8*)&(t),sizeof(TUint32));
hgs
parents:
diff changeset
   714
        }
hgs
parents:
diff changeset
   715
    else
hgs
parents:
diff changeset
   716
        {
hgs
parents:
diff changeset
   717
        // removed
hgs
parents:
diff changeset
   718
        iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TUint32));
hgs
parents:
diff changeset
   719
        }
hgs
parents:
diff changeset
   720
    *size += sizeof(TUint);
hgs
parents:
diff changeset
   721
            
hgs
parents:
diff changeset
   722
    // append the thread user stack size
hgs
parents:
diff changeset
   723
    iSampleDescriptor.Append((TUint8*)&(zero),sizeof(TInt));
hgs
parents:
diff changeset
   724
    *size += sizeof(TInt);
hgs
parents:
diff changeset
   725
    return ((TInt)(*size))+1;
hgs
parents:
diff changeset
   726
    }
hgs
parents:
diff changeset
   727