添加了运行时间计算代码,用来分析性能

This commit is contained in:
zzh 2023-12-25 13:58:15 +08:00
parent 293f3bb80e
commit c981585fd2
7 changed files with 51 additions and 5 deletions

View File

@ -3,8 +3,9 @@ CC= gcc
# CFLAGS= -g -Wall -Wno-unused-function -O2
CFLAGS= -g -Wall -Wno-unused-function -O2
WRAP_MALLOC=-DUSE_MALLOC_WRAPPERS
SHOW_PERF= -DSHOW_PERF
AR= ar
DFLAGS= -DHAVE_PTHREAD $(WRAP_MALLOC)
DFLAGS= -DHAVE_PTHREAD $(WRAP_MALLOC) $(SHOW_PERF)
LOBJS= utils.o kthread.o kstring.o ksw.o bwt.o bntseq.o bwa.o bwamem.o bwamem_pair.o bwamem_extra.o malloc_wrap.o \
QSufSort.o bwt_gen.o rope.o rle.o is.o bwtindex.o
AOBJS= bwashm.o bwase.o bwaseqio.o bwtgap.o bwtaln.o bamlite.o \

View File

@ -306,8 +306,15 @@ mem_chain_v mem_chain(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bn
mem_chain_t tmp, *lower, *upper;
mem_seed_t s;
int rid, to_add = 0;
#ifdef SHOW_PERF
int64_t tmp_time = realtime_msec();
#endif
s.rbeg = tmp.pos = bwt_sa(bwt, p->x[0] + k); // this is the base coordinate in the forward-reverse reference
s.qbeg = p->info>>32;
#ifdef SHOW_PERF
tmp_time = realtime_msec() - tmp_time;
__sync_fetch_and_add(&time_bwt_sa, tmp_time);
#endif
s.qbeg = p->info >> 32;
s.score= s.len = slen;
rid = bns_intv2rid(bns, s.rbeg, s.rbeg + s.len);
if (rid < 0) continue; // bridging multiple reference sequences or the forward-reverse boundary; TODO: split the seed; don't discard it!!!

View File

@ -41,6 +41,18 @@
#include "fmt_idx.h"
KSEQ_DECLARE(gzFile)
// 记录运行时间的变量
#ifdef SHOW_PERF
int64_t time_ksw_extend2 = 0,
time_ksw_global2 = 0,
time_ksw_align2 = 0,
time_bwt_smem1a = 0,
time_bwt_occ4 = 0,
time_bwt_sa = 0;
#endif
extern unsigned char nst_nt4_table[256];
void *kopen(const char *fn, int *_fd);
@ -406,6 +418,13 @@ int main_mem(int argc, char *argv[])
kseq_destroy(aux.ks2);
err_gzclose(fp2); kclose(ko2);
}
#ifdef SHOW_PERF
fprintf(stderr, "\n");
fprintf(stderr, "time_bwt_sa: %f s\n", time_bwt_sa / 1000.0 / opt->n_threads);
fprintf(stderr, "\n");
#endif
return 0;
}

View File

@ -23,5 +23,5 @@ void BuildBwtdFromBwt(bwt_t *bwt, bwtd_t **bwtd_p) {
printf("kmer size: %ld M\n", kmerSize * sizeof(kmer_range_t) / 1024 / 1024);
exit(0);
// exit(0);
}

4
run.sh
View File

@ -1,7 +1,7 @@
time ./bwa mem -t 1 -M -R @RG\\tID:normal\\tSM:normal\\tPL:illumina\\tLB:normal\\tPG:bwa \
time ./bwa mem -t 12 -M -R @RG\\tID:normal\\tSM:normal\\tPL:illumina\\tLB:normal\\tPG:bwa \
/home/zzh/data/reference/human_g1k_v37_decoy.fasta \
/home/zzh/data/fastq/nm1.fq \
/home/zzh/data/fastq/nm2.fq #-o /dev/null
/home/zzh/data/fastq/nm2.fq -o /dev/null
# time ./bwa mem -t 1 -M -R @RG\\tID:normal\\tSM:normal\\tPL:illumina\\tLB:normal\\tPG:bwa \
# /public/home/zzh/data/reference/human_g1k_v37_decoy.fasta \

View File

@ -294,6 +294,13 @@ double realtime(void)
return tp.tv_sec + tp.tv_usec * 1e-6;
}
int64_t realtime_msec(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (int64_t)1000 * (tv.tv_sec + ((1e-6) * tv.tv_usec));
}
long peakrss(void)
{
struct rusage r;

12
utils.h
View File

@ -31,6 +31,17 @@
#include <stdio.h>
#include <zlib.h>
#ifdef SHOW_PERF
extern int64_t time_ksw_extend2,
time_ksw_global2,
time_ksw_align2,
time_bwt_smem1a,
time_bwt_occ4,
time_bwt_sa;
#endif
#ifdef __GNUC__
// Tell GCC to validate printf format string and args
#define ATTRIBUTE(list) __attribute__ (list)
@ -86,6 +97,7 @@ extern "C" {
double cputime(void);
double realtime(void);
int64_t realtime_msec(void);
long peakrss(void);
void ks_introsort_64 (size_t n, uint64_t *a);