File: timeprof.c

package info (click to toggle)
rscheme 0.7.2-1.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 10,672 kB
  • ctags: 12,430
  • sloc: lisp: 37,104; ansic: 29,763; cpp: 2,630; sh: 1,677; makefile: 568; yacc: 202; lex: 175; perl: 33
file content (104 lines) | stat: -rw-r--r-- 2,262 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*-----------------------------------------------------------------*-C-*---
 * File:    handc/runtime/timeprof.c
 *
 *          Copyright (C)1997 Donovan Kolbly <d.kolbly@rscheme.org>
 *          as part of the RScheme project, licensed for free use.
 *          See <http://www.rscheme.org/> for the latest information.
 *
 * File version:     1.3
 * File mod date:    1997.11.29 23:10:50
 * System build:     v0.7.2, 97.12.21
 *
 *------------------------------------------------------------------------*/

#ifdef TIMEPOINT
#include <time.h>
#include <stdio.h>
#include <rscheme/scheme.h>
#include <rscheme/smemory.h>
#endif
#include <rscheme/timeprof.h>

#ifdef TIMEPOINT

struct timepoint {
  struct timeval t;
  int id;
};

static struct timepoint *timepoints, *time_pt_lim, *time_pt;

void timepoint( int id )
{
  if (time_pt)
    {
      if (time_pt < time_pt_lim)
	{
	  time_pt->id = id;
	  gettimeofday( &time_pt->t, NULL );
	  time_pt++;
	}
      else
	time_pt = NULL;
    }
}

void start_timepoints( unsigned cap )
{
  timepoints = malloc( sizeof( struct timepoint ) * cap );
  time_pt_lim = timepoints + cap;
  time_pt = timepoints;
}


void flush_timepoints( const char *file )
{
  struct timepoint *p;
  extern unsigned insn_count;
  FILE *out = fopen( file, "w" );
  if (!out)
    {
      perror( file );
      return;
    }
  
  for (p=timepoints; p<time_pt; p++)
    {
      if (p->id < 0)
	fprintf( out, "--------- " );
      else
	fprintf( out, "%9d ", p->id );
      fprintf( out, "%9u.%06u", p->t.tv_sec, p->t.tv_usec );
      if (p+1 < time_pt)
	{
	  fprintf( out," (delta %6u us)", 
		  (p[1].t.tv_sec - p[0].t.tv_sec) * 1000000 
		  + (p[1].t.tv_usec - p[0].t.tv_usec));
	}
      if (p->id < 0)
	{
	  obj lit = OBJ(p->id - 0x80000000);
	  if (OBJ_ISA_PTR(lit))
	    fprintf( out, " [%s]", procedure_name(lit) ); 
	  else
	    fprintf( out, " <%08x>", lit );
	}
      fprintf( out, "\n" );
    }
  fprintf( out, "%u instructions (monotones)\n", insn_count );
  fprintf( out, "total time = %u us\n",
	  (time_pt[-1].t.tv_sec - timepoints[0].t.tv_sec) * 1000000
	  + (time_pt[-1].t.tv_usec - timepoints[0].t.tv_usec) );
  fclose(out);
}
#else

void start_timepoints( unsigned cap )
{
}

void flush_timepoints( const char *file )
{
}

#endif