2009-04-13 16 views
12

¿Qué herramientas están disponibles para atribuir los consumos de memoria en la aplicación VB6 a sus componentes múltiples? Puedo obtener la memoria consumida por toda la aplicación observando varios contadores (Bytes privados, Conjunto de trabajo, etc.), por ejemplo, en Process Explorer. Quiero ir a un nivel más profundo que eso y comprender cuánta memoria consumen los diversos componentes u objetos creados en tiempo de ejecución. Por ejemplo, descubra cuánta memoria consume una gran colección que almacena datos en caché en tiempo de ejecución y cómo cambia según el número de elementos en la colección.Herramientas para identificar cerdos de memoria en aplicaciones VB6

Respuesta

2

No estoy seguro de que las herramientas (gratuitas) disponibles públicamente perfilen el código VB6 hasta el nivel del módulo. Hay varios perfiladores de memoria disponibles para C/C++ y .NET, pero no mucho en VB6 que vi. Parece que todos los proveedores anteriores (IBM Purify, Compuware Devpartner/Boundschecker) en esta área han sido comprados o pasaron al soporte de .NET solamente.

Puede probar GlowCode. Establece compatibilidad con C++, pero también enfatiza las imágenes nativas x86 de Win32.

Microsoft publica DebugDiag, que tiene soporte para detección de fuga de memoria para .NET o Win32, aunque nunca lo he usado con VB. Puede que no muestre asignaciones sobresalientes al nivel de módulo, pero apostaría que al menos se atribuirá qué bibliotecas/dlls han asignado la mayor cantidad de memoria.

1

Hay otra herramienta en el sitio de MS llamada processmonitor.exe. Informa cada llamada de solicitud y puede usar su capacidad de filtrado para supervisar solo las solicitudes de proceso de su aplicación.

+0

Esta herramienta no puede ir más allá de Process Monitor porque no conoce el uso de la memoria VB6. –

5

Mi herramienta favorita tiene que ser DevPartner, aunque en £ 1,500 el pop no es barato. Sin embargo, hace muchísimo más que la comprobación de fuga de memoria, pero si eso es todo lo que necesitas, podrías ser hormigas de bombardeo de alfombras.

Si desea ver si su aplicación está liberando recursos correctamente, use esta función que escribí para volcar la memoria en una ubicación determinada. Primero almacenaría en caché las direcciones de cada una de sus variables y luego, al apagarlas, podría llamar a DumpVariableMemory pasando referencias a esas ubicaciones para ver si se han desasignado.

Si no tiene uno ya, tendrá que añadir un declarar fopr CopyMemory también :)

Public Function DumpVariableMemory(ByVal lngVariablePointer&, _ 
            ByVal lngBufferSizeInBytes&) As String 
    '' * Object Name: DumpVariableMemory 
    '' * Type:   Function 
    '' * Purpose:  Returns a memory dump of the variable or pointer location 
    '' * Created:  21/08/2006 - 17:41:32 
    '' * Coder:   Richard Pashley - NUPUK00008148 
    '' * Build Machine: W-XPRP-77 
    '' * Encapsulation: Full 
    '' * Parameters: lngVariablePointer  - Long - Pointer to the data to dump 
    '' *    lngBufferSizeInBytes - Long - Size of the dump to ouput in bytes 
    '' * Returns:  -      - String - Memory dump output as a string 
    '' *    This will dump the memory location starting at the pointer address and 
    '' *    ending at the address plus the offset (lngBufferSizeInBytes). 
    '' *    You can use LenB to determine the size of the variable for the 
    '' *    lngBufferSizeInBytes parameter if required. 
    '' *    Example: DebugPrint DumpVariableMemory(VarPtr(lngMyLongValue),LenB(lngMyLongValue) 
    '' * Modified By: [Name] 
    '' * Date:   [Date] 
    '' * Reason:  [NUPUKxxxxxxxxx] 
    '' Declare locals 
    Dim lngBufferIterator&     '' Buffer iterator 
    Dim lngBufferInnerIterator&    '' Buffer loop inner iterator 
    Dim bytHexDumpArray() As Byte   '' Received output buffer 
    Dim strDumpBuffer$      '' Formatted hex dump construction buffer 
    Dim lngValidatedBufferSize&    '' Validated passed buffer size 
    '' Turn on error handling 
    On Error GoTo DumpVariableMemory_Err 
    '' Resize output buffer 
    ReDim bytHexDumpArray(0 To lngBufferSizeInBytes - 1) As Byte 
    '' Retrieve memory contents from supplied pointer 
    Call CopyMemory(bytHexDumpArray(0), _ 
     ByVal lngVariablePointer, _ 
     lngBufferSizeInBytes) 
    '' Format dump header 
    strDumpBuffer = String(81, "=") & vbCrLf & _ 
     "Pointer Address = &h" & Hex$(lngVariablePointer) & _ 
     " Ouput Buffer Size = " & FormatBytes(lngBufferSizeInBytes) 
    '' Add header seperator 
    strDumpBuffer = strDumpBuffer & _ 
     vbCrLf & String(81, Chr$(61)) 
    '' Validate buffer dimensions 
    If lngBufferSizeInBytes Mod 16 = 0 Then 
     '' Validated ok so assign 
     lngValidatedBufferSize = lngBufferSizeInBytes 
    Else 
     '' Refactor to base 16 
     lngValidatedBufferSize = _ 
      ((lngBufferSizeInBytes \ 16) + 1) * 16 
    End If 
    '' Iterate through buffer contents 
    For lngBufferIterator = 0 To (lngValidatedBufferSize - 1) 
     '' Determine if first row 
     If (lngBufferIterator Mod 16) = 0 Then 
      '' Format dump output row 
      strDumpBuffer = strDumpBuffer & vbCrLf & Right$(String(8, Chr$(48)) _ 
       & Hex$(lngVariablePointer + lngBufferIterator), 8) & Space(2) & _ 
       Right$(String(4, Chr$(48)) & Hex$(lngBufferIterator), 4) & Space(2) 
     End If 
     '' Determine required dump buffer padding 
     If lngBufferIterator < lngBufferSizeInBytes Then 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Right$(Chr$(48) & _ 
       Hex(bytHexDumpArray(lngBufferIterator)), 2) 
     Else 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Space(2) 
     End If 
     '' Determine required dump buffer padding 
     If (lngBufferIterator Mod 16) = 15 Then 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Space(2) 
      '' Iterate through buffer row 
      For lngBufferInnerIterator = (lngBufferIterator - 15) To lngBufferIterator 
       '' Validate row width 
       If lngBufferInnerIterator < lngBufferSizeInBytes Then 
        '' Validate buffer constraints 
        If bytHexDumpArray(lngBufferInnerIterator) >= 32 And _ 
         bytHexDumpArray(lngBufferInnerIterator) <= 126 Then 
         '' Ouput data to dump buffer row 
         strDumpBuffer = strDumpBuffer & _ 
          Chr$(bytHexDumpArray(lngBufferInnerIterator)) 
        Else 
         '' Pad dump buffer 
         strDumpBuffer = strDumpBuffer & Chr$(45) 
        End If 
       End If 
      Next 
      '' Determine required dump buffer padding 
     ElseIf (lngBufferIterator Mod 8) = 7 Then 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Chr$(45) 
     Else 
      '' Pad dump buffer 
      strDumpBuffer = strDumpBuffer & Space(1) 
     End If 
    Next 
    '' Assign result to function output 
    DumpVariableMemory = strDumpBuffer & _ 
     vbCrLf & String(81, Chr$(61)) & vbCrLf 
Exit_Point: 
    Exit Function 
    '' Error Handling 
DumpVariableMemory_Err: 
    LogError "modNYFixLibrary.DumpVariableMemory", Err.Number, Err.Description 
    DumpVariableMemory = String(81, Chr$(61)) & vbCrLf & _ 
     "DumpFailed!" & vbCrLf & String(81, Chr$(61)) 
    GoTo Exit_Point 
    Resume 
End Function 
2

Memory Validator se puede decir donde se asigna la memoria (y filtrada) en programas de Visual Basic 6 (y C++, C, Delphi, Fortran 95 ...).

Cuestiones relacionadas