~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Paul Hummer
  • Date: 2009-03-30 22:39:07 UTC
  • mfrom: (314.1.9 memory-profiling)
  • Revision ID: paul@canonical.com-20090330223907-66ndm7vo0dg43if3
Added MemoryProfileMiddleware

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from optparse import OptionParser
23
23
 
 
24
from bzrlib.plugin import load_plugins
 
25
 
24
26
from paste import httpserver
25
27
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
26
28
from paste.translogger import TransLogger
48
50
                            "(defaults to 8080)."))
49
51
    parser.add_option("--host", dest="user_host",
50
52
                      help="Host Loggerhead should listen on.")
 
53
    parser.add_option('--memory-profile', action='store_true',
 
54
                      dest='memory_profile',
 
55
                      help='Profile the memory usage using heapy.')
51
56
    parser.add_option("--prefix", dest="user_prefix",
52
57
                      help="Specify host prefix.")
53
58
    parser.add_option("--profile", action="store_true", dest="profile",
115
120
    logfile.setFormatter(formatter)
116
121
    logfile.setLevel(logging.DEBUG)
117
122
    logger.addHandler(logfile)
 
123
 
 
124
    memprofile = logging.getLogger('loggerhead-memprofile')
 
125
    memprofile.setLevel(logging.DEBUG)
 
126
    memprofile.addHandler(logging.FileHandler('loggerhead-memprofile'))
 
127
 
118
128
    # setup_logging() #end
 
129
 
119
130
    app = TransLogger(app, logger=logger)
120
131
    if options.profile:
121
132
        from loggerhead.middleware.profile import LSProfMiddleware
122
133
        app = LSProfMiddleware(app)
 
134
    if options.memory_profile:
 
135
        from loggerhead.middleware.profile import MemoryProfileMiddleware
 
136
        app = MemoryProfileMiddleware(app)
123
137
 
124
138
    if not options.user_prefix:
125
139
        prefix = '/'
126
140
    else:
127
141
        prefix = options.user_prefix
 
142
        if not prefix.startswith('/'):
 
143
            prefix = '/' + prefix
128
144
 
129
145
    try:
130
146
        from paste.deploy.config import PrefixMiddleware
144
160
    else:
145
161
        app = PrefixMiddleware(app, prefix=prefix)
146
162
 
 
163
    app = HTTPExceptionHandler(app)
147
164
    app = ErrorHandlerApp(app)
148
 
    app = HTTPExceptionHandler(app)
149
165
 
150
166
    if not options.user_port:
151
167
        port = '8080'
157
173
    else:
158
174
        host = options.user_host
159
175
 
 
176
    load_plugins()
 
177
 
160
178
    httpserver.serve(app, host=host, port=port)
161
179
 
162
180