summaryrefslogtreecommitdiffstats
path: root/js/src/devtools/vprof/testVprofMT.c
blob: 5fb6a80e128527487ef928e4e88779bd794cc536 (plain)
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
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <windows.h>
#include <stdio.h>
#include <time.h>

#include "vprof.h"

static void cProbe(void* vprofID) {
  if (_VAL == _IVAR1) _I64VAR1++;
  _IVAR1 = _IVAR0;

  if (_VAL == _IVAR0) _I64VAR0++;
  _IVAR0 = (int)_VAL;

  _DVAR0 = ((double)_I64VAR0) / _COUNT;
  _DVAR1 = ((double)_I64VAR1) / _COUNT;
}

//__declspec (thread) boolean cv;
//#define if(c) cv = (c); _vprof (cv); if (cv)
//#define if(c) cv = (c); _vprof (cv, cProbe); if (cv)

#define THREADS 1
#define COUNT 100000
#define SLEEPTIME 0

static int64_t evens = 0;
static int64_t odds = 0;

void sub(int val) {
  int i;
  //_vprof (1);
  for (i = 0; i < COUNT; i++) {
    //_nvprof ("Iteration", 1);
    //_nvprof ("Iteration", 1);
    _vprof(i);
    //_vprof (i);
    //_hprof(i, 3, (int64_t) 1000, (int64_t)2000, (int64_t)3000);
    //_hprof(i, 3, 10000, 10001, 3000000);
    //_nhprof("Event", i, 3, 10000, 10001, 3000000);
    //_nhprof("Event", i, 3, 10000, 10001, 3000000);
    // Sleep(SLEEPTIME);
    if (i % 2 == 0) {
      //_vprof (i);
      ////_hprof(i, 3, 10000, 10001, 3000000);
      //_nvprof ("Iteration", i);
      evens++;
    } else {
      //_vprof (1);
      _vprof(i, cProbe);
      odds++;
    }
    //_nvprof ("Iterate", 1);
  }
  // printf("sub %d done.\n", val);
}

HANDLE array[THREADS];

static int run(void) {
  int i;

  time_t start_time = time(0);

  for (i = 0; i < THREADS; i++) {
    array[i] = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)sub, (LPVOID)i, 0, 0);
  }

  for (i = 0; i < THREADS; i++) {
    WaitForSingleObject(array[i], INFINITE);
  }

  return 0;
}

int main() {
  DWORD start, end;

  start = GetTickCount();
  run();
  end = GetTickCount();

  printf("\nRun took %d msecs\n\n", end - start);
}