Commit 9c8ed4999740e921ecc2966bbcd0dbcfc725f59a

Russell Belfer 2014-04-29T15:05:58

Remove trace / add git_diff_perfdata struct + api

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
diff --git a/include/git2/diff.h b/include/git2/diff.h
index 1888088..b849e3b 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -391,14 +391,13 @@ typedef struct {
 * Initializes a `git_diff_options` with default values. Equivalent to
 * creating an instance with GIT_DIFF_OPTIONS_INIT.
 *
-* @param opts the `git_diff_options` instance to initialize.
-* @param version the version of the struct; you should pass
-* `GIT_DIFF_OPTIONS_VERSION` here.
+* @param opts The `git_diff_options` instance to initialize.
+* @param version Version of struct; pass `GIT_DIFF_OPTIONS_VERSION`
 * @return Zero on success; -1 on failure.
 */
 GIT_EXTERN(int) git_diff_init_options(
-	git_diff_options* opts,
-	int version);
+	git_diff_options *opts,
+	unsigned int version);
 
 /**
  * When iterating over a diff, callback that will be made per file.
@@ -632,14 +631,13 @@ typedef struct {
 * Initializes a `git_diff_find_options` with default values. Equivalent to
 * creating an instance with GIT_DIFF_FIND_OPTIONS_INIT.
 *
-* @param opts the `git_diff_find_options` instance to initialize.
-* @param version the version of the struct; you should pass
-* `GIT_DIFF_FIND_OPTIONS_VERSION` here.
+* @param opts The `git_diff_find_options` instance to initialize.
+* @param version Version of struct; pass `GIT_DIFF_FIND_OPTIONS_VERSION`
 * @return Zero on success; -1 on failure.
 */
 GIT_EXTERN(int) git_diff_find_init_options(
-	git_diff_find_options* opts,
-	int version);
+	git_diff_find_options *opts,
+	unsigned int version);
 
 /** @name Diff Generator Functions
  *
@@ -1223,17 +1221,17 @@ GIT_EXTERN(int) git_diff_commit_as_email(
 	const git_diff_options *diff_opts);
 
 /**
-* Initializes a `git_diff_format_email_options` with default values. Equivalent to
-* creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT.
+* Initializes a `git_diff_format_email_options` with default values.
 *
-* @param opts the `git_diff_format_email_options` instance to initialize.
-* @param version the version of the struct; you should pass
-* `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION` here.
+* Equivalent to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT.
+*
+* @param opts Uhe `git_diff_format_email_options` instance to initialize.
+* @param version Version of struct; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION`
 * @return Zero on success; -1 on failure.
 */
 GIT_EXTERN(int) git_diff_format_email_init_options(
 	git_diff_format_email_options *opts,
-	int version);
+	unsigned int version);
 
 GIT_END_DECL
 
diff --git a/include/git2/status.h b/include/git2/status.h
index ee2f332..effe5e1 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -184,14 +184,13 @@ typedef struct {
  * Initializes a `git_status_options` with default values. Equivalent to
  * creating an instance with GIT_STATUS_OPTIONS_INIT.
  *
- * @param opts the `git_status_options` instance to initialize.
- * @param version the version of the struct; you should pass
- *        `GIT_STATUS_OPTIONS_VERSION` here.
+ * @param opts The `git_status_options` instance to initialize.
+ * @param version Version of struct; pass `GIT_STATUS_OPTIONS_VERSION`
  * @return Zero on success; -1 on failure.
  */
 GIT_EXTERN(int) git_status_init_options(
-	git_status_options* opts,
-	int version);
+	git_status_options *opts,
+	unsigned int version);
 
 /**
  * A status entry, providing the differences between the file as it exists
diff --git a/include/git2/sys/diff.h b/include/git2/sys/diff.h
index bc6cdf3..48d72f4 100644
--- a/include/git2/sys/diff.h
+++ b/include/git2/sys/diff.h
@@ -10,6 +10,8 @@
 #include "git2/common.h"
 #include "git2/types.h"
 #include "git2/oid.h"
+#include "git2/diff.h"
+#include "git2/status.h"
 
 /**
  * @file git2/sys/diff.h
@@ -58,6 +60,32 @@ GIT_EXTERN(int) git_diff_print_callback__to_file_handle(
 	const git_diff_line *line,
 	void *payload); /*< payload must be a `FILE *` */
 
+
+typedef struct {
+	unsigned int version;
+	size_t stat_calls;
+	size_t oid_calculations;
+} git_diff_perfdata;
+
+#define GIT_DIFF_PERFDATA_VERSION 1
+#define GIT_DIFF_PERFDATA_INIT {GIT_DIFF_PERFDATA_VERSION,0,0}
+
+/**
+ * Get performance data for a diff object.
+ *
+ * @param out Structure to be filled with diff performance data
+ * @param diff Diff to read performance data from
+ * @return 0 for success, <0 for error
+ */
+GIT_EXTERN(int) git_diff_get_perfdata(
+	git_diff_perfdata *out, const git_diff *diff);
+
+/**
+ * Get performance data for diffs from a git_status_list
+ */
+GIT_EXTERN(int) git_status_list_get_perfdata(
+	git_diff_perfdata *out, const git_status_list *status);
+
 /** @} */
 GIT_END_DECL
 #endif
diff --git a/include/git2/trace.h b/include/git2/trace.h
index 867b346..f9b4d6f 100644
--- a/include/git2/trace.h
+++ b/include/git2/trace.h
@@ -20,64 +20,47 @@
 GIT_BEGIN_DECL
 
 /**
- * Available tracing messages.  Each tracing level can be enabled
- * independently or pass GIT_TRACE_ALL to enable all levels.
+ * Available tracing levels.  When tracing is set to a particular level,
+ * callers will be provided tracing at the given level and all lower levels.
  */
 typedef enum {
 	/** No tracing will be performed. */
-	GIT_TRACE_NONE = 0x0000u,
-
-	/** All tracing messages will be sent. */
-	GIT_TRACE_ALL = 0xFFFFu,
+	GIT_TRACE_NONE = 0,
 
 	/** Severe errors that may impact the program's execution */
-	GIT_TRACE_FATAL = 0x0001u,
+	GIT_TRACE_FATAL = 1,
 
 	/** Errors that do not impact the program's execution */
-	GIT_TRACE_ERROR = 0x0002u,
-	GIT_TRACE_ERROR_AND_BELOW = 0x0003u,
+	GIT_TRACE_ERROR = 2,
 
 	/** Warnings that suggest abnormal data */
-	GIT_TRACE_WARN = 0x0004u,
-	GIT_TRACE_WARN_AND_BELOW = 0x0007u,
+	GIT_TRACE_WARN = 3,
 
 	/** Informational messages about program execution */
-	GIT_TRACE_INFO = 0x0008u,
-	GIT_TRACE_INFO_AND_BELOW = 0x000Fu,
+	GIT_TRACE_INFO = 4,
 
 	/** Detailed data that allows for debugging */
-	GIT_TRACE_DEBUG = 0x0010u,
+	GIT_TRACE_DEBUG = 5,
 
 	/** Exceptionally detailed debugging data */
-	GIT_TRACE_TRACE = 0x0020u,
-
-	/** Performance tracking related traces */
-	GIT_TRACE_PERF = 0x0040u,
+	GIT_TRACE_TRACE = 6
 } git_trace_level_t;
 
 /**
  * An instance for a tracing function
  */
-typedef void (*git_trace_callback)(
-	git_trace_level_t level, /* just one bit will be sent */
-	void *cb_payload,
-	void *msg_payload,
-	const char *msg);
+typedef void (*git_trace_callback)(git_trace_level_t level, const char *msg);
 
 /**
  * Sets the system tracing configuration to the specified level with the
  * specified callback.  When system events occur at a level equal to, or
  * lower than, the given level they will be reported to the given callback.
  *
- * @param level Bitmask of all enabled trace levels
- * @param cb Function to call with trace messages
- * @param cb_payload Payload to pass when callback is invoked
+ * @param level Level to set tracing to
+ * @param cb Function to call with trace data
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_trace_set(
-	git_trace_level_t level,
-	git_trace_callback cb,
-	void *cb_payload);
+GIT_EXTERN(int) git_trace_set(git_trace_level_t level, git_trace_callback cb);
 
 /** @} */
 GIT_END_DECL
diff --git a/src/diff.c b/src/diff.c
index b34d153..26e671d 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -14,7 +14,6 @@
 #include "index.h"
 #include "odb.h"
 #include "submodule.h"
-#include "trace.h"
 
 #define DIFF_FLAG_IS_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) != 0)
 #define DIFF_FLAG_ISNT_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) == 0)
@@ -555,7 +554,8 @@ int git_diff__oid_for_entry(
 	if (!entry.mode) {
 		struct stat st;
 
-		git_trace(GIT_TRACE_PERF, NULL, "stat");
+		diff->perf.stat_calls++;
+
 		if (p_stat(full_path.ptr, &st) < 0) {
 			error = git_path_set_error(errno, entry.path, "stat");
 			git_buf_free(&full_path);
@@ -570,7 +570,6 @@ int git_diff__oid_for_entry(
 	if (S_ISGITLINK(entry.mode)) {
 		git_submodule *sm;
 
-		git_trace(GIT_TRACE_PERF, NULL, "submodule_lookup");
 		if (!git_submodule_lookup(&sm, diff->repo, entry.path)) {
 			const git_oid *sm_oid = git_submodule_wd_id(sm);
 			if (sm_oid)
@@ -583,8 +582,8 @@ int git_diff__oid_for_entry(
 			giterr_clear();
 		}
 	} else if (S_ISLNK(entry.mode)) {
-		git_trace(GIT_TRACE_PERF, NULL, "oid_calculation");
 		error = git_odb__hashlink(out, full_path.ptr);
+		diff->perf.oid_calculations++;
 	} else if (!git__is_sizet(entry.file_size)) {
 		giterr_set(GITERR_OS, "File size overflow (for 32-bits) on '%s'",
 			entry.path);
@@ -596,10 +595,10 @@ int git_diff__oid_for_entry(
 		if (fd < 0)
 			error = fd;
 		else {
-			git_trace(GIT_TRACE_PERF, NULL, "oid_calculation");
 			error = git_odb__hashfd_filtered(
 				out, fd, (size_t)entry.file_size, GIT_OBJ_BLOB, fl);
 			p_close(fd);
+			diff->perf.oid_calculations++;
 		}
 
 		git_filter_list_free(fl);
@@ -655,8 +654,6 @@ static int maybe_modified_submodule(
 		ign == GIT_SUBMODULE_IGNORE_ALL)
 		return 0;
 
-	git_trace(GIT_TRACE_PERF, NULL, "submodule_lookup");
-
 	if ((error = git_submodule_lookup(
 			&sub, diff->repo, info->nitem->path)) < 0) {
 
@@ -965,8 +962,6 @@ static int handle_unmatched_new_item(
 		delta_type = GIT_DELTA_ADDED;
 
 	else if (nitem->mode == GIT_FILEMODE_COMMIT) {
-		git_trace(GIT_TRACE_PERF, NULL, "submodule_lookup");
-
 		/* ignore things that are not actual submodules */
 		if (git_submodule_lookup(NULL, info->repo, nitem->path) != 0) {
 			giterr_clear();
@@ -1119,6 +1114,8 @@ int git_diff__from_iterators(
 			error = 0;
 	}
 
+	diff->perf.stat_calls += old_iter->stat_calls + new_iter->stat_calls;
+
 cleanup:
 	if (!error)
 		*diff_ptr = diff;
@@ -1313,6 +1310,22 @@ int git_diff_is_sorted_icase(const git_diff *diff)
 	return (diff->opts.flags & GIT_DIFF_IGNORE_CASE) != 0;
 }
 
+static int diff_options_bad_version(int version, const char *thing)
+{
+	giterr_set(GITERR_INVALID, "Invalid version %d for %s", version, thing);
+	return -1;
+}
+
+int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff)
+{
+	if (!out || out->version != GIT_DIFF_PERFDATA_VERSION)
+		return diff_options_bad_version(
+			out ? out->version : 0, "git_diff_perfdata");
+	out->stat_calls = diff->perf.stat_calls;
+	out->oid_calculations = diff->perf.oid_calculations;
+	return 0;
+}
+
 int git_diff__paired_foreach(
 	git_diff *head2idx,
 	git_diff *idx2wd,
@@ -1615,38 +1628,29 @@ int git_diff_commit_as_email(
 	return error;
 }
 
-int git_diff_init_options(git_diff_options* opts, int version)
+int git_diff_init_options(git_diff_options* opts, unsigned int version)
 {
-	if (version != GIT_DIFF_OPTIONS_VERSION) {
-		giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_options", version);
-		return -1;
-	} else {
-		git_diff_options o = GIT_DIFF_OPTIONS_INIT;
-		memcpy(opts, &o, sizeof(o));
-		return 0;
-	}
+	git_diff_options o = GIT_DIFF_OPTIONS_INIT;
+	if (version != o.version)
+		return diff_options_bad_version(version, "git_diff_options");
+	memcpy(opts, &o, sizeof(o));
+	return 0;
 }
 
-int git_diff_find_init_options(git_diff_find_options* opts, int version)
+int git_diff_find_init_options(git_diff_find_options* opts, unsigned int version)
 {
-	if (version != GIT_DIFF_FIND_OPTIONS_VERSION) {
-		giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_find_options", version);
-		return -1;
-	} else {
-		git_diff_find_options o = GIT_DIFF_FIND_OPTIONS_INIT;
-		memcpy(opts, &o, sizeof(o));
-		return 0;
-	}
+	git_diff_find_options o = GIT_DIFF_FIND_OPTIONS_INIT;
+	if (version != o.version)
+		return diff_options_bad_version(version, "git_diff_find_options");
+	memcpy(opts, &o, sizeof(o));
+	return 0;
 }
 
-int git_diff_format_email_init_options(git_diff_format_email_options* opts, int version)
+int git_diff_format_email_init_options(git_diff_format_email_options* opts, unsigned int version)
 {
-	if (version != GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION) {
-		giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_format_email_options", version);
-		return -1;
-	} else {
-		git_diff_format_email_options o = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
-		memcpy(opts, &o, sizeof(o));
-		return 0;
-	}
+	git_diff_format_email_options o = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
+	if (version != o.version)
+		return diff_options_bad_version(version, "git_diff_format_email_options");
+	memcpy(opts, &o, sizeof(o));
+	return 0;
 }
diff --git a/src/diff.h b/src/diff.h
index 2e7ce0b..3305238 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -8,6 +8,7 @@
 #define INCLUDE_diff_h__
 
 #include "git2/diff.h"
+#include "git2/sys/diff.h"
 #include "git2/oid.h"
 
 #include <stdio.h>
@@ -62,6 +63,7 @@ struct git_diff {
 	git_iterator_type_t old_src;
 	git_iterator_type_t new_src;
 	uint32_t diffcaps;
+	git_diff_perfdata perf;
 
 	int (*strcomp)(const char *, const char *);
 	int (*strncomp)(const char *, const char *, size_t);
diff --git a/src/iterator.c b/src/iterator.c
index 0d7e591..4f8087c 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -11,7 +11,6 @@
 #include "ignore.h"
 #include "buffer.h"
 #include "submodule.h"
-#include "trace.h"
 #include <ctype.h>
 
 #define ITERATOR_SET_CB(P,NAME_LC) do { \
@@ -1017,8 +1016,7 @@ static int fs_iterator__expand_dir(fs_iterator *fi)
 		fs_iterator__free_frame(ff);
 		return GIT_ENOTFOUND;
 	}
-
-	git_trace(GIT_TRACE_PERF, &ff->entries.length, "stat");
+	fi->base.stat_calls += ff->entries.length;
 
 	fs_iterator__seek_frame_start(fi, ff);
 
@@ -1310,7 +1308,6 @@ static int workdir_iterator__enter_dir(fs_iterator *fi)
 		if (!S_ISDIR(entry->st.st_mode) || !strcmp(GIT_DIR, entry->path))
 			continue;
 
-		git_trace(GIT_TRACE_PERF, entry->path, "submodule_lookup");
 		if (git_submodule__is_submodule(fi->base.repo, entry->path)) {
 			entry->st.st_mode = GIT_FILEMODE_COMMIT;
 			entry->path_len--;
diff --git a/src/iterator.h b/src/iterator.h
index ba9c1e4..f678302 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -52,6 +52,7 @@ struct git_iterator {
 	char *start;
 	char *end;
 	int (*prefixcomp)(const char *str, const char *prefix);
+	size_t stat_calls;
 	unsigned int flags;
 };
 
diff --git a/src/status.c b/src/status.c
index e418cf7..aab838b 100644
--- a/src/status.c
+++ b/src/status.c
@@ -518,14 +518,38 @@ int git_status_should_ignore(
 	return git_ignore_path_is_ignored(ignored, repo, path);
 }
 
-int git_status_init_options(git_status_options* opts, int version)
+int git_status_init_options(git_status_options* opts, unsigned int version)
 {
-	if (version != GIT_STATUS_OPTIONS_VERSION) {
+	git_status_options o = GIT_STATUS_OPTIONS_INIT;
+	if (version != o.version) {
 		giterr_set(GITERR_INVALID, "Invalid version %d for git_status_options", version);
 		return -1;
-	} else {
-		git_status_options o = GIT_STATUS_OPTIONS_INIT;
-		memcpy(opts, &o, sizeof(o));
-		return 0;
 	}
+	memcpy(opts, &o, sizeof(o));
+	return 0;
+}
+
+int git_status_list_get_perfdata(
+	git_diff_perfdata *out, const git_status_list *status)
+{
+	if (!out || out->version != GIT_DIFF_PERFDATA_VERSION) {
+		giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_perfdata",
+				   out ? out->version : 0);
+		return -1;
+	}
+
+	out->stat_calls = 0;
+	out->oid_calculations = 0;
+
+	if (status->head2idx) {
+		out->stat_calls += status->head2idx->perf.stat_calls;
+		out->oid_calculations += status->head2idx->perf.oid_calculations;
+	}
+	if (status->idx2wd) {
+		out->stat_calls += status->idx2wd->perf.stat_calls;
+		out->oid_calculations += status->idx2wd->perf.oid_calculations;
+	}
+
+	return 0;
 }
+
diff --git a/src/trace.c b/src/trace.c
index 6ee2cf2..ee5039f 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -17,25 +17,22 @@ struct git_trace_data git_trace__data = {0};
 
 #endif
 
-int git_trace_set(
-	git_trace_level_t level, git_trace_callback cb, void *cb_payload)
+int git_trace_set(git_trace_level_t level, git_trace_callback callback)
 {
 #ifdef GIT_TRACE
-	assert(level == 0 || cb != NULL);
+	assert(level == 0 || callback != NULL);
 
 	git_trace__data.level = level;
-	git_trace__data.callback = cb;
-	git_trace__data.callback_payload = cb_payload;
+	git_trace__data.callback = callback;
 	GIT_MEMORY_BARRIER;
 
 	return 0;
 #else
 	GIT_UNUSED(level);
-	GIT_UNUSED(cb);
-	GIT_UNUSED(cb_payload);
+	GIT_UNUSED(callback);
 
-	giterr_set(
-		GITERR_INVALID, "This version of libgit2 was not built with tracing.");
+	giterr_set(GITERR_INVALID,
+		"This version of libgit2 was not built with tracing.");
 	return -1;
 #endif
 }
diff --git a/src/trace.h b/src/trace.h
index b35e380..4d4e3bf 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -15,16 +15,13 @@
 struct git_trace_data {
 	git_trace_level_t level;
 	git_trace_callback callback;
-	void *callback_payload;
 };
 
 extern struct git_trace_data git_trace__data;
 
 GIT_INLINE(void) git_trace__write_fmt(
 	git_trace_level_t level,
-	void *message_payload,
-	const char *fmt,
-	...)
+	const char *fmt, ...)
 {
 	git_trace_callback callback = git_trace__data.callback;
 	git_buf message = GIT_BUF_INIT;
@@ -34,18 +31,18 @@ GIT_INLINE(void) git_trace__write_fmt(
 	git_buf_vprintf(&message, fmt, ap);
 	va_end(ap);
 
-	callback(
-		level, git_trace__data.callback_payload, message_payload,
-		git_buf_cstr(&message));
+	callback(level, git_buf_cstr(&message));
 
 	git_buf_free(&message);
 }
 
 #define git_trace_level()		(git_trace__data.level)
-#define git_trace(l, p, ...)	do { \
-	if ((git_trace__data.level & (l)) != 0 && git_trace__data.callback) { \
-		git_trace__write_fmt((l), (p), __VA_ARGS__); \
-	} } while (0)
+#define git_trace(l, ...)		{ \
+									if (git_trace__data.level >= l && \
+										git_trace__data.callback != NULL) { \
+										git_trace__write_fmt(l, __VA_ARGS__); \
+									} \
+								}
 
 #else
 
diff --git a/tests/diff/diff_helpers.c b/tests/diff/diff_helpers.c
index 5de9834..279cb20 100644
--- a/tests/diff/diff_helpers.c
+++ b/tests/diff/diff_helpers.c
@@ -229,22 +229,3 @@ void diff_print_raw(FILE *fp, git_diff *diff)
 		git_diff_print(diff, GIT_DIFF_FORMAT_RAW,
 			git_diff_print_callback__to_file_handle, fp ? fp : stderr));
 }
-
-void diff_perf_track_stats(
-	git_trace_level_t level,
-	void *cb_payload,
-	void *msg_payload,
-	const char *msg)
-{
-	diff_perf *data = cb_payload;
-
-	if (!(level & GIT_TRACE_PERF))
-		return;
-
-	if (!strcmp("stat", msg))
-		data->stat_calls += msg_payload ? *((size_t *)msg_payload) : 1;
-	else if (!strcmp("submodule_lookup", msg))
-		data->submodule_lookups++;
-	else if (!strcmp("oid_calculation", msg))
-		data->oid_calcs++;
-}
diff --git a/tests/diff/diff_helpers.h b/tests/diff/diff_helpers.h
index 3ed5387..bf21f4b 100644
--- a/tests/diff/diff_helpers.h
+++ b/tests/diff/diff_helpers.h
@@ -62,17 +62,3 @@ extern int diff_foreach_via_iterator(
 
 extern void diff_print(FILE *fp, git_diff *diff);
 extern void diff_print_raw(FILE *fp, git_diff *diff);
-
-#include "git2/trace.h"
-
-typedef struct {
-	size_t stat_calls;
-	size_t oid_calcs;
-	size_t submodule_lookups;
-} diff_perf;
-
-extern void diff_perf_track_stats(
-	git_trace_level_t level,
-	void *cb_payload,
-	void *msg_payload,
-	const char *msg);
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 952c902..a6d48ab 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -1,28 +1,13 @@
 #include "clar_libgit2.h"
 #include "diff_helpers.h"
 #include "repository.h"
+#include "git2/sys/diff.h"
 
 static git_repository *g_repo = NULL;
 
-#ifdef GIT_TRACE
-static diff_perf g_diff_perf;
-#endif
-
-void test_diff_workdir__initialize(void)
-{
-#ifdef GIT_TRACE
-	memset(&g_diff_perf, 0, sizeof(g_diff_perf));
-	cl_git_pass(git_trace_set(
-		GIT_TRACE_PERF, diff_perf_track_stats, &g_diff_perf));
-#endif
-}
-
 void test_diff_workdir__cleanup(void)
 {
 	cl_git_sandbox_cleanup();
-#ifdef GIT_TRACE
-	cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL));
-#endif
 }
 
 void test_diff_workdir__to_index(void)
@@ -70,13 +55,14 @@ void test_diff_workdir__to_index(void)
 		cl_assert_equal_i(5, exp.line_ctxt);
 		cl_assert_equal_i(4, exp.line_adds);
 		cl_assert_equal_i(5, exp.line_dels);
+	}
 
-#ifdef GIT_TRACE
+	{
+		git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
+		cl_git_pass(git_diff_get_perfdata(&perf, diff));
 		cl_assert_equal_sz(
-			13 /* in root */ + 3 /* in subdir */, g_diff_perf.stat_calls);
-		cl_assert_equal_sz(5, g_diff_perf.oid_calcs);
-		cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
-#endif
+			13 /* in root */ + 3 /* in subdir */, perf.stat_calls);
+		cl_assert_equal_sz(5, perf.oid_calculations);
 	}
 
 	git_diff_free(diff);
@@ -1532,10 +1518,6 @@ static void basic_diff_status(git_diff **out, const git_diff_options *opts)
 {
 	diff_expects exp;
 
-#ifdef GIT_TRACE
-	memset(&g_diff_perf, 0, sizeof(g_diff_perf));
-#endif
-
 	cl_git_pass(git_diff_index_to_workdir(out, g_repo, NULL, opts));
 
 	memset(&exp, 0, sizeof(exp));
@@ -1555,6 +1537,7 @@ void test_diff_workdir__can_update_index(void)
 {
 	git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
 	git_diff *diff = NULL;
+	git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
 
 	g_repo = cl_git_sandbox_init("status");
 
@@ -1569,11 +1552,10 @@ void test_diff_workdir__can_update_index(void)
 	opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
 
 	basic_diff_status(&diff, &opts);
-#ifdef GIT_TRACE
-	cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
-	cl_assert_equal_sz(5, g_diff_perf.oid_calcs);
-	cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
-#endif
+
+	cl_git_pass(git_diff_get_perfdata(&perf, diff));
+	cl_assert_equal_sz(13 + 3, perf.stat_calls);
+	cl_assert_equal_sz(5, perf.oid_calculations);
 
 	git_diff_free(diff);
 
@@ -1581,22 +1563,20 @@ void test_diff_workdir__can_update_index(void)
 	opts.flags |= GIT_DIFF_UPDATE_INDEX;
 
 	basic_diff_status(&diff, &opts);
-#ifdef GIT_TRACE
-	cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
-	cl_assert_equal_sz(5, g_diff_perf.oid_calcs);
-	cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
-#endif
+
+	cl_git_pass(git_diff_get_perfdata(&perf, diff));
+	cl_assert_equal_sz(13 + 3, perf.stat_calls);
+	cl_assert_equal_sz(5, perf.oid_calculations);
 
 	git_diff_free(diff);
 
 	/* now if we do it again, we should see fewer OID calculations */
 
 	basic_diff_status(&diff, &opts);
-#ifdef GIT_TRACE
-	cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
-	cl_assert_equal_sz(0, g_diff_perf.oid_calcs); /* Yay */
-	cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
-#endif
+
+	cl_git_pass(git_diff_get_perfdata(&perf, diff));
+	cl_assert_equal_sz(13 + 3, perf.stat_calls);
+	cl_assert_equal_sz(0, perf.oid_calculations);
 
 	git_diff_free(diff);
 }
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 06864ad..ca9068a 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -6,19 +6,7 @@
 #include "util.h"
 #include "path.h"
 #include "../diff/diff_helpers.h"
-
-#ifdef GIT_TRACE
-static diff_perf g_diff_perf;
-#endif
-
-void test_status_worktree__initialize(void)
-{
-#ifdef GIT_TRACE
-	memset(&g_diff_perf, 0, sizeof(g_diff_perf));
-	cl_git_pass(git_trace_set(
-		GIT_TRACE_PERF, diff_perf_track_stats, &g_diff_perf));
-#endif
-}
+#include "git2/sys/diff.h"
 
 /**
  * Cleanup
@@ -29,9 +17,6 @@ void test_status_worktree__initialize(void)
 void test_status_worktree__cleanup(void)
 {
 	cl_git_sandbox_cleanup();
-#ifdef GIT_TRACE
-	cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL));
-#endif
 }
 
 /**
@@ -903,38 +888,50 @@ void test_status_worktree__long_filenames(void)
  * while reducing the amount of work that needs to be done
  */
 
+static void check_status0(git_status_list *status)
+{
+	size_t i, max_i = git_status_list_entrycount(status);
+	cl_assert_equal_sz(entry_count0, max_i);
+	for (i = 0; i < max_i; ++i) {
+		const git_status_entry *entry = git_status_byindex(status, i);
+		cl_assert_equal_i(entry_statuses0[i], entry->status);
+	}
+}
+
 void test_status_worktree__update_stat_cache_0(void)
 {
 	git_repository *repo = cl_git_sandbox_init("status");
+	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+	git_status_list *status;
+	git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
 
-	assert_show(entry_count0, entry_paths0, entry_statuses0,
-		repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
+	opts.flags = GIT_STATUS_OPT_DEFAULTS;
 
-#ifdef GIT_TRACE
-	cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
-	cl_assert_equal_sz(5, g_diff_perf.oid_calcs);
-	cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
+	cl_git_pass(git_status_list_new(&status, repo, &opts));
+	check_status0(status);
+	cl_git_pass(git_status_list_get_perfdata(&perf, status));
+	cl_assert_equal_sz(13 + 3, perf.stat_calls);
+	cl_assert_equal_sz(5, perf.oid_calculations);
 
-	memset(&g_diff_perf, 0, sizeof(g_diff_perf));
-#endif
+	git_status_list_free(status);
 
-	assert_show(entry_count0, entry_paths0, entry_statuses0,
-		repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_OPT_UPDATE_INDEX);
+	opts.flags |= GIT_STATUS_OPT_UPDATE_INDEX;
+
+	cl_git_pass(git_status_list_new(&status, repo, &opts));
+	check_status0(status);
+	cl_git_pass(git_status_list_get_perfdata(&perf, status));
+	cl_assert_equal_sz(13 + 3, perf.stat_calls);
+	cl_assert_equal_sz(5, perf.oid_calculations);
 
-#ifdef GIT_TRACE
-	cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
-	cl_assert_equal_sz(5, g_diff_perf.oid_calcs);
-	cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
+	git_status_list_free(status);
 
-	memset(&g_diff_perf, 0, sizeof(g_diff_perf));
-#endif
+	opts.flags &= ~GIT_STATUS_OPT_UPDATE_INDEX;
 
-	assert_show(entry_count0, entry_paths0, entry_statuses0,
-		repo, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
+	cl_git_pass(git_status_list_new(&status, repo, &opts));
+	check_status0(status);
+	cl_git_pass(git_status_list_get_perfdata(&perf, status));
+	cl_assert_equal_sz(13 + 3, perf.stat_calls);
+	cl_assert_equal_sz(0, perf.oid_calculations);
 
-#ifdef GIT_TRACE
-	cl_assert_equal_sz(13 + 3, g_diff_perf.stat_calls);
-	cl_assert_equal_sz(0, g_diff_perf.oid_calcs);
-	cl_assert_equal_sz(1, g_diff_perf.submodule_lookups);
-#endif
+	git_status_list_free(status);
 }
diff --git a/tests/trace/trace.c b/tests/trace/trace.c
index 3285393..87b3253 100644
--- a/tests/trace/trace.c
+++ b/tests/trace/trace.c
@@ -3,49 +3,44 @@
 
 static int written = 0;
 
-static void trace_callback(
-	git_trace_level_t level,
-	void *cb_payload,
-	void *msg_payload,
-	const char *msg)
+static void trace_callback(git_trace_level_t level, const char *message)
 {
-	GIT_UNUSED(level); GIT_UNUSED(msg_payload);
+	GIT_UNUSED(level);
 
-	cl_assert(strcmp(msg, "Hello world!") == 0);
+	cl_assert(strcmp(message, "Hello world!") == 0);
 
-	if (cb_payload)
-		*((int *)cb_payload) = 1;
+	written = 1;
 }
 
 void test_trace_trace__initialize(void)
 {
-	git_trace_set(GIT_TRACE_INFO_AND_BELOW, trace_callback, &written);
+	git_trace_set(GIT_TRACE_INFO, trace_callback);
 	written = 0;
 }
 
 void test_trace_trace__cleanup(void)
 {
-	git_trace_set(GIT_TRACE_NONE, NULL, NULL);
+	git_trace_set(GIT_TRACE_NONE, NULL);
 }
 
 void test_trace_trace__sets(void)
 {
 #ifdef GIT_TRACE
-	cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
+	cl_assert(git_trace_level() == GIT_TRACE_INFO);
 #endif
 }
 
 void test_trace_trace__can_reset(void)
 {
 #ifdef GIT_TRACE
-	cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
-	cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback, &written));
+	cl_assert(git_trace_level() == GIT_TRACE_INFO);
+	cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback));
 
 	cl_assert(written == 0);
-	git_trace(GIT_TRACE_INFO, NULL, "Hello %s!", "world");
+	git_trace(GIT_TRACE_INFO, "Hello %s!", "world");
 	cl_assert(written == 0);
 
-	git_trace(GIT_TRACE_ERROR, NULL, "Hello %s!", "world");
+	git_trace(GIT_TRACE_ERROR, "Hello %s!", "world");
 	cl_assert(written == 1);
 #endif
 }
@@ -53,13 +48,13 @@ void test_trace_trace__can_reset(void)
 void test_trace_trace__can_unset(void)
 {
 #ifdef GIT_TRACE
-	cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
-	cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL));
+	cl_assert(git_trace_level() == GIT_TRACE_INFO);
+	cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL));
 
 	cl_assert(git_trace_level() == GIT_TRACE_NONE);
 
 	cl_assert(written == 0);
-	git_trace(GIT_TRACE_FATAL, NULL, "Hello %s!", "world");
+	git_trace(GIT_TRACE_FATAL, "Hello %s!", "world");
 	cl_assert(written == 0);
 #endif
 }
@@ -68,7 +63,7 @@ void test_trace_trace__skips_higher_level(void)
 {
 #ifdef GIT_TRACE
 	cl_assert(written == 0);
-	git_trace(GIT_TRACE_DEBUG, NULL, "Hello %s!", "world");
+	git_trace(GIT_TRACE_DEBUG, "Hello %s!", "world");
 	cl_assert(written == 0);
 #endif
 }
@@ -77,7 +72,7 @@ void test_trace_trace__writes(void)
 {
 #ifdef GIT_TRACE
 	cl_assert(written == 0);
-	git_trace(GIT_TRACE_INFO, NULL, "Hello %s!", "world");
+	git_trace(GIT_TRACE_INFO, "Hello %s!", "world");
 	cl_assert(written == 1);
 #endif
 }
@@ -86,7 +81,7 @@ void test_trace_trace__writes_lower_level(void)
 {
 #ifdef GIT_TRACE
 	cl_assert(written == 0);
-	git_trace(GIT_TRACE_ERROR, NULL, "Hello %s!", "world");
+	git_trace(GIT_TRACE_ERROR, "Hello %s!", "world");
 	cl_assert(written == 1);
 #endif
 }