久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何確定變量的內存占用(大小)?

How to determine the memory footprint (size) of a variable?(如何確定變量的內存占用(大小)?)
本文介紹了如何確定變量的內存占用(大小)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

PHP(或 PHP 擴展)中是否有函數可以找出給定變量使用了多少內存?sizeof 只是告訴我元素/屬性的數量.

memory_get_usage 的幫助在于它為我提供了 整個 腳本使用的內存大小.有沒有辦法對單個變量執行此操作?

請注意,這是在開發機器上,因此加載擴展或調試工具是可行的.

解決方案

您可能需要一個內存分析器.我已經收集了 SO 的信息,但我復制了一些可能對您也有幫助的重要內容.

您可能知道,從 2.* 版本開始,Xdebug 放棄了內存分析支持.請搜索已刪除的功能"這里的字符串:.

黑火

Blackfire 是 Symfony2 的 SensioLabs 開發的 PHP 分析器https://blackfire.io/

如果您使用 puphpet 來設置您的虛擬機,您會很高興知道它受支持;-)

Xdebug 和跟蹤內存使用情況

XDEBUG2 是 PHP 的擴展.Xdebug 允許您記錄所有函數調用,包括參數和以不同格式返回到文件的值.有三種輸出格式.一個是人類可讀的跟蹤,另一個更適合計算機程序,因為它更容易解析,最后一個使用 HTML 來格式化跟蹤.您可以通過設置在兩種不同的格式之間切換.一個例子是此處提供

forp

forp 簡單、非侵入性、面向生產的 PHP 分析器.一些功能是:

  • 為每個函數測量時間和分配的內存

  • CPU 使用率

  • 函數調用的文件和行號

  • 輸出為 Google 的跟蹤事件格式

  • 函數說明

  • 功能分組

  • 函數的別名(對匿名函數有用)

DBG

DBG 是一個全功能的 php 調試器,一個幫助您調試 php 腳本的交互式工具.它適用于生產和/或開發 WEB 服務器,允許您從 IDE 或控制臺在本地或遠程調試腳本,其功能是:

  • 遠程和本地調試

  • 顯式和隱式激活

  • 調用棧,包括函數調用、動態和靜態方法調用及其參數

  • 在調用堆棧中導航,能夠評估相應(嵌套)位置中的變量

  • 步進/步進/步進/運行到光標功能

  • 條件斷點

  • 全局斷點

  • 記錄錯誤和警告

  • 用于并行調試的多個同時會話

  • 支持 GUI 和 CLI 前端

  • 支持 IPv6 和 IPv4 網絡

  • 調試器傳輸的所有數據都可以選擇使用 SSL 保護

Is there a function in PHP (or a PHP extension) to find out how much memory a given variable uses? sizeof just tells me the number of elements/properties.

memory_get_usage helps in that it gives me the memory size used by the whole script. Is there a way to do this for a single variable?

Note that this is on a development machine, so loading extensions or debug tools is feasible.

解決方案

You Probably need a Memory Profiler. I have gathered information fro SO but I have copied the some important thing which may help you also.

As you probably know, Xdebug dropped the memory profiling support since the 2.* version. Please search for the "removed functions" string here: http://www.xdebug.org/updates.php

Removed functions

Removed support for Memory profiling as that didn't work properly.

Other Profiler Options

php-memory-profiler

https://github.com/arnaud-lb/php-memory-profiler. This is what I've done on my Ubuntu server to enable it:

sudo apt-get install libjudy-dev libjudydebian1
sudo pecl install memprof
echo "extension=memprof.so" > /etc/php5/mods-available/memprof.ini
sudo php5enmod memprof
service apache2 restart

And then in my code:

<?php
memprof_enable();
// do your stuff
memprof_dump_callgrind(fopen("/tmp/callgrind.out", "w"));

Finally open the callgrind.out file with KCachegrind

Using Google gperftools (recommended!)

First of all install the Google gperftools by downloading the latest package here: https://code.google.com/p/gperftools/

Then as always:

sudo apt-get update
sudo apt-get install libunwind-dev -y
./configure
make
make install

Now in your code:

memprof_enable();

// do your magic

memprof_dump_pprof(fopen("/tmp/profile.heap", "w"));

Then open your terminal and launch:

pprof --web /tmp/profile.heap

pprof will create a new window in your existing browser session with something like shown below:

Xhprof + Xhgui (the best in my opinion to profile both cpu and memory)

With Xhprof and Xhgui you can profile the cpu usage as well or just the memory usage if that's your issue at the moment. It's a very complete solutions, it gives you full control and the logs can be written both on mongo or in the filesystem.

For more details see here.

Blackfire

Blackfire is a PHP profiler by SensioLabs, the Symfony2 guys https://blackfire.io/

If you use puphpet to set up your virtual machine you'll be happy to know it's supported ;-)

Xdebug and tracing memory usage

XDEBUG2 is a extension for PHP. Xdebug allows you to log all function calls, including parameters and return values to a file in different formats.There are three output formats. One is meant as a human readable trace, another one is more suited for computer programs as it is easier to parse, and the last one uses HTML for formatting the trace. You can switch between the two different formats with the setting. An example would be available here

forp

forp simple, non intrusive, production-oriented, PHP profiler. Some of features are:

  • measurement of time and allocated memory for each function

  • CPU usage

  • file and line number of the function call

  • output as Google's Trace Event format

  • caption of functions

  • grouping of functions

  • aliases of functions (useful for anonymous functions)

DBG

DBG is a a full-featured php debugger, an interactive tool that helps you debugging php scripts. It works on a production and/or development WEB server and allows you debug your scripts locally or remotely, from an IDE or console and its features are:

  • Remote and local debugging

  • Explicit and implicit activation

  • Call stack, including function calls, dynamic and static method calls, with their parameters

  • Navigation through the call stack with ability to evaluate variables in corresponding (nested) places

  • Step in/Step out/Step over/Run to cursor functionality

  • Conditional breakpoints

  • Global breakpoints

  • Logging for errors and warnings

  • Multiple simultaneous sessions for parallel debugging

  • Support for GUI and CLI front-ends

  • IPv6 and IPv4 networks supported

  • All data transferred by debugger can be optionally protected with SSL

這篇關于如何確定變量的內存占用(大小)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 中文字幕欧美日韩 | 99九色| 三区在线 | 爱爱视频在线观看 | 亚洲一区二区在线免费观看 | 围产精品久久久久久久 | 午夜无码国产理论在线 | 精品国产色 | 欧美视频1区 | 国产精品成人一区二区三区吃奶 | 综合五月 | 偷拍自拍网 | 免费在线一区二区三区 | 性一交一乱一伦视频免费观看 | 欧美一级高潮片免费的 | 毛片入口 | 国产精品美女久久久 | 综合激情网| 中文字幕一区二区三区四区 | 中文字幕第一页在线 | 一区二区三区在线 | 成人污污视频 | 网站一区二区三区 | 久久曰视频 | 国产成人网 | 中文字幕 在线观看 | 激情91 | 亚洲精品短视频 | 日韩精品一区二区三区视频播放 | 日韩欧美在线观看一区 | 精品一区二区三区在线观看 | 日日精品 | 国产乱一区二区三区视频 | 国产高清在线精品 | 欧美涩涩网| 国产传媒在线播放 | 国产高清在线观看 | 国产美女免费视频 | 亚洲精品久久久久中文字幕欢迎你 | 91久久久久| 国产一区二区在线免费播放 |