From 4967bea22079e8c1ce1abd5ee62fadb4df21215a Mon Sep 17 00:00:00 2001 From: Dave Wetzel Date: Mon, 28 Oct 2002 19:57:10 +0000 Subject: [PATCH] o a start to make statistics work git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@14860 72102866-910b-0410-8b05-ffd578937521 --- GSWeb.framework/GSWApplication.m | 11 ++ GSWeb.framework/GSWComponentRequestHandler.m | 12 +- GSWeb.framework/GSWSession.m | 3 +- GSWeb.framework/GSWStatisticsStore.h | 1 + GSWeb.framework/GSWStatisticsStore.m | 112 ++++++++++++++++++- 5 files changed, 128 insertions(+), 11 deletions(-) diff --git a/GSWeb.framework/GSWApplication.m b/GSWeb.framework/GSWApplication.m index fc6b24d..ea6f0aa 100644 --- a/GSWeb.framework/GSWApplication.m +++ b/GSWeb.framework/GSWApplication.m @@ -1988,6 +1988,7 @@ selfLockn, LOGObjectFnStart(); session=[self _createSessionForRequest:aRequest]; NSDebugMLLog(@"sessions",@"session:%@",session); + [_statisticsStore _applicationCreatedSession:session]; LOGObjectFnStop(); return session; }; @@ -2512,6 +2513,9 @@ selfLockn, //OK GSWResponse* response=nil; GSWRequestHandler* requestHandler=nil; + NSDate* reqStartDate=nil; + NSTimeInterval timeInterval = 0.0; + LOGObjectFnStart(); #ifndef NDEBUG [self lock]; @@ -2519,6 +2523,8 @@ selfLockn, [self unlock]; #endif + reqStartDate = [NSDate date]; + response = [self checkAppIfRefused:aRequest]; if (!response) { @@ -2539,6 +2545,11 @@ selfLockn, response=[requestHandler handleRequest:aRequest]; NSDebugMLLog(@"requests",@"sessionStore=%@",_sessionStore); [self _resetCache]; + timeInterval=[reqStartDate timeIntervalSinceNow]; + // negate to make positive + timeInterval = timeInterval*-1.0; + [_statisticsStore _applicationDidHandleComponentActionRequestInTimeInterval:timeInterval]; + NSDebugMLLog(@"requests",@"sessionStore=%@",_sessionStore); }; if (!response) diff --git a/GSWeb.framework/GSWComponentRequestHandler.m b/GSWeb.framework/GSWComponentRequestHandler.m index a148c8b..b0cadf3 100644 --- a/GSWeb.framework/GSWComponentRequestHandler.m +++ b/GSWeb.framework/GSWComponentRequestHandler.m @@ -60,7 +60,7 @@ static char rcsId[] = "$Id$"; -(GSWResponse*)lockedHandleRequest:(GSWRequest*)aRequest { //OK - GSWStatisticsStore* statisticsStore=nil; + //GSWStatisticsStore* statisticsStore=nil; GSWApplication* application=[GSWApplication application]; GSWContext* aContext=nil; GSWResponse* response=nil; @@ -92,9 +92,9 @@ static char rcsId[] = "$Id$"; if (!exceptionRaised) { NSDebugMLLog(@"requests",@"requestHandlerValues=%@",requestHandlerValues); - statisticsStore=[[GSWApplication application]statisticsStore]; - NSDebugMLLog(@"requests",@"statisticsStore=%@",statisticsStore); - [statisticsStore _applicationWillHandleComponentActionRequest]; + //statisticsStore=[[GSWApplication application]statisticsStore]; +// NSDebugMLLog(@"requests",@"statisticsStore=%@",statisticsStore); + //[statisticsStore _applicationWillHandleComponentActionRequest]; aContext=[GSWContext contextWithRequest:aRequest]; NSDebugMLLog(@"aContext",@"aContext=%@",aContext); senderID=[requestHandlerValues objectForKey:GSWKey_ElementID[GSWebNamingConv]]; @@ -154,8 +154,8 @@ static char rcsId[] = "$Id$"; }; [application _setContext:nil]; - statisticsStore=[[GSWApplication application] statisticsStore]; - [statisticsStore _applicationDidHandleComponentActionRequest]; + //statisticsStore=[[GSWApplication application] statisticsStore]; + //[statisticsStore _applicationDidHandleComponentActionRequest]; NSDebugMLLog(@"requests",@"response=%@",response); LOGObjectFnStop(); return response; diff --git a/GSWeb.framework/GSWSession.m b/GSWeb.framework/GSWSession.m index dda44e1..2400df9 100644 --- a/GSWeb.framework/GSWSession.m +++ b/GSWeb.framework/GSWSession.m @@ -287,7 +287,7 @@ static char rcsId[] = "$Id$"; GSWApplication* application=nil; GSWStatisticsStore* statisticsStore=nil; LOGObjectFnStart(); - statisticsStore=[[GSWApplication application]statisticsStore]; + statisticsStore=[GSWApp statisticsStore]; [statisticsStore _applicationCreatedSession:self]; ASSIGNCOPY(_sessionID,aSessionID); @@ -343,6 +343,7 @@ static char rcsId[] = "$Id$"; //call GSWApp _discountTerminatedSession //call GSWApp statisticsStore //call statstore _sessionTerminating:self + [[GSWApp statisticsStore] _sessionTerminating:self]; LOGObjectFnStop(); }; // componentDefinition _notifyObserversForDyingComponent:Main component diff --git a/GSWeb.framework/GSWStatisticsStore.h b/GSWeb.framework/GSWStatisticsStore.h index 7460ca3..e57db7a 100644 --- a/GSWeb.framework/GSWStatisticsStore.h +++ b/GSWeb.framework/GSWStatisticsStore.h @@ -97,6 +97,7 @@ -(void)_sessionTerminating:(id)session; -(void)_applicationCreatedSession:(GSWSession*)session; -(void)_applicationDidHandleComponentActionRequest; +-(void)_applicationDidHandleComponentActionRequestInTimeInterval:(double)timeInterval; -(void)_applicationDidHandleDirectActionRequestWithActionNamed:(id)name; -(double)_applicationDidHandleRequest; -(void)_applicationWillHandleDirectActionRequest; diff --git a/GSWeb.framework/GSWStatisticsStore.m b/GSWeb.framework/GSWStatisticsStore.m index ffb3f30..ed5081c 100644 --- a/GSWeb.framework/GSWStatisticsStore.m +++ b/GSWeb.framework/GSWStatisticsStore.m @@ -102,10 +102,81 @@ static char rcsId[] = "$Id$"; }; //-------------------------------------------------------------------- +/* + should return this: + + 2002-10-26 13:50:19.825 foobarWO[3207] stats={count = 5, capacity = 6, pairs = ( + 0 : Pages = {count = 1, capacity = 3, pairs = ( + 1 : Main = {count = 4, capacity = 6, pairs = ( + 1 : Min Resp. Time = 0.06496943533420562432 + 2 : Max Resp. Time = 0.4728142097592352768 + 3 : Avg Resp. Time = 0.2195588141679763968 + 7 : Served = 5 + )} + )} + 3 : StartedAt = 2002-10-26 13:49:05 +0200 + 5 : Transactions = {count = 11, capacity = 11, pairs = ( + 0 : Component Action Transactions = 6 + 2 : Transaction Rate = 0 + 4 : Direct Action Avg. Transaction Time = 0 + 5 : Transactions = 6 + 7 : Avg. Idle Time = 12.154283278932174848 + 9 : Moving Avg. Idle Time = 12.154283278932174848 + 10 : Direct Action Transactions = 0 + 11 : Component Action Avg. Transaction Time = 0.2195588141679763456 + 12 : Moving Avg. Transaction Time = 0.2195588141679763456 + 13 : Avg. Transaction Time = 0.2195588141679763456 + 15 : Sample Size For Moving Avg. = 100 + )} + 6 : Sessions = {count = 11, capacity = 11, pairs = ( + 0 : Peak Active Sessions Date = 2002-10-26 13:50:17 +0200 + 1 : Current Active Sessions = 2 + 4 : Peak Active Sessions = 2 + 6 : Avg. Memory Per Session = {count = 2, capacity = 3, pairs = ( + 2 : Virtual = 1388544 + 3 : Resident Set Size = 264192 + )} + 9 : Moving Avg. Transactions Per Session = 0 + 10 : Sample Size For Moving Avg. = 10 + 11 : Moving Avg. Session Life = 0 + 12 : Session Rate = 0 + 13 : Avg. Transactions Per Session = 0 + 14 : Avg. Session Life = 0 + 15 : Total Sessions Created = 2 + )} + 7 : Memory = {count = 2, capacity = 3, pairs = ( + 2 : Virtual = 541458432 + 3 : Resident Set Size = 1622016 + )} + )} + */ + -(id)statistics { - LOGObjectFnNotImplemented(); //TODOFN - return nil; + NSMutableDictionary *statDict = [NSMutableDictionary dictionary]; + NSMutableDictionary *sessionsDict = [NSMutableDictionary dictionary]; + + [statDict setObject:_startDate + forKey:@"StartedAt"]; + + // Sessions + + [sessionsDict setObject:[NSString stringWithFormat:@"%d",_sessionsCount] + forKey:@"Current Active Sessions"]; + + + [statDict setObject:sessionsDict + forKey:@"Sessions"]; + + // Pages + if (_pagesStatistics) { + [statDict setObject:_pagesStatistics + forKey:@"Pages"]; + } + + +// LOGObjectFnNotImplemented(); //TODOFN + return statDict; }; //-------------------------------------------------------------------- @@ -244,7 +315,7 @@ static char rcsId[] = "$Id$"; } else AvgRespTimeValue=aTimeInterval; - Served++; + ServedValue++; } else { @@ -366,9 +437,42 @@ static char rcsId[] = "$Id$"; { timeInterval=[self _applicationDidHandleRequest]; NSDebugMLog(@"currentPage=%@",_currentPage); - if (_currentPage)//TODO no current page if no session (error page,...) + if (_currentPage) { //TODO no current page if no session (error page,...) + NSLog(@"GSWStatisticsStore timeInterval=%f",timeInterval); [self _updatePagesStatisticsForPage:_currentPage timeInterval:timeInterval]; + } + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]", + localException,[localException reason], + __FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_applicationDidHandleComponentActionRequestInTimeInterval:(double)timeInterval +{ + //OK +// double timeInterval=0; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + // timeInterval=[self _applicationDidHandleRequest]; + NSDebugMLog(@"currentPage=%@",_currentPage); + if (_currentPage) { //TODO no current page if no session (error page,...) + NSLog(@"GSWStatisticsStore timeInterval=%f",timeInterval); + [self _updatePagesStatisticsForPage:_currentPage + timeInterval:timeInterval]; + } } NS_HANDLER {