Skip to content

Commit

Permalink
Merge pull request #5 from SeasX/master
Browse files Browse the repository at this point in the history
update to 2.0.2
  • Loading branch information
Neeke committed Feb 12, 2019
2 parents dab1d55 + 14e46bc commit 3809c86
Show file tree
Hide file tree
Showing 21 changed files with 1,191 additions and 167 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Expand Up @@ -4,6 +4,7 @@ skip_tags: true
branches:
only:
- master
- 2.x
- bug_fix
- /branch.*/

Expand Down
8 changes: 7 additions & 1 deletion .travis.yml
Expand Up @@ -8,14 +8,20 @@ os:
- linux
# - osx

matrix:
include:
- php: 5.3
dist: precise

php:
# - 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- nightly
# - nightly

notifications:
email: neeke@php.net
Expand Down
42 changes: 40 additions & 2 deletions README.md
Expand Up @@ -18,7 +18,7 @@ An effective,fast,stable log extension for PHP
- **[What is the target](#what-is-the-target)**
- **[Install](#install)**
- **[Make Install SeasLog](#make-Install-SeasLog)**
- **[seaslog.ini](#seaslog.ini)**
- **[seaslog.ini](#seaslogini)**
- **[Custom log template](#custom-log-template)**
- [Log template overview](#log-template-overview)
- [Default variable table](#default-variable-table)
Expand Down Expand Up @@ -206,6 +206,33 @@ seaslog.throw_exception = 1
;Switch ignore SeasLog warning.
;1-On(Default) 0-Off
seaslog.ignore_warning = 1
;Switch Performance Tracking 1-On 0-Off(Default)
seaslog.trace_performance = 0
;Performance Tracking Sample Rate Per Thousand.
;10(Default). 10 conceptions per thousand
seaslog.trace_performance_sample_rate = 10
;Performance Tracking Start With Depth Level. 1(Default)
seaslog.trace_performance_start_depth = 1
;Performance Tracking Depth Level. 5(Default)
seaslog.trace_performance_max_depth = 5
;Maximum number of functions per layer in descending order of wall_time for performance tracking.
;Top default top5
seaslog.trace_performance_max_functions_per_depth = 5
;The record threshold of the current request execution time for performance tracking.
;Only when the request execution time is greater than that value.
;1000(ms Default)
seaslog.trace_performance_min_wall_time = 1000
;The record threshold of execution time of each method in performance tracking.
;Only when the execution time of each method is greater than that value.
;10(ms Default)
seaslog.trace_performance_min_function_wall_time = 10
```
> `seaslog.disting_folder = 1` Switch use Logger DisTing by folder, it’s meaning SeasLog will create the file deistic by folder, and when this configure close SeasLog will create file use underline connect Logger and Time like default_20180211.log.
Expand Down Expand Up @@ -241,6 +268,17 @@ seaslog.ignore_warning = 1
> `seaslog.ignore_warning = 1` Open a warning to ignore SeasLog itself. When directory permissions or receive server ports are blocked, they are ignored; when closed, a warning is thrown.
> `seaslog.trace_performance = 1` Open the performance tracing. Performance log such as:
```sh
2019-01-30 11:46:53 | INFO | 91390 | 5c518ea46e010 | 1548848813.299 | {"main()":{"wt":8848,"mu":20712},"1":[{"cm":"Class0::Method0","ct":2,"wt":2007,"mu":192},{"cm":"Class1::Method1","ct":1,"wt":1002,"mu":192},{"cm":"Class2::Method2","ct":1,"wt":1001,"mu":192},{"cm":"Class3::Method3","ct":1,"wt":1000,"mu":192},{"cm":"Class4::Method4","ct":1,"wt":1000,"mu":192}],"2":[{"cm":"Class5::Method5","ct":1,"wt":1000,"mu":192}],"3":[{"cm":"Class5::Recursion","ct":1,"wt":1000,"mu":3248}],"4":[{"cm":"Class5::Recursion","ct":1,"wt":1000,"mu":2952}],"5":[{"cm":"Class5::Recursion","ct":1,"wt":1000,"mu":2656}]}
cm => function_name (ClassName::MethodName)
wt => wall_time (ms)
mu => memory_usage (byte)
ct => call_times (function call times)
```
### Custom log template
Many friends mentioned the need for custom log templates during their use,
so `SeasLog` began with the 1.7.2 version and has the ability to allow users to customize the template for the log.
Expand Down Expand Up @@ -270,7 +308,7 @@ At the same time, many preset variables that are preset by `SeasLog` can be used
* `%F` - FileName:LineNo. Such as `UserService.php:118`.
* `%U` - MemoryUsage. byte. Call `zend_memory_usage`.
* `%u` - PeakMemoryUsage. byte. Call `zend_memory_peak_usage`.
* `%C` - `TODO` Class::Action. Such as `UserService::getUserInfo`.
* `%C` - Class::Action. Such as `UserService::getUserInfo`. in procedural programming, it falls back to function name.
## Use age
Expand Down
35 changes: 34 additions & 1 deletion README_zh.md
Expand Up @@ -196,6 +196,28 @@ seaslog.throw_exception = 1
;是否开启忽略SeasLog自身warning 1开启(默认) 0否
seaslog.ignore_warning = 1
;是否开启性能追踪 1开启 0关闭(默认)
seaslog.trace_performance = 0
;性能追踪时的千分比采样率
;默认10,即百分之一
seaslog.trace_performance_sample_rate = 10
;性能追踪时的开始层级 默认从第1层开始
seaslog.trace_performance_start_depth = 1
;性能追踪时深度层级 默认5层
seaslog.trace_performance_max_depth = 5
;性能追踪时每层的函数最大数 按wall_time降序排列top 默认top5
seaslog.trace_performance_max_functions_per_depth = 5
;性能追踪时当前请求执行时间的记录阈值 只有当请求执行时间大于该值时,才记录性能日志 默认1000ms
seaslog.trace_performance_min_wall_time = 1000
;性能追踪时每个方法执行时间的记录阈值 只有当方法执行时间大于该值时,才参与计算 默认10ms
seaslog.trace_performance_min_function_wall_time = 10
```
> `seaslog.disting_folder = 1` 开启以目录分文件,即logger以目录区分。当关闭时,logger以下划线拼接时间, 如default_20180211.log。
Expand Down Expand Up @@ -231,6 +253,17 @@ seaslog.ignore_warning = 1
> `seaslog.ignore_warning = 1` 开启忽略SeasLog自身的警告。当出现目录权限或接收服务器端口不通等情况时,将进行忽略;关闭时,将抛出警告。
> `seaslog.trace_performance = 1` 开启性能追踪功能。性能日志如:
```sh
2019-01-30 11:46:53 | INFO | 91390 | 5c518ea46e010 | 1548848813.299 | {"main()":{"wt":8848,"mu":20712},"1":[{"cm":"Class0::Method0","ct":2,"wt":2007,"mu":192},{"cm":"Class1::Method1","ct":1,"wt":1002,"mu":192},{"cm":"Class2::Method2","ct":1,"wt":1001,"mu":192},{"cm":"Class3::Method3","ct":1,"wt":1000,"mu":192},{"cm":"Class4::Method4","ct":1,"wt":1000,"mu":192}],"2":[{"cm":"Class5::Method5","ct":1,"wt":1000,"mu":192}],"3":[{"cm":"Class5::Recursion","ct":1,"wt":1000,"mu":3248}],"4":[{"cm":"Class5::Recursion","ct":1,"wt":1000,"mu":2952}],"5":[{"cm":"Class5::Recursion","ct":1,"wt":1000,"mu":2656}]}
cm => function_name (类名::方法名)
wt => wall_time (ms)
mu => memory_usage (byte)
ct => call_times (方法调用计数)
```
### 自定义日志模板
很多朋友在使用过程中提到自定义日志模板的需求,于是`SeasLog`自1.7.2版本开始,拥有了这个能力,允许用户自定义日志的模板,
同时在模板中可以使用`SeasLog`预置的诸多预设变量,参照[预设变量表](#预设变量表)。
Expand All @@ -257,7 +290,7 @@ seaslog.ignore_warning = 1
* `%F` - FileName:LineNo 文件名:行号,如`UserService.php:118`
* `%U` - MemoryUsage 当前内容使用量,单位byte。调用`zend_memory_usage`
* `%u` - PeakMemoryUsage 当前内容使用峰值量,单位byte。调用`zend_memory_peak_usage`
* `%C` - `TODO` Class::Action 类名::方法名,如`UserService::getUserInfo`
* `%C` - Class::Action 类名::方法名,如`UserService::getUserInfo`不在类中使用时,记录函数名
## 使用
Expand Down
25 changes: 23 additions & 2 deletions Specification/SeasLog_PHP_Re_Result.md
Expand Up @@ -3,7 +3,7 @@
```php
/path/to/php --re seaslog

Extension [ <persistent> extension #44 SeasLog version 1.9.0 ] {
Extension [ <persistent> extension #44 SeasLog version 2.0.2 ] {

- Dependencies {
}
Expand Down Expand Up @@ -81,10 +81,31 @@ Extension [ <persistent> extension #44 SeasLog version 1.9.0 ] {
Entry [ seaslog.ignore_warning <ALL> ]
Current = '1'
}
Entry [ seaslog.trace_performance <SYSTEM> ]
Current = '1'
}
Entry [ seaslog.trace_performance_sample_rate <ALL> ]
Current = '10'
}
Entry [ seaslog.trace_performance_start_depth <ALL> ]
Current = '1'
}
Entry [ seaslog.trace_performance_max_depth <ALL> ]
Current = '5'
}
Entry [ seaslog.trace_performance_max_functions_per_depth <ALL> ]
Current = '5'
}
Entry [ seaslog.trace_performance_min_wall_time <ALL> ]
Current = '1000'
}
Entry [ seaslog.trace_performance_min_function_wall_time <ALL> ]
Current = '10'
}
}

- Constants [22] {
Constant [ string SEASLOG_VERSION ] { 1.9.0 }
Constant [ string SEASLOG_VERSION ] { 2.0.2 }
Constant [ string SEASLOG_AUTHOR ] { Chitao.Gao [ neeke@php.net ] }
Constant [ string SEASLOG_ALL ] { ALL }
Constant [ string SEASLOG_DEBUG ] { DEBUG }
Expand Down
1 change: 1 addition & 0 deletions _config.yml
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
2 changes: 2 additions & 0 deletions include/Common.h
Expand Up @@ -19,6 +19,8 @@

#include "php_seaslog.h"

int seaslog_smart_str_get_len(smart_str str);

int check_sapi_is_cli(TSRMLS_D);
int check_log_level(int level TSRMLS_DC);
int seaslog_get_level_int(char *level);
Expand Down
24 changes: 24 additions & 0 deletions include/Performance.h
Expand Up @@ -22,5 +22,29 @@
void seaslog_memory_usage(smart_str *buf TSRMLS_DC);
void seaslog_peak_memory_usage(smart_str *buf TSRMLS_DC);

void initZendHooks(TSRMLS_D);
void recoveryZendHooks(TSRMLS_D);

static inline int seaslog_process_performance_sample(TSRMLS_D);
static inline int seaslog_check_performance_sample(TSRMLS_D);
void seaslog_rinit_performance(TSRMLS_D);
void seaslog_clear_performance(zend_class_entry *ce TSRMLS_DC);
int seaslog_check_performance_active(TSRMLS_D);

int performance_frame_begin(zend_execute_data *execute_data TSRMLS_DC);
void performance_frame_end(TSRMLS_D);

seaslog_frame* seaslog_performance_fast_alloc_frame(TSRMLS_D);
void seaslog_performance_fast_free_frame(seaslog_frame *p TSRMLS_DC);
void seaslog_performance_free_the_free_list(TSRMLS_D);

static inline void seaslog_performance_bucket_process(seaslog_frame* current_frame TSRMLS_DC);
void seaslog_performance_bucket_free(seaslog_performance_bucket *bucket TSRMLS_DC);

char* seaslog_performance_get_class_name(zend_execute_data *data TSRMLS_DC);
char* seaslog_performance_get_function_name(zend_execute_data *data TSRMLS_DC);

int process_seaslog_performance_log(zend_class_entry *ce TSRMLS_DC);
int process_seaslog_performance_clear(TSRMLS_D);
#endif /* _SEASLOG_PERFORMANCE_H_ */

75 changes: 56 additions & 19 deletions include/SeasLog.h
Expand Up @@ -39,8 +39,8 @@

#define SEASLOG_RES_NAME "SeasLog"
#define SEASLOG_AUTHOR "Chitao.Gao [ neeke@php.net ]"
#define SEASLOG_VERSION "1.9.1"
#define SEASLOG_VERSION_ID 10901
#define SEASLOG_VERSION "2.0.2"
#define SEASLOG_VERSION_ID 20002
#define SEASLOG_SUPPORTS "https://github.com/SeasX/SeasLog"

#define SEASLOG_ALL "ALL"
Expand Down Expand Up @@ -142,25 +142,15 @@

#define SEASLOG_GLOBAL_VARS_SERVER TRACK_VARS_SERVER

#ifndef PHP_STREAM_URL_STAT_NOCACHE
#define PHP_STREAM_URL_STAT_NOCACHE 4
#endif

#if PHP_VERSION_ID >= 70000
#define SEASLOG_PERFORMANCE_LOGGER "performance"
#define SEASLOG_PERFORMANCE_ROOT_SYMBOL "main()"
#define SEASLOG_PERFORMANCE_COUNTER_SIZE 1024
#define SEASLOG_PERFORMANCE_BUCKET_SLOTS 8192

#define EX_ARRAY_DESTROY(arr) \
do { \
zval_ptr_dtor(arr); \
ZVAL_NULL(arr); \
} while(0)

#else

#define EX_ARRAY_DESTROY(arr) \
do { \
zval_ptr_dtor(arr);\
} while(0)
#define SEASLOG_CONTINUE 3

#ifndef PHP_STREAM_URL_STAT_NOCACHE
#define PHP_STREAM_URL_STAT_NOCACHE 4
#endif

typedef struct _logger_entry_t
Expand Down Expand Up @@ -210,5 +200,52 @@ typedef struct _request_variable_t
int request_method_len;
} request_variable_t;

typedef struct seaslog_performance_main_t
{
long wt_start;
long mu_start;
long wall_time;
long memory;
} seaslog_performance_main;

typedef struct seaslog_frame
{
char *function_name;
char *class_name;
int recurse_level;
long stack_level;
zend_ulong hash_code;
long wt_start;
long int mu_start;
struct seaslog_frame *previous_frame;
} seaslog_frame;

typedef struct seaslog_performance_bucket_t
{
zend_ulong bucket_key;
zend_ulong hash_code;
char *function_name;
char *class_name;
long stack_level;
long count;
long wall_time;
long memory;

struct seaslog_performance_bucket_t *next;
} seaslog_performance_bucket;

typedef struct seaslog_performance_result_t
{
zend_ulong hash_code;
char *function;
long count;
long wall_time;
long memory;
} seaslog_performance_result;

#define SEASLOG_LOGO_DATA "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAClCAMAAAAu7EIoAAAAG1BMVEVHcEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABp4cHsAAAACXRSTlMA/+XLIkSuaoqRdtD3AAAF7klEQVR42u2dbXvzLAiGW0Dw///i5362dUsaMZh6kXTH7Le8NAE9UcTg7XYzpUa5+7+nsjr5VVRu4WJMxNY6I1VZq7RPMd25lsUhvUNKCYpRvhRD2xvs668aQj5O3fX7UL3fz5TE/Bt+3qw+37VQPj+OEUoQisghyzvWbaj4Slkpv6IFWdS6X8i/ge8NtW9E/FGYwgS5264c6tfhqq5WlSXUbMOCE4QkDsjmdYsLnDp3FZwkPABIWJDq3lVxktSuINyT2xOkdLQFxKRng2vfOlCTHqEeiTjL1bHB2yYtLkDmK526jTXBBsvupXqPdN+2ox24DeZ9y1A3pJVd6YHASwyQ1nVFmVhLBxDa6ZrgNrgc6D1bLyk7gwW4DaZOExGrJrFatBB8QBvcsT3yeY4lUIsaNIcwG2x+EzFX21tAONpBoWxwB5DO2J2DZgQKvAUBEb8i64h5oBQb3AGE3TctQ+M4ybDB5huD6r5qHBDvIdNtsPhNxHydaxwQNPBld8wrfuMZAsSzDZNtMAcBWTa5MUDQwGu7sRdX63QUEHS/aK32Y4HOhUcBQQMv2xrXgHtSj85iVqgN1iAg9BIgYODrs+rLvtaPAeLdO9MGWwogYOBpBaH5mnsdEDDw+u1yLEMoEEDAwH/WghTpPmwGIGjgI56fDwjJqCAw4Hn/SbMAAQNfw/77y4CAgS/BCa4JgGA9X8oDBAy89p4xFxAw8OZXyGxAwMDLbvhJKDyvfybw7HFo+539tYCv7f9HAAIGvrRemF+brB+LvM6ywdKJpk8GBAu8bqsEBggWeHumpOIAwQIv69c2ICBY4HkZKfxZXrYf7r0c8DWmN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n82Jk+6Km6vzH5bicyaVbjlqp3O2d/aT4YDF/D9vpZPqL4ezW8rsZnlhJjc422ptT89eafkSwHhbA0FbH8fS8jYGfOZqrZP2b/xpA6ELP49holnfTf+8VcfO9b+B3vdXPjYWJ4TAAAAAElFTkSuQmCC"

#define SEASLOG_LOGO_IMG "<a href=\"http://seasx.io\"><img src=\""SEASLOG_LOGO_DATA"\" height=\"20px\" alt=\"SeasLog logo\"></a>\n"

#endif /* _SEASLOG_H_ */

0 comments on commit 3809c86

Please sign in to comment.