Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Commit

Permalink
Init repo with Webgrind bundles from Neard
Browse files Browse the repository at this point in the history
Retrieve changes from git commit 78850a70 on jokkedk/webgrind repository
  • Loading branch information
crazy-max committed Apr 7, 2016
0 parents commit ee86cb6
Show file tree
Hide file tree
Showing 44 changed files with 3,288 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Eclipse
.settings
.buildpath
.project
.jsdtscope
*.launch

# Ant
build.properties
build.xml

# Neard
.dev
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## r1 (2016/04/07)

This release works since **[Neard 1.0.0](https://github.com/crazy-max/neard/releases/tag/v1.0.0)**

* Init repo with Webgrind bundles from [Neard](https://github.com/crazy-max/neard)
* Retrieve changes from [git commit 78850a70 on jokkedk/webgrind repository](https://github.com/jokkedk/webgrind/tree/78850a704538040d3d5326cfe7a9d039abdc4d56)
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
This a sub-repo of [Neard project](https://github.com/crazy-max/neard) involving Webgrind app bundles.

## Installation

* Download and install [Neard](https://github.com/crazy-max/neard).
* If you already have installed Neard, stop it.
* Download [a Webgrind bundle](#download).
* Extract archive in `neard\apps\webgrind\`. Directory structure example :

```
[-] neard
| [-] apps
| | [-] webgrind
| | | [-] webgrind1.0
| | | neard.conf
```

* Edit the `neard.conf` file and replace the key `webgrindVersion` with the correct version.
* Edit the `alias/webgrind.conf` file and replace the lines with the correct version.
* Start Neard.

## Download

![](https://raw.github.com/crazy-max/neard-app-webgrind/master/img/star-20160403.png) : Default bundle on Neard.

| | Webgrind release date | Neard release | Download |
| -----------------|:---------------------:|:-------------:|:--------:|
| **Webgrind 1.0** | 2009/02/20 | [r1](https://github.com/crazy-max/neard-app-webgrind/releases/tag/r1) | [neard-webgrind-1.0-r1.zip](https://github.com/crazy-max/neard-app-webgrind/releases/download/r1/neard-webgrind-1.0-r1.zip) |

## Sources

* https://github.com/jokkedk/webgrind

## Issues

Issues must be reported on [Neard repository](https://github.com/crazy-max/neard/issues).<br />
Please read [Found a bug?](https://github.com/crazy-max/neard#found-a-bug) section before reporting an issue.
85 changes: 85 additions & 0 deletions bin/webgrind1.0/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/**
* Configuration for webgrind
* @author Jacob Oettinger
* @author Joakim Nygård
*/
class Webgrind_Config{
/**
* Automatically check if a newer version of webgrind is available for download
*/
static $checkVersion = true;
static $hideWebgrindProfiles = true;

/**
* Writable dir for information storage.
* If empty, will use system tmp folder or xdebug tmp
*/
static $storageDir = '';
static $profilerDir = '';

/**
* Suffix for preprocessed files
*/
static $preprocessedSuffix = '.webgrind';

static $defaultTimezone = 'UTC';
static $dateFormat = 'Y-m-d H:i:s';
static $defaultCostformat = 'percent'; // 'percent', 'usec' or 'msec'
static $defaultFunctionPercentage = 90;
static $defaultHideInternalFunctions = false;

/**
* sprintf compatible format for generating links to source files.
* %1$s will be replaced by the full path name of the file
* %2$d will be replaced by the linenumber
*/
static $fileUrlFormat = 'index.php?op=fileviewer&file=%1$s&line=%2$d'; // Built in fileviewer
//static $fileUrlFormat = 'txmt://open/?url=file://%1$s&line=%2$d'; // Textmate
//static $fileUrlFormat = 'file://%1$s'; // ?


#########################
# BELOW NOT FOR EDITING #
#########################

static $webgrindVersion = '1.0';

/**
* Regex that matches the trace files generated by xdebug
*/
static function xdebugOutputFormat() {
$outputName = ini_get('xdebug.profiler_output_name');
if($outputName=='') // Ini value not defined
$outputName = '/^cachegrind\.out\..+$/';
else
$outputName = '/^'.preg_replace('/(%[^%])+/', '.+', $outputName).'$/';
return $outputName;
}

/**
* Directory to search for trace files
*/
static function xdebugOutputDir() {
$dir = ini_get('xdebug.profiler_output_dir');
if($dir=='') // Ini value not defined
return realpath(Webgrind_Config::$profilerDir).'/';
return realpath($dir).'/';
}

/**
* Writable dir for information storage
*/
static function storageDir() {
if (!empty(Webgrind_Config::$storageDir))
return realpath(Webgrind_Config::$storageDir).'/';

if (!function_exists('sys_get_temp_dir') || !is_writable(sys_get_temp_dir())) {
# use xdebug setting
return Webgrind_Config::xdebugOutputDir();
}
return realpath(sys_get_temp_dir()).'/';
}
}
Binary file added bin/webgrind1.0/img/asc.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/bg.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/blank.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/call_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/call_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/call_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/call_orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/desc.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/down.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/file_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/gradient_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/gradient_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/gradient_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/gradient_left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/gradient_markers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/gradient_orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/gradient_right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/reload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/webgrind1.0/img/right.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 159 additions & 0 deletions bin/webgrind1.0/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php
/**
* @author Jacob Oettinger
* @author Joakim Nygård
*/

require 'config.php';
require 'library/FileHandler.php';

// TODO: Errorhandling:
// No files, outputdir not writabel

set_time_limit(0);

// Make sure we have a timezone for date functions.
if (ini_get('date.timezone') == '')
date_default_timezone_set( Webgrind_Config::$defaultTimezone );


switch(get('op')){
case 'file_list':
echo json_encode(Webgrind_FileHandler::getInstance()->getTraceList());
break;
case 'function_list':
$dataFile = get('dataFile');
if($dataFile=='0'){
$files = Webgrind_FileHandler::getInstance()->getTraceList();
$dataFile = $files[0]['filename'];
}
$reader = Webgrind_FileHandler::getInstance()->getTraceReader($dataFile, get('costFormat', Webgrind_Config::$defaultCostformat));
$functions = array();
$shownTotal = 0;
$breakdown = array('internal' => 0, 'user' => 0, 'class' => 0, 'include' => 0);

for($i=0;$i<$reader->getFunctionCount();$i++) {
$functionInfo = $reader->getFunctionInfo($i);


if (false !== strpos($functionInfo['functionName'], 'php::')) {
$breakdown['internal'] += $functionInfo['summedSelfCost'];
$humanKind = 'internal';
$kind = 'blue';
} elseif (false !== strpos($functionInfo['functionName'], 'require_once::') ||
false !== strpos($functionInfo['functionName'], 'require::') ||
false !== strpos($functionInfo['functionName'], 'include_once::') ||
false !== strpos($functionInfo['functionName'], 'include::')) {
$breakdown['include'] += $functionInfo['summedSelfCost'];
$humanKind = 'include';
$kind = 'grey';
} else {
if (false !== strpos($functionInfo['functionName'], '->') || false !== strpos($functionInfo['functionName'], '::')) {
$breakdown['class'] += $functionInfo['summedSelfCost'];
$humanKind = 'class';
$kind = 'green';
} else {
$breakdown['user'] += $functionInfo['summedSelfCost'];
$humanKind = 'procedural';
$kind = 'orange';
}
}
if (!(int)get('hideInternals', 0) || strpos($functionInfo['functionName'], 'php::') === false) {
$shownTotal += $functionInfo['summedSelfCost'];
$functions[$i] = $functionInfo;
$functions[$i]['nr'] = $i;
$functions[$i]['kind'] = $kind;
$functions[$i]['humanKind'] = $humanKind;
}

}
usort($functions,'costCmp');

$remainingCost = $shownTotal*get('showFraction');

$result['functions'] = array();
foreach($functions as $function){

$remainingCost -= $function['summedSelfCost'];

$result['functions'][] = $function;
if($remainingCost<0)
break;
}
$result['summedInvocationCount'] = $reader->getFunctionCount();
$result['summedRunTime'] = $reader->formatCost($reader->getHeader('summary'), 'msec');
$result['dataFile'] = $dataFile;
$result['invokeUrl'] = $reader->getHeader('cmd');
$result['runs'] = $reader->getHeader('runs');
$result['breakdown'] = $breakdown;
$result['mtime'] = date(Webgrind_Config::$dateFormat,filemtime(Webgrind_Config::xdebugOutputDir().$dataFile));
echo json_encode($result);
break;
case 'callinfo_list':
$reader = Webgrind_FileHandler::getInstance()->getTraceReader(get('file'), get('costFormat', Webgrind_Config::$defaultCostformat));
$functionNr = get('functionNr');
$function = $reader->getFunctionInfo($functionNr);

$result = array('calledFrom'=>array(), 'subCalls'=>array());
$foundInvocations = 0;
for($i=0;$i<$function['calledFromInfoCount'];$i++){
$invo = $reader->getCalledFromInfo($functionNr, $i);
$foundInvocations += $invo['callCount'];
$callerInfo = $reader->getFunctionInfo($invo['functionNr']);
$invo['file'] = $callerInfo['file'];
$invo['callerFunctionName'] = $callerInfo['functionName'];
$result['calledFrom'][] = $invo;
}
$result['calledByHost'] = ($foundInvocations<$function['invocationCount']);

for($i=0;$i<$function['subCallInfoCount'];$i++){
$invo = $reader->getSubCallInfo($functionNr, $i);
$callInfo = $reader->getFunctionInfo($invo['functionNr']);
$invo['file'] = $function['file']; // Sub call to $callInfo['file'] but from $function['file']
$invo['callerFunctionName'] = $callInfo['functionName'];
$result['subCalls'][] = $invo;
}
echo json_encode($result);

break;
case 'fileviewer':
$file = get('file');
$line = get('line');

if($file && $file!=''){
$message = '';
if(!file_exists($file)){
$message = $file.' does not exist.';
} else if(!is_readable($file)){
$message = $file.' is not readable.';
} else if(is_dir($file)){
$message = $file.' is a directory.';
}
} else {
$message = 'No file to view';
}
require 'templates/fileviewer.phtml';

break;
case 'version_info':
$response = @file_get_contents('http://jokke.dk/webgrindupdate.json?version='.Webgrind_Config::$webgrindVersion);
echo $response;
break;
default:
require 'templates/index.phtml';
}


function get($param, $default=false){
return (isset($_GET[$param])? $_GET[$param] : $default);
}

function costCmp($a, $b){
$a = $a['summedSelfCost'];
$b = $b['summedSelfCost'];

if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
Loading

0 comments on commit ee86cb6

Please sign in to comment.