Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
parf committed Mar 22, 2018
1 parent 9412549 commit ba96c6f
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
6 changes: 6 additions & 0 deletions project/app1/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

define("APP_DIR", __DIR__);
include dirname(__DIR__)."/init.php"; // project init

\hb\HB::dispatch();
84 changes: 84 additions & 0 deletions project/app1/src/app1/action/Profiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace app1\action;

/*
* Sample Nested and Deep Profiling Example
**/

class Profiler extends \hb\Action {

# uri: /profiler/
function index() {
echo "<h1>Complex Profiling Example</h1>";

$API_KEY = \hb\Str::random(6);
iprofiler()->in("api-call-wrapper", ["api-params" => 'outter api call'], ['api' => $API_KEY, 'style' => 'hide']);
iprofiler()->api("api-call", ["api-params"]);
iprofiler()->info("opts[link] + args[0]", ['arg[0] text', 'a' => 'A'], ['link' => '/url/', 'edit' => '/xxx']);
iprofiler()->inHide("in and hide", ['text'], ['details' => '/url/', 'edit' => '/xxx']);
iprofiler()->api("api-call internal", ["api-params 2"]);
usleep(60200);
$a = str_repeat("xxx", 400000);
iprofiler()->out(['arg-in-out' => "a"]);
unset($a);
iprofiler()->out(['arg-in-out' => "b"]);


$x = new XXX_Very_Very_Long_ClassName();
$x->veryVeryLong_Method__Name("a", [1,2,3], "b", str_repeat("abC-", 22), $_SERVER);
unset($P);


return 0;
}

}


function A_Project($callable, ...$args) {
return $callable(...$args);
}

class XXX_Very_Very_Long_ClassName {

function veryVeryLong_Method__Name($a, $b, $c, $d) {
return A_Project("XXX_Very_Very_Long_ClassName::methodName", $b, [$a, [$c, $d]]);
}

static function methodName($param1, &$param2, $deep = 0) {
$P = profiler(__FUNCTION__, $param1);
hb\dbg(1, "in-here");
// hb\e(hb\HB::$Q);
usleep(800);
iprofiler()->info("info", ['reason' => 'test:', 'p' => $param1]);
usleep(900);
if ($deep == 3) {
static $cnt = 0;
if (! $cnt++)
iprofiler()->alert("alert",['reason' => 'test alert', 'p' => $param1]);
}
elseif ($deep == 4)
iprofiler()->warn("warning",['reason' => 'test warning', 'p' => $param1]);
else
iprofiler()->info("some info",['rxx' => 'test', \hb\Str::random(3)]);
if ($deep > 4) {
$API_KEY = \hb\Str::random(6);
iprofiler()->info("api-call", ["xxarams" => $param1], ['api' => $API_KEY]);
return;
}
if ($deep > 3)
iprofiler()->inHide("xx$deep", [\hb\Str::random(3) => \hb\Str::random()], ['tag' => $deep & 1 ? 'sql' : 'mongo', 'details' => '/dvp/vvv']);
else
iprofiler()->in("xx$deep", [\hb\Str::random(2) => \hb\Str::random(5)], ['tag' => 'sql', 'edit' => "/dvp/edit"]);
usleep(900);
$x = [1,2];
self::methodName($deep, $x, $deep+1);
self::methodName($deep."x", $x, $deep+1);
iprofiler()->out();
# <h1>H1sdfs</h1>
#1/0;
#C(str_repeat("unknonwn.node;", 22));
}

}
11 changes: 11 additions & 0 deletions project/app1/src/app1/action/Root.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace app1\action;

class Root extends \hb\Action {

function index() {
echo "hello world";
}

}
6 changes: 6 additions & 0 deletions project/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
if (! defined("APP_DIR"))
define("APP_DIR", __DIR__);
define("PROJECT_DIR", __DIR__);
include __DIR__."/vendor/hb2/src/homebase-bundle.inc.php"; // homebase project init

11 changes: 11 additions & 0 deletions project/scripts/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/env p
<?php

# file develper play with
v(C("A"));
v(C("B"));
v(C("tier"));
v("--config", i('config')->_appConfig());
v("--config", i('config')->_projectConfig());

# v("--fw-config", i('config')->getFrameworkDefault());
28 changes: 28 additions & 0 deletions project/scripts/profiler-use.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/php
<?php

include __DIR__."/../init.php";

// project-specific init
# iprofiler()->enable(true); // turn on profiler EVEN in cli mode ## same as "--profile"
# iprofiler()->trace(); // echo all profiler calls (debug mode only) ## same as "--trace"
# iprofiler()->trace('File', ['filename' => 'trace.log']); // save all profiler calls to file (debug mode only)
echo i('cli')->red("red bold text", "bold"), "\n";
i('cli')->e("{red}{bold}%s{/}\n", "red bold text");

iprofiler()->in("a");
iprofiler()->in("b");
iprofiler()->in("b:1");
iprofiler()->out();
iprofiler()->in("b:2");
usleep(2000);
iprofiler()->out();
iprofiler()->in("b:3");
i('cli')->box("Hello World");
iprofiler()->out();
iprofiler()->out(['x' => 1]);
iprofiler()->out();
iprofiler()->in("cc");
iprofiler()->out();

# iprofiler()->debug();

0 comments on commit ba96c6f

Please sign in to comment.