File: stats.h

package info (click to toggle)
psyco-doc 1.6-1
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 1,832 kB
  • ctags: 3,236
  • sloc: ansic: 23,895; python: 5,646; perl: 1,309; makefile: 153
file content (74 lines) | stat: -rw-r--r-- 2,214 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 /***************************************************************/
/***     Statistics management and usage about code objects    ***/
 /***************************************************************/

#ifndef _STATS_H
#define _STATS_H

/* NB.: the real-time profilers are in profile.c */

#include "psyco.h"
#include "cstruct.h"
#include "mergepoints.h"
#include "timing.h"
#include "Python/frames.h"
#include <compile.h>
#include <frameobject.h>


#if VERBOSE_STATS
# define stats_printf(args)   debug_printf(1, args)
#else
# define stats_printf(args)   do { } while (0) /* nothing */
#endif


/* extra data attached to code objects */
typedef struct {
  PyCStruct_HEAD             /* cs_key is the code object */
  float st_charge;           /* usage statistics */
  PyObject* st_mergepoints;
  PyObject* st_codebuf;      /* as compiled from PsycoCode_CompileCode() */
  PyObject* st_globals;      /* globals used in st_codebuf */
} PyCodeStats;


/* return the PyCodeStats for 'co' */
EXTERNFN PyCodeStats* PyCodeStats_Get(PyCodeObject* co);
EXTERNFN PyCodeStats* PyCodeStats_MaybeGet(PyCodeObject* co);

/* compute and return a Borrowed reference to st_mergepoints */
PSY_INLINE PyObject* PyCodeStats_MergePoints(PyCodeStats* cs, int module) {
	PyObject* mp = cs->st_mergepoints;
	if (mp == NULL) {
		mp = psyco_build_merge_points((PyCodeObject*) cs->cs_key,
					      module);
		cs->st_mergepoints = mp;
	}
	else if (!module && mp != Py_None &&
		 (psyco_mp_flags(mp) & MP_FLAGS_MODULE))
		mp = Py_None;  /* can only run as top-level module code */
	return mp;
}


EXTERNFN void psyco_stats_reset(void);
EXTERNFN void psyco_stats_append(PyThreadState* tstate, PyFrameObject* f);
EXTERNFN void psyco_stats_collect(void);
EXTERNFN PyObject* psyco_stats_top(int n);
 /* set tunable parameters */
EXTERNFN bool psyco_stats_write(PyObject* args, PyObject* kwds);
EXTERNFN PyObject* psyco_stats_read(char* name);
EXTERNFN PyObject* psyco_stats_dump(void);


/* private timing data, based on timing.h */
#if MEASURE_ALL_THREADS
#  define measuring_state(ts)   1
#else
#  define measuring_state(ts)   ((ts) == psyco_main_threadstate)
EXTERNVAR PyThreadState* psyco_main_threadstate;
#endif


#endif /* _STATS_H */